Sort folders by renaming, some code changes

Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2020-12-16 22:09:37 +07:00
parent 3dd855ff38
commit 69b815e917
22 changed files with 210 additions and 257 deletions

18
.gitignore vendored
View File

@@ -3,15 +3,15 @@
## Ignoring Python complied files
/__pycache__
/parsing/__pycache__
/choice/__pycache__
/choice/form.py
/main/__pycache__
/main/form.py
/second/__pycache__
/second/form.py
/config_editor/__pycache__
/config_editor/form.py
/module_parsing/__pycache__
/module_choice/__pycache__
/module_choice/form.py
/module_main/__pycache__
/module_main/form.py
/module_second/__pycache__
/module_second/form.py
/module_config_editor/__pycache__
/module_config_editor/form.py
## Ignoring UPX
/upx

View File

@@ -1 +0,0 @@
python setup.py build

View File

@@ -1 +0,0 @@
pyinstaller build.spec --noupx

View File

@@ -1,13 +0,0 @@
cls
@echo off
title Form converter
:SETUP
echo Enter form name to convert into .py (without .ui):
echo Type 'exit' to exit
set/p "name=> "
if %name%==exit goto EXIT
pyuic5 %name%.ui -o %name%.py
goto SETUP
:EXIT

View File

@@ -3,7 +3,7 @@
from sys import argv, exit
from PyQt5.QtWidgets import QApplication
from config_editor.script import EditorWindow
from module_config_editor.script import EditorWindow
if __name__ == '__main__':
app = QApplication(argv)

View File

@@ -3,7 +3,7 @@
from sys import argv, exit
from PyQt5.QtWidgets import QApplication
from choice.script import ChoiceWindow
from module_choice.script import ChoiceWindow
if __name__ == '__main__':
app = QApplication(argv)

View File

@@ -5,8 +5,8 @@ from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QMessageBox
from ast import literal_eval
from .form import Ui_Choice
from main.script import MainWindow
from parsing.script import check_remote_hashes, update_configs
from module_main.script import MainWindow
from module_parsing.script import check_remote_hashes, update_configs
from statics import update_config_name

View File

