2020-08-06 18:10:55 +02:00
|
|
|
"""
|
|
|
|
|
# GeneratorCSV
|
2020-08-06 18:17:00 +02:00
|
|
|
# Wersja 4.0 Experimental
|
2020-08-06 18:10:55 +02:00
|
|
|
# by Mateusz Skoczek
|
|
|
|
|
# luty 2019 - grudzień 2019
|
|
|
|
|
# dla ZSP Sobolew
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Moduł zarządzający plikiem konfiguracyjnym
|
|
|
|
|
#
|
|
|
|
|
"""
|
|
|
|
|
|
2020-08-06 18:12:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----------------------------------- # Import bibliotek zewnętrznych i modułów # ------------------------------------ #
|
|
|
|
|
|
|
|
|
|
# Biblioteki zewnętrzne
|
|
|
|
|
import sys as SS
|
|
|
|
|
|
2020-08-06 18:20:52 +02:00
|
|
|
|
|
|
|
|
|
2020-08-06 18:12:58 +02:00
|
|
|
# Moduły składowe programu
|
|
|
|
|
try:
|
2020-08-06 18:26:57 +02:00
|
|
|
from modules import dialog as MDdlg
|
2020-08-06 18:12:58 +02:00
|
|
|
except ModuleNotFoundError:
|
2020-08-06 18:26:57 +02:00
|
|
|
print('Wystąpił krytyczny błąd!')
|
|
|
|
|
print('Nie znaleziono jednego z modułów programu (dialog.py). Nie można załadować programu')
|
|
|
|
|
print('Kod błędu: E00x0011')
|
|
|
|
|
wait = input('Naciśnij ENTER aby wyjść')
|
|
|
|
|
SS.exit(0)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
print('Wystąpił krytyczny błąd!')
|
|
|
|
|
print('Nieznany błąd podczas ładowania jednego z modułów programu (dialog.py). Nie można załadować programu.')
|
|
|
|
|
print('Treść błędu: ' + exc)
|
|
|
|
|
print('Kod błędu: E00x0010')
|
2020-08-06 18:20:52 +02:00
|
|
|
wait = input('Naciśnij ENTER aby wyjść')
|
2020-08-06 18:12:58 +02:00
|
|
|
SS.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------- # Funkcje # ---------------------------------------------------- #
|
|
|
|
|
|
|
|
|
|
# Wewnętrzna funkcja sprawdzająca błędy pliku konfiguracyjnego
|
|
|
|
|
def CheckConfig(settings):
|
|
|
|
|
# Ilość wierszy
|
|
|
|
|
try:
|
2020-08-06 18:25:27 +02:00
|
|
|
if len(settings) != 7:
|
2020-08-06 18:12:58 +02:00
|
|
|
error = int('x')
|
|
|
|
|
except ValueError:
|
2020-08-06 18:20:52 +02:00
|
|
|
MDdlg.err(1)
|
2020-08-06 18:12:58 +02:00
|
|
|
|
|
|
|
|
# Linia 1 (0/1)
|
|
|
|
|
try:
|
|
|
|
|
check = int(settings[0])
|
|
|
|
|
if 0 > check > 1:
|
|
|
|
|
error = int('x')
|
|
|
|
|
except ValueError:
|
2020-08-06 18:20:52 +02:00
|
|
|
MDdlg.err(2)
|
2020-08-06 18:12:58 +02:00
|
|
|
# Linia 2 (utf-8)
|
2020-08-06 18:20:52 +02:00
|
|
|
|
2020-08-06 18:12:58 +02:00
|
|
|
DostepneKodowanieWyjsciowe = ['utf-8']
|
|
|
|
|
try:
|
|
|
|
|
if settings[1] not in DostepneKodowanieWyjsciowe:
|
|
|
|
|
error = int('x')
|
|
|
|
|
except ValueError:
|
2020-08-06 18:20:52 +02:00
|
|
|
MDdlg.err(3)
|
2020-08-06 18:12:58 +02:00
|
|
|
|
2020-08-06 18:22:56 +02:00
|
|
|
# Linia 4 (int)
|
|
|
|
|
try:
|
|
|
|
|
x = int(settings[3])
|
|
|
|
|
except ValueError:
|
|
|
|
|
MDdlg.err(17)
|
|
|
|
|
|
2020-08-06 18:25:27 +02:00
|
|
|
# Linia 6 (int)
|
|
|
|
|
try:
|
|
|
|
|
x = int(settings[5])
|
|
|
|
|
except ValueError:
|
|
|
|
|
MDdlg.err(18)
|
|
|
|
|
|
|
|
|
|
# Linia 7 (int)
|
|
|
|
|
try:
|
|
|
|
|
x = int(settings[6])
|
|
|
|
|
except ValueError:
|
|
|
|
|
MDdlg.err(19)
|
2020-08-06 18:12:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Odczytywanie ustawień z pliku konfiguracyjnego
|
2020-08-06 18:10:55 +02:00
|
|
|
def read():
|
2020-08-06 18:12:58 +02:00
|
|
|
try:
|
|
|
|
|
check = open('.\config.cfg')
|
|
|
|
|
except FileNotFoundError:
|
2020-08-06 18:20:52 +02:00
|
|
|
MDdlg.err(0)
|
2020-08-06 18:12:58 +02:00
|
|
|
else:
|
|
|
|
|
with open('.\config.cfg', 'r') as cfg:
|
|
|
|
|
config = cfg.read().split('\n')
|
|
|
|
|
settings = []
|
|
|
|
|
for x in config:
|
|
|
|
|
settings.append(x.split(': ')[1])
|
|
|
|
|
CheckConfig(settings)
|
|
|
|
|
return settings
|
|
|
|
|
|
|
|
|
|
|
2020-08-06 18:10:55 +02:00
|
|
|
|
2020-08-06 18:12:58 +02:00
|
|
|
# Zapis ustawień do pliku konfiguracyjnego
|
|
|
|
|
def edit(settings):
|
|
|
|
|
CheckConfig(settings)
|
|
|
|
|
try:
|
|
|
|
|
check = open('.\config.cfg')
|
|
|
|
|
except FileNotFoundError:
|
2020-08-06 18:20:52 +02:00
|
|
|
MDdlg.err(0)
|
2020-08-06 18:12:58 +02:00
|
|
|
else:
|
|
|
|
|
SettingsToSave = []
|
|
|
|
|
SettingsToSave.append('Ciemny motyw(0/1): ' + str(settings[0]) + '\n')
|
2020-08-06 18:22:56 +02:00
|
|
|
SettingsToSave.append('Kodowanie wyjsciowe: ' + str(settings[1]) + '\n')
|
|
|
|
|
SettingsToSave.append('Domena: ' + str(settings[2]) + '\n')
|
|
|
|
|
SettingsToSave.append('Quota: ' + str(settings[3]) + '\n')
|
2020-08-06 18:25:27 +02:00
|
|
|
SettingsToSave.append('Kraj: ' + str(settings[4]) + '\n')
|
|
|
|
|
SettingsToSave.append('Dlugosc liceum: ' + str(settings[5]) + '\n')
|
|
|
|
|
SettingsToSave.append('Dlugosc branzowej: ' + str(settings[6]))
|
2020-08-06 18:12:58 +02:00
|
|
|
with open('.\config.cfg', 'w') as cfg:
|
|
|
|
|
for x in SettingsToSave:
|
2020-08-06 18:25:27 +02:00
|
|
|
cfg.write(x)
|