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 ## Ignoring Python complied files
/__pycache__ /__pycache__
/parsing/__pycache__ /module_parsing/__pycache__
/choice/__pycache__ /module_choice/__pycache__
/choice/form.py /module_choice/form.py
/main/__pycache__ /module_main/__pycache__
/main/form.py /module_main/form.py
/second/__pycache__ /module_second/__pycache__
/second/form.py /module_second/form.py
/config_editor/__pycache__ /module_config_editor/__pycache__
/config_editor/form.py /module_config_editor/form.py
## Ignoring UPX ## Ignoring UPX
/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 sys import argv, exit
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from config_editor.script import EditorWindow from module_config_editor.script import EditorWindow
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(argv) app = QApplication(argv)

View File

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

View File

@@ -5,8 +5,8 @@ from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QMessageBox from PyQt5.QtWidgets import QDialog, QMessageBox
from ast import literal_eval from ast import literal_eval
from .form import Ui_Choice from .form import Ui_Choice
from main.script import MainWindow from module_main.script import MainWindow
from parsing.script import check_remote_hashes, update_configs from module_parsing.script import check_remote_hashes, update_configs
from statics import update_config_name 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 ast import literal_eval
from .form import Ui_MainWindow from .form import Ui_MainWindow
from dataIO import dataIO from dataIO import dataIO
from util import generate_md5 from util import util
class EditorWindow(QMainWindow, Ui_MainWindow): class EditorWindow(QMainWindow, Ui_MainWindow):
@@ -70,7 +70,7 @@ class EditorWindow(QMainWindow, Ui_MainWindow):
def save_as(self): def save_as(self):
file_path, file_name = QFileDialog.getSaveFileName(parent=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")) filter=self.tr("*.json"))
file_data = literal_eval(self.ui.textEdit.toPlainText()) file_data = literal_eval(self.ui.textEdit.toPlainText())
ret = dataIO.save_json(file_path, file_data) ret = dataIO.save_json(file_path, file_data)
@@ -82,11 +82,10 @@ class EditorWindow(QMainWindow, Ui_MainWindow):
def copy_hash(self): def copy_hash(self):
if self.maybe_save(): if self.maybe_save():
result = generate_md5(self.file_path) result = util.generate_md5(self.file_path)
clip = QApplication.clipboard() clip = QApplication.clipboard()
QClipboard.setText(clip, result) QClipboard.setText(clip, result)
box = QMessageBox(QMessageBox.Information, "Information", "Hash successfully copied into your clipboard.") QMessageBox.information(self, "Information", "Hash successfully copied into your clipboard.")
box.exec()
def close_file(self): def close_file(self):
if self.maybe_save(): if self.maybe_save():
@@ -101,7 +100,7 @@ class EditorWindow(QMainWindow, Ui_MainWindow):
if not self.ui.textEdit.document().isModified(): if not self.ui.textEdit.document().isModified():
return True return True
box = QMessageBox.warning(self, 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?"), self.tr("The document has been modified.\nDo you want to save your changes?"),
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
if box == QMessageBox.Save: if box == QMessageBox.Save:

View File

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

View File

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

View File

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

View File

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

219
util.py
View File

@@ -1,142 +1,113 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# from re import search, match, sub
from re import search, match from re import search, match
# from re import search, match, sub
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
from hashlib import md5 from hashlib import md5
from statics import hash_chunk_size from statics import hash_chunk_size
lines = []
class CustomFuncs:
# Custom functions
def __init__(self):
self.lines = []
# Custom functions def set_lines(self, new_lines):
def set_lines(new_lines): self.lines = new_lines
global lines
lines = new_lines
def get_lines(self, index=None):
if index is not None:
return self.lines[index]
return self.lines
def get_lines(index=None): @staticmethod
global lines def generate_md5(fn):
if index is not None: try:
return lines[index] hash_md5 = md5()
return lines with open(fn, "rb") as f:
for chunk in iter(lambda: f.read(hash_chunk_size), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
except FileNotFoundError:
return False
# Stock functions
def show_message(icon, title, text): def search_line(self, term, start=0, cancel=r"this_string_must_not_exist"):
box = QMessageBox(icon, title, text, QMessageBox.Ok) if search(term, self.lines[start]):
box.exec()
def generate_md5(fn):
try:
hash_md5 = md5()
with open(fn, "rb") as f:
for chunk in iter(lambda: f.read(hash_chunk_size), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
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]):
return start
start += 1
while start <= len(lines) - 1:
if search(term, lines[start]):
return start return start
if search(cancel, lines[start]):
return None
start += 1 start += 1
return None while start <= len(self.lines) - 1:
if search(term, self.lines[start]):
return start
def search_line_in_unit(term, unit): if search(cancel, self.lines[start]):
global lines return None
line = search_line(" : " + unit + " {") start += 1
return search_line(term, start=line, cancel="}")
def search_all_lines(term):
global lines
matches = []
line = 0
while search_line(term, start=line + 1):
line = search_line(term, start=line + 1)
matches.append(line)
if matches is None:
return None return None
return matches
def search_line_in_unit(self, term, unit):
line = self.search_line(" : " + unit + " {")
return self.search_line(term, start=line, cancel="}")
def search_all_lines(self, term):
matches = []
line = 0
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 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 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_array_index_by_value(self, line, value):
# count = 0
# 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(self, line):
items = []
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 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):
# 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
# self.set_value(line, value)
def get_value(line): util = CustomFuncs()
global lines
return search(r": (.+)$", lines[line]).group(1)
def set_value(line, value):
global lines
name = match(r"(.+):", lines[line]).group(1)
lines[line] = name + ": " + value
# 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
# count = 0
# for i in range(get_array_length(line)):
# if get_value(line + count + 1) == value:
# return count
# count += 1
# return None
def get_array_items(line):
global lines
items = []
for i in range(get_array_length(line)):
items.append(search(r": (.+)$", lines[line + i + 1]).group(1))
if items is None:
return None
return items
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)
# 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
# line += index + 1
# set_value(line, value)