@@ -7,7 +7,7 @@ from PyQt5.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QApplication
from ast import literal_eval
from .form import Ui_MainWindow
from dataIO import dataIO
from util import generate_md5
from util import util
class EditorWindow(QMainWindow, Ui_MainWindow):
@@ -70,7 +70,7 @@ class EditorWindow(QMainWindow, Ui_MainWindow):
def save_as(self):
file_path, file_name = QFileDialog.getSaveFileName(parent=self,
caption=self.tr("Select position"),
caption=self.tr("Select place to save file"),
filter=self.tr("*.json"))
file_data = literal_eval(self.ui.textEdit.toPlainText())
ret = dataIO.save_json(file_path, file_data)
@@ -82,11 +82,10 @@ class EditorWindow(QMainWindow, Ui_MainWindow):
def copy_hash(self):
if self.maybe_save():
result = generate_md5(self.file_path)
result = util.generate_md5(self.file_path)
clip = QApplication.clipboard()
QClipboard.setText(clip, result)
box = QMessageBox(QMessageBox.Information, "Information", "Hash successfully copied into your clipboard.")
box.exec()
QMessageBox.information(self, "Information", "Hash successfully copied into your clipboard.")
def close_file(self):
if self.maybe_save():
@@ -101,7 +100,7 @@ class EditorWindow(QMainWindow, Ui_MainWindow):
if not self.ui.textEdit.document().isModified():
return True
box = QMessageBox.warning(self,
self.tr("App"),
self.tr("SaveWizard config editor"),
self.tr("The document has been modified.\nDo you want to save your changes?"),
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
if box == QMessageBox.Save:

View File

@@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QDialog, QFileDialog
from .form import Ui_MainWindow
from util import *
from dataIO import dataIO
from second.script import SecondWindow
from module_second.script import SecondWindow
class MainWindow(QDialog, Ui_MainWindow):
@@ -68,7 +68,7 @@ class MainWindow(QDialog, Ui_MainWindow):
self.ui.apply.clicked.connect(self.apply_changes)
self.check_config()
self.clear_fields()
self.clear_form_data()
def text_edited(self):
sender = self.sender()
@@ -99,16 +99,16 @@ class MainWindow(QDialog, Ui_MainWindow):
cfg_path = "configs/{}/dlc.json".format(self.selected_game)
if dataIO.is_valid_json(cfg_path) is False:
self.owns = False
show_message(QMessageBox.Warning, "Warning", "'dlc.json' from '{}' have errors or not found, "
QMessageBox.warning(self, "Warning", "'dlc.json' from '{}' have errors or not found, "
"functionality has been limited".format(self.selected_game))
else:
self.owns = {}
self.dlc = dataIO.load_json(cfg_path)
def clear_fields(self):
def clear_form_data(self):
self.file_path = ""
self.old_file = ""
set_lines([])
util.set_lines([])
if self.owns is not False:
self.owns = {}
@@ -136,33 +136,33 @@ class MainWindow(QDialog, Ui_MainWindow):
system("SII_Decrypt.exe --on_file -i \"{}\"".format(file))
with open(file) as f:
self.old_file = f.read()
show_message(QMessageBox.Information, "Success", "File successfully decrypted.")
QMessageBox.information(self, "Success", "File successfully decrypted.")
except UnicodeDecodeError:
show_message(QMessageBox.Critical, "Error", "Error to decrypt and open file. "
QMessageBox.critical(self, "Error", "Error to decrypt and open file. "
"Try again.\nIf you still get error on this step, "
"try to change \"uset g_save_format\" to 2, resave game "
"and try again.")
"try to change \"uset g_save_format\" to 2, resave "
"game and try again.")
return
set_lines(self.old_file.split("\n"))
util.set_lines(self.old_file.split("\n"))
if self.owns is not False:
self.owns["base"] = True
companies = get_array_items(search_line("companies:"))
companies = util.get_array_items(util.search_line("companies:"))
for key, value in self.dlc.items():
if value in companies:
self.owns[key] = True
for key, value in self.basic_edits.items():
key.setText(get_value(search_line(value[1])))
key.setText(util.get_value(util.search_line(value[1])))
adr = self.get_adr(get_value(search_line("adr:")))
adr = self.get_adr(util.get_value(util.search_line("adr:")))
adr_list = ""
for i in range(6):
adr_list += adr[i] + "," if i != 5 else adr[i]
self.ui.adr_edit.setText(adr_list)
for key, value in self.skill_edits.items():
key.setText(get_value(search_line(value[1])))
key.setText(util.get_value(util.search_line(value[1])))
self.ui.apply.setEnabled(True)
self.ui.backup.setEnabled(True)
@@ -172,7 +172,7 @@ class MainWindow(QDialog, Ui_MainWindow):
file_path, file_name = QFileDialog.getOpenFileName(parent=self,
caption=self.tr("Choose your save file..."),
filter=self.tr("game.sii"))
self.clear_fields()
self.clear_form_data()
if file_path != "":
self.file_path = file_path
self.get_file_data(file_path)
@@ -185,23 +185,22 @@ class MainWindow(QDialog, Ui_MainWindow):
box.addButton("Yes", QMessageBox.YesRole)
box.addButton("No", QMessageBox.NoRole)
if box.exec() == 0:
self.clear_fields()
self.clear_form_data()
self.selected_game = "ets2" if self.selected_game == "ats" else "ats"
self.ui.chosen_cfgs.setText("{} {}".format(self.chosen_cfg_text, self.selected_game.upper()))
self.check_config()
def recover_backup(self):
try:
backup = self.file_path + ".swbak"
f = open(backup)
with open(self.file_path, "w") as g:
g.write(f.read())
f.close()
remove(backup)
show_message(QMessageBox.Information, "Success", "Backup successfully recovered.")
backup_path = self.file_path + ".swbak"
with open(self.file_path, "w") as current:
with open(backup_path) as backup:
current.write(backup.read())
remove(backup_path)
QMessageBox.information(self, "Success", "Backup successfully recovered.")
self.get_file_data(self.file_path)
except IOError:
show_message(QMessageBox.Critical, "Error", "Backup not found.")
QMessageBox.critical(self, "Error", "Backup not found.")
def open_second_win(self):
second_win = SecondWindow(self.selected_game, self.owns, self)
@@ -211,25 +210,25 @@ class MainWindow(QDialog, Ui_MainWindow):
if not self.ui.dont_change_all_inf.isChecked():
for key, value in self.basic_edits.items():
if value[0].isChecked() is False:
set_value(search_line(value[1]), key.text())
util.set_value(util.search_line(value[1]), key.text())
value[0].setChecked(True)
if self.ui.adr_dont_change.isChecked() is False:
adr_set = self.get_adr_from_line()
if len(adr_set) < 6:
show_message(QMessageBox.Critical, "Error", "ADR can't have less than 6 elements.")
QMessageBox.critical(self, "Error", "ADR can't have less than 6 elements.")
elif len(adr_set) > 6:
show_message(QMessageBox.Critical, "Error", "ADR can't have more than 6 elements.")
QMessageBox.critical(self, "Error", "ADR can't have more than 6 elements.")
else:
adr_new = int("".join(adr_set), 2)
set_value(search_line("adr:"), str(adr_new))
util.set_value(util.search_line("adr:"), str(adr_new))
for key, value in self.skill_edits.items():
if value[0].isChecked() is False:
set_value(search_line(value[1]), key.text())
util.set_value(util.search_line(value[1]), key.text())
value[0].setChecked(True)
backup = self.file_path + ".swbak"
with open(backup, "w") as f:
f.write(self.old_file)
with open(self.file_path, "w") as f:
f.write("\n".join(get_lines()))
show_message(QMessageBox.Information, "Success", "Changes successfully applied!")
f.write("\n".join(util.get_lines()))
QMessageBox.information(self, "Success", "Changes successfully applied!")
self.get_file_data(self.file_path)

View File

@@ -6,7 +6,7 @@ from ast import literal_eval
import os
from statics import github_link, update_config_name
from dataIO import dataIO
from util import generate_md5
from util import util
def get_response_result(url):
@@ -33,7 +33,7 @@ def check_remote_hashes():
for key, value in remote_cfg.items():
path = key.split("_")
path = "configs/{}/{}.json".format(path[0], path[1])
if generate_md5(path) != value:
if util.generate_md5(path) != value:
need_update.append(path)
return need_update
return False

View File

@@ -33,8 +33,8 @@ class SecondWindow(QDialog, Ui_SecondWindow):
self.ui.dealer_edit.setEnabled(False)
self.ui.dealer_add.setEnabled(False)
self.ui.dealer_add_all.setEnabled(False)
show_message(QMessageBox.Warning, "Warning", "'dealers.json' from '{}' have errors or not found, dealers "
"editing has been disabled".format(selected_game))
QMessageBox.warning(self, "Warning", "'dealers.json' from '{}' have errors or not found.\n"
"Dealers editing has been disabled".format(selected_game))
else:
self.dealers = []
self.dealers_file = dataIO.load_json(dealers_path)
@@ -44,8 +44,8 @@ class SecondWindow(QDialog, Ui_SecondWindow):
self.ui.agency_edit.setEnabled(False)
self.ui.agency_add.setEnabled(False)
self.ui.agency_add_all.setEnabled(False)
show_message(QMessageBox.Warning, "Warning", "'agencies.json' from '{}' have errors or not found, agencies "
"editing has been disabled".format(selected_game))
QMessageBox.warning(self, "Warning", "'agencies.json' from '{}' have errors or not found.\n"
"Agencies editing has been disabled".format(selected_game))
else:
self.agencies = []
self.agencies_file = dataIO.load_json(agencies_path)
@@ -85,16 +85,16 @@ class SecondWindow(QDialog, Ui_SecondWindow):
@staticmethod
def purchased_garages():
garages = []
for index in search_all_lines("garage : garage."):
city = match(r"garage : garage.(.+) {$", get_lines(index)).group(1)
if get_value(search_line("status:", start=index)) != "0":
for index in util.search_all_lines("garage : garage."):
city = match(r"garage : garage.(.+) {$", util.get_lines(index)).group(1)
if util.get_value(util.search_line("status:", start=index)) != "0":
garages.append(city)
return garages
@staticmethod
def all_cities():
cities = []
for line in get_array_items(search_line("companies:")):
for line in util.get_array_items(util.search_line("companies:")):
city = match(r"company.volatile.[a-z0-9_]+[.]([a-z_]+)", line).group(1)
if city not in cities:
cities.append(city)
@@ -123,55 +123,55 @@ class SecondWindow(QDialog, Ui_SecondWindow):
def add_garage(self):
garage = self.ui.garage_edit.text().lower()
if garage is "":
show_message(QMessageBox.Critical, "Error", "Enter city name!")
QMessageBox.critical(self, "Error", "Enter city name!")
return
self.ui.garage_edit.setText("")
reg_garage = "garage." + garage
current_status = search_line_in_unit("status:", reg_garage)
if get_value(current_status) == "0":
current_status = util.search_line_in_unit("status:", reg_garage)
if util.get_value(current_status) == "0":
new_status, size = self.check_garage_size()
set_value(current_status, new_status)
vehicles_array = search_line_in_unit("vehicles:", reg_garage)
drivers_array = search_line_in_unit("drivers:", reg_garage)
util.set_value(current_status, new_status)
vehicles_array = util.search_line_in_unit("vehicles:", reg_garage)
drivers_array = util.search_line_in_unit("drivers:", reg_garage)
for i in range(1, size+1):
add_array_value(vehicles_array, "null")
add_array_value(drivers_array+i, "null")
show_message(QMessageBox.Information, "Success", "Garage in \"{}\" successfully unlocked.".format(garage))
util.add_array_value(vehicles_array, "null")
util.add_array_value(drivers_array+i, "null")
QMessageBox.information(self, "Success", "Garage in \"{}\" successfully unlocked.".format(garage))
else:
show_message(QMessageBox.Critical, "Error", "Garage in \"{}\" already unlocked.".format(garage))
QMessageBox.critical(self, "Error", "Garage in \"{}\" already unlocked.".format(garage))
def add_all_garages(self):
new_status, size = self.check_garage_size()
for item in get_array_items(search_line("garages:")):
for item in util.get_array_items(util.search_line("garages:")):
item = match(r"garage.(.+)$", item).group(1)
current_garage = search_line("garage : garage."+item+" {")
current_status = search_line("status:", start=current_garage)
if get_value(current_status) == "0":
set_value(current_status, new_status)
vehicles_array = search_line("vehicles:", start=current_garage)
drivers_array = search_line("drivers:", start=current_garage)
current_garage = util.search_line("garage : garage."+item+" {")
current_status = util.search_line("status:", start=current_garage)
if util.get_value(current_status) == "0":
util.set_value(current_status, new_status)
vehicles_array = util.search_line("vehicles:", start=current_garage)
drivers_array = util.search_line("drivers:", start=current_garage)
for i in range(1, size+1):
add_array_value(vehicles_array, "null")
add_array_value(drivers_array+i, "null")
show_message(QMessageBox.Information, "Success", "All garages successfully unlocked.")
util.add_array_value(vehicles_array, "null")
util.add_array_value(drivers_array+i, "null")
QMessageBox.information(self, "Success", "All garages successfully unlocked.")
def change_headquarter(self):
hq = self.ui.headquarter_edit.text().lower()
if hq is "":
show_message(QMessageBox.Critical, "Error", "Enter city name!")
QMessageBox.critical(self, "Error", "Enter city name!")
return
if get_value(search_line("hq_city:")) == hq:
show_message(QMessageBox.Information, "Info", "Your headquarter is already in this city.")
if util.get_value(util.search_line("hq_city:")) == hq:
QMessageBox.information(self, "Info", "Your headquarter is already in this city.")
elif hq not in self.purchased_garages():
show_message(QMessageBox.Critical, "Error", "You need a garage in \"{}\" to set headquarter.".format(hq))
QMessageBox.critical(self, "Error", "You need a garage in \"{}\" to set headquarter.".format(hq))
else:
set_value(search_line("hq_city:"), hq)
show_message(QMessageBox.Information, "Success", "Headquarter successfully set to \"{}\".".format(hq))
util.set_value(util.search_line("hq_city:"), hq)
QMessageBox.information(self, "Success", "Headquarter successfully set to \"{}\".".format(hq))
def check_cities(self):
self.ui.headquarter_edit.setText(get_value(search_line("hq_city:")))
self.ui.headquarter_edit.setText(util.get_value(util.search_line("hq_city:")))
self.ui.cities_text.clear()
visited_cities = get_array_items(search_line("visited_cities:"))
visited_cities = util.get_array_items(util.search_line("visited_cities:"))
if not visited_cities:
self.ui.cities_text.append("No cities visited yet.")
return
@@ -182,29 +182,29 @@ class SecondWindow(QDialog, Ui_SecondWindow):
def add_city(self):
city = self.ui.city_edit.text().lower()
if city is "":
show_message(QMessageBox.Critical, "Error", "Enter city name!")
QMessageBox.critical(self, "Error", "Enter city name!")
return
self.ui.city_edit.setText("")
if city not in get_array_items(search_line("visited_cities:")):
add_array_value(search_line("visited_cities:"), city)
add_array_value(search_line("visited_cities_count:"), "1")
show_message(QMessageBox.Information, "Success", "City \"{}\" successfully visited.".format(city))
if city not in util.get_array_items(util.search_line("visited_cities:")):
util.add_array_value(util.search_line("visited_cities:"), city)
util.add_array_value(util.search_line("visited_cities_count:"), "1")
QMessageBox.information(self, "Success", "City \"{}\" successfully visited.".format(city))
self.check_cities()
else:
show_message(QMessageBox.Critical, "Error", "You've already visited \"{}\".".format(city))
QMessageBox.critical(self, "Error", "You've already visited \"{}\".".format(city))
def add_all_cities(self):
visited_cities = get_array_items(search_line("visited_cities:"))
visited_cities = util.get_array_items(util.search_line("visited_cities:"))
for city in self.all_cities():
if city not in visited_cities:
add_array_value(search_line("visited_cities:"), city)
add_array_value(search_line("visited_cities_count:"), "1")
show_message(QMessageBox.Information, "Success", "All cities successfully visited.")
util.add_array_value(util.search_line("visited_cities:"), city)
util.add_array_value(util.search_line("visited_cities_count:"), "1")
QMessageBox.information(self, "Success", "All cities successfully visited.")
self.check_cities()
def check_dealers(self):
self.ui.dealerships_text.clear()
visited_dealers = get_array_items(search_line("unlocked_dealers:"))
visited_dealers = util.get_array_items(util.search_line("unlocked_dealers:"))
if not visited_dealers:
self.ui.dealerships_text.append("No dealerships unlocked yet.")
return
@@ -214,16 +214,16 @@ class SecondWindow(QDialog, Ui_SecondWindow):
def add_all_dealers(self):
all_cities = self.all_cities()
visited_dealers = get_array_items(search_line("unlocked_dealers:"))
visited_dealers = util.get_array_items(util.search_line("unlocked_dealers:"))
for dealer in self.dealers:
if dealer in all_cities and dealer not in visited_dealers:
add_array_value(search_line("unlocked_dealers:"), dealer)
show_message(QMessageBox.Information, "Success", "All dealerships unlocked.")
util.add_array_value(util.search_line("unlocked_dealers:"), dealer)
QMessageBox.information(self, "Success", "All dealerships unlocked.")
self.check_dealers()
def check_agencies(self):
self.ui.agencies_text.clear()
visited_agencies = get_array_items(search_line("unlocked_recruitments:"))
visited_agencies = util.get_array_items(util.search_line("unlocked_recruitments:"))
if not visited_agencies:
self.ui.agencies_text.append("No recruitment agencies unlocked yet.")
return
@@ -233,11 +233,11 @@ class SecondWindow(QDialog, Ui_SecondWindow):
def add_all_agencies(self):
all_cities = self.all_cities()
visited_agencies = get_array_items(search_line("unlocked_recruitments:"))
visited_agencies = util.get_array_items(util.search_line("unlocked_recruitments:"))
for agency in self.agencies:
if agency in all_cities and agency not in visited_agencies:
add_array_value(search_line("unlocked_recruitments:"), agency)
show_message(QMessageBox.Information, "Success", "All recruitment agencies unlocked.")
util.add_array_value(util.search_line("unlocked_recruitments:"), agency)
QMessageBox.information(self, "Success", "All recruitment agencies unlocked.")
self.check_agencies()
def da_clicked(self):
@@ -247,16 +247,15 @@ class SecondWindow(QDialog, Ui_SecondWindow):
edit, file_var, message_var = da_arr[0], da_arr[1], da_arr[2]
city_element = edit.text().lower()
if not city_element:
show_message(QMessageBox.Critical, "Error", "Enter city name!")
QMessageBox.critical(self, "Error", "Enter city name!")
return
edit.setText("")
if city_element not in da_arr[3]:
show_message(QMessageBox.Critical, "Error", "There is no {} in that city.".format(message_var.lower()))
elif city_element in get_array_items(search_line(file_var)):
show_message(QMessageBox.Information, "Info",
"{} in \"{}\" is already unlocked.".format(message_var, city_element))
QMessageBox.critical(self, "Error", "There is no {} in that city.".format(message_var.lower()))
elif city_element in util.get_array_items(util.search_line(file_var)):
QMessageBox.information(self, "Info", "{} in \"{}\" is already unlocked.".format(message_var, city_element))
else:
add_array_value(search_line(file_var), city_element)
show_message(QMessageBox.Information, "Success",
"{} in \"{}\" successfully unlocked.".format(message_var, city_element))
util.add_array_value(util.search_line(file_var), city_element)
QMessageBox.information(self, "Success", "{} in \"{}\" successfully unlocked."
"".format(message_var, city_element))
da_arr[4]()

View File

@@ -16,7 +16,7 @@ executables = [
excludes = ['html', 'pydoc_data', 'unittest', 'xml', 'pwd', 'shlex', 'platform', 'webbrowser', 'pydoc', 'tty',
'inspect', 'doctest', 'plistlib', 'subprocess', 'bz2', '_strptime', 'dummy_threading']
includes = ['pkgutil', 'enum', 'queue', 'PyQt5.sip']
includes = ['pkgutil', 'enum', 'queue']
zip_include_packages = [
# Stock modules
@@ -27,7 +27,7 @@ zip_include_packages = [
# Modules for parsing cfg's
'requests', 'logging', 'certifi', 'chardet', 'idna', 'urllib3',
# Self-written modules
'parsing', 'choice', 'main', 'second', 'config_editor'
'module_parsing', 'module_choice', 'module_main', 'module_second', 'module_config_editor'
]
include_files = [

139
util.py
View File

@@ -1,33 +1,27 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# from re import search, match, sub
from re import search, match
# from re import search, match, sub
from PyQt5.QtWidgets import QMessageBox
from hashlib import md5
from statics import hash_chunk_size
lines = []
class CustomFuncs:
# Custom functions
def set_lines(new_lines):
global lines
lines = new_lines
def __init__(self):
self.lines = []
def set_lines(self, new_lines):
self.lines = new_lines
def get_lines(index=None):
global lines
def get_lines(self, index=None):
if index is not None:
return lines[index]
return lines
def show_message(icon, title, text):
box = QMessageBox(icon, title, text, QMessageBox.Ok)
box.exec()
return self.lines[index]
return self.lines
@staticmethod
def generate_md5(fn):
try:
hash_md5 = md5()
@@ -38,105 +32,82 @@ def generate_md5(fn):
except FileNotFoundError:
return False
# Stock functions
def search_line(term, start=0, cancel=r"this_string_must_not_exist"):
global lines
if search(term, lines[start]):
def search_line(self, term, start=0, cancel=r"this_string_must_not_exist"):
if search(term, self.lines[start]):
return start
start += 1
while start <= len(lines) - 1:
if search(term, lines[start]):
while start <= len(self.lines) - 1:
if search(term, self.lines[start]):
return start
if search(cancel, lines[start]):
if search(cancel, self.lines[start]):
return None
start += 1
return None
def search_line_in_unit(self, term, unit):
line = self.search_line(" : " + unit + " {")
return self.search_line(term, start=line, cancel="}")
def search_line_in_unit(term, unit):
global lines
line = search_line(" : " + unit + " {")
return search_line(term, start=line, cancel="}")
def search_all_lines(term):
global lines
def search_all_lines(self, term):
matches = []
line = 0
while search_line(term, start=line + 1):
line = search_line(term, start=line + 1)
while self.search_line(term, start=line + 1):
line = self.search_line(term, start=line + 1)
matches.append(line)
if matches is None:
return None
return matches
def get_value(self, line):
return search(r": (.+)$", self.lines[line]).group(1)
def get_value(line):
global lines
return search(r": (.+)$", lines[line]).group(1)
def set_value(self, line, value):
name = match(r"(.+):", self.lines[line]).group(1)
self.lines[line] = name + ": " + value
# def get_unit_name(self, line):
# return search(r" : (.+) {$", self.lines[line]).group(1)
def set_value(line, value):
global lines
name = match(r"(.+):", lines[line]).group(1)
lines[line] = name + ": " + value
def get_array_length(self, line):
return int(search(r": ([0-9]+)$", self.lines[line]).group(1))
# def get_array_value_by_index(self, line, index):
# return search(r": (.+)$", self.lines[line + index + 1]).group(1)
# def get_unit_name(line):
# global lines
# return search(r" : (.+) {$", lines[line]).group(1)
def get_array_length(line):
global lines
return int(search(r": ([0-9]+)$", lines[line]).group(1))
# def get_array_value_by_index(line, index):
# global lines
# return search(r": (.+)$", lines[line + index + 1]).group(1)
#
#
# def get_array_index_by_value(line, value):
# global lines
# def get_array_index_by_value(self, line, value):
# count = 0
# for i in range(get_array_length(line)):
# if get_value(line + count + 1) == value:
# for i in range(self.get_array_length(line)):
# if self.get_value(line + count + 1) == value:
# return count
# count += 1
# return None
def get_array_items(line):
global lines
def get_array_items(self, line):
items = []
for i in range(get_array_length(line)):
items.append(search(r": (.+)$", lines[line + i + 1]).group(1))
for i in range(self.get_array_length(line)):
items.append(search(r": (.+)$", self.lines[line + i + 1]).group(1))
if items is None:
return None
return items
def add_array_value(self, line, value):
name = match(r"(.+):", self.lines[line]).group(1)
count = self.get_array_length(line)
self.lines[line] = name + ": " + str(count + 1)
self.lines.insert(line + count + 1, name + "[" + str(count) + "]: " + value)
def add_array_value(line, value):
global lines
name = match(r"(.+):", lines[line]).group(1)
count = get_array_length(line)
lines[line] = name + ": " + str(count + 1)
lines.insert(line + count + 1, name + "[" + str(count) + "]: " + value)
# def remove_array_value(line, value):
# global lines
# name = match(r"(.+):", lines[line]).group(1)
# del lines[line + 1 + get_array_index_by_value(line, value)]
# count = get_array_length(line)
# lines[line] = name + ": " + str(count - 1)
# def remove_array_value(self, line, value):
# name = match(r"(.+):", self.lines[line]).group(1)
# del self.lines[line + 1 + self.get_array_index_by_value(line, value)]
# count = self.get_array_length(line)
# self.lines[line] = name + ": " + str(count - 1)
# for i in range(count):
# lines[line + i + 1] = sub(r"\[[0-9]+]", "[" + str(i) + "]", lines[line + i + 1])
#
#
# def change_array_value(line, index, value):
# global lines
# self.lines[line + i + 1] = sub(r"\[[0-9]+]", "[" + str(i) + "]", lines[line + i + 1])
# def change_array_value(self, line, index, value):
# line += index + 1
# set_value(line, value)
# self.set_value(line, value)
util = CustomFuncs()