diff --git a/build_executable_win.ps1 b/build_executable_win.ps1 index 6f57334..6ef9db3 100644 --- a/build_executable_win.ps1 +++ b/build_executable_win.ps1 @@ -1,4 +1,4 @@ ./init_venv.ps1 -.venv/bin/activate +.venv/Scripts/Activate.ps1 pyinstaller main.spec -deactivate \ No newline at end of file +deactivate diff --git a/init_venv.ps1 b/init_venv.ps1 index 0decbe3..76208a5 100644 --- a/init_venv.ps1 +++ b/init_venv.ps1 @@ -1,7 +1,7 @@ echo "Creating venv" -python3 -m venv .venv -.venv/bin/activate +python -m venv .venv +.venv/Scripts/Activate.ps1 python -m pip install --upgrade pip echo "Installing python packages from requirements.txt" pip install -r requirements.txt diff --git a/main.spec b/main.spec index 12509dc..5a25694 100755 --- a/main.spec +++ b/main.spec @@ -1,14 +1,12 @@ # -*- mode: python ; coding: utf-8 -*- from PyInstaller.utils.hooks import collect_data_files from PyInstaller.utils.hooks import copy_metadata -import platform +#import site -python_version = platform.python_version() -last_dot = python_version.rfind('.') -python_version = python_version[0:last_dot] +#site_packages_path = site.getsitepackages() datas = [('img/dpsg_logo.png', 'img'), ('img/favicon.ico', 'img')] -datas.append((f'.venv/lib/python{python_version}/site-packages/schwifty/bank_registry/', 'bank_registry')) -datas.append((f'.venv/lib/python{python_version}/site-packages/schwifty/iban_registry/', 'iban_registry')) +#datas.append((f'{site_packages_path[1]}/schwifty/bank_registry/', 'bank_registry')) +#datas.append((f'{site_packages_path[1]}/schwifty/iban_registry/', 'iban_registry')) datas += collect_data_files('sv_ttk') datas += collect_data_files('pycountry') datas += collect_data_files('schwifty') diff --git a/src/accounting.py b/src/accounting.py index 77d861a..14267e5 100755 --- a/src/accounting.py +++ b/src/accounting.py @@ -1,9 +1,11 @@ +import sys import csv from vr_import import VRImport, VRMandat import tools import datetime from marshmallow import exceptions from pdf_converter import PdfConverter, PdfMemberList +from os import path from pathlib import Path import logging import tkinter as tk @@ -49,7 +51,8 @@ def get_designated_use(self, accounting_year, bookingHalfYear: tools.BookingHalf class NamiAccounting: - def __init__(self, config: tools.Config, memberTree, nami:Nami, sepa:Sepa): + def __init__(self, config_path: str, config: tools.Config, memberTree, nami:Nami, sepa:Sepa): + self._config_path = config_path self._config = config self._memberTree = memberTree self._nami = nami @@ -344,8 +347,10 @@ def download_invoices(self) -> PdfMemberList: print('Herunterladen aller Rechnungen aus der Nami...') year_start_date = datetime.date(self._config.get_accounting_year(), 1,1) billing_sum = 0 - members_overall = [] - Path('../invoices/').mkdir(parents=True, exist_ok=True) + members_overall = [] + invoice_path = path.join(self._config_path, 'invoices') + print(invoice_path) + Path(invoice_path).mkdir(parents=True, exist_ok=True) nami = self._nami.get_nami_interface() groupId = nami.grpId @@ -355,7 +360,7 @@ def download_invoices(self) -> PdfMemberList: if n.reDatum >= year_start_date: billing_sum = billing_sum + float(n.reNetto[:-4].replace(',', '.')) invoice = nami.invoice(groupId, n.id) - filename = './invoices/' + str(n.id)+'.pdf' + filename = path.join(invoice_path, str(n.id)+'.pdf') nami.download_invoice(n.id, open_file=False, save_file=True, filename=filename) members = PdfConverter.convert(pdfpath=filename) members_overall.extend(members) @@ -378,4 +383,4 @@ def remove_unused_members(self, members : list, bookingPeriod : tools.BookingHal elif bookingPeriod == tools.BookingHalfYear.BOTH and \ m.datumBis <= self._config.get_key_date_second_half(): members_new.append(m) - return members_new \ No newline at end of file + return members_new diff --git a/src/main.py b/src/main.py index d060729..f0b6471 100644 --- a/src/main.py +++ b/src/main.py @@ -18,18 +18,20 @@ class RunAccounting(Thread): - def __init__(self, config: Config, memberTree, nami: Nami, sepa: Sepa): + def __init__(self, config_path: str, config: Config, memberTree, nami: Nami, sepa: Sepa): super().__init__() - self.m = NamiAccounting(config, memberTree, nami, sepa) + self.m = NamiAccounting(config_path, config, memberTree, nami, sepa) def run(self): self.m.process() class App(ttk.Frame): - def __init__(self, parent): + def __init__(self, parent, root_path: str): ttk.Frame.__init__(self, parent) self._parent = parent + self._root_path = root_path + # Init self._nami = None self._sepa = None @@ -39,7 +41,12 @@ def __init__(self, parent): self._parent.bind('', self.save) # Read Config - self._config = Config('../config.ini') + self._config_root_path = self._root_path + if getattr(sys, 'frozen', False): + self._config_root_path = path.dirname(sys.executable) + + config_path = path.join(self._config_root_path, 'config.ini') + self._config = Config(config_path) # Read some stuff from the theme (colors and font) self._color_foreground = '#fafafa' @@ -115,11 +122,7 @@ def __init__(self, parent): # get path to image. Do it this way to allow the correct image path search with pyinstaller try: # Get the absolute path of the temp directory - pathToDpsgLogo = path.abspath(path.join(path.dirname(__file__), '../img/dpsg_logo.png')) - # Different folder, if application got build - if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): - pathToDpsgLogo = path.abspath(path.join(path.dirname(__file__), 'img/dpsg_logo.png')) - + pathToDpsgLogo = path.join(self._root_path, 'img/dpsg_logo.png') # Set the dpsg logo self.dpsgImage = tk.PhotoImage(file=pathToDpsgLogo) self.dpsgImageLabel = ttk.Label(master=self.frame_login, image=self.dpsgImage, anchor="w") @@ -291,11 +294,14 @@ def __init__(self, parent): def nami_login(self): username = self.usernameEntry.get() password = self.passwordEntry.get() + self.config(cursor="watch") + self.update() nami = Nami(username, password) self._nami = None if nami.check_login(): self._nami = nami - + self.config(cursor="") + def position_path_open_dialog(self): filetypes = (('csv files', '*.csv'),) filePath = filedialog.askopenfilename(title='VR-Networld Mandate Pfad', filetypes=filetypes) @@ -336,7 +342,7 @@ def start(self): logging.error('Gläubiger Identifikation inkorrekt. Bitte nochmal die Daten überprüfen.') return - process = RunAccounting(self._config, self.memberTree, self._nami, self._sepa) + process = RunAccounting(self._config_root_path, self._config, self.memberTree, self._nami, self._sepa) process.start() self.monitor(process) @@ -415,9 +421,16 @@ def main(): root = tk.Tk() root.title("Nami Beitragsrechner Version 0.2") + # Get the root path of the executable or main.py script + # Get the absolute path of the temp directory + root_path = path.abspath(path.join(path.dirname(__file__), '../')) + # Different folder, if application got build + if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): + root_path = path.abspath(path.dirname(__file__)) + try: # Get the absolute path of the temp directory - pathToDpsgIcon = path.abspath(path.join(path.dirname(__file__), '../img/favicon.ico')) + pathToDpsgIcon = path.join(root_path, 'img/favicon.ico') # Set the DPSG Logo as icon root.iconbitmap(pathToDpsgIcon) except: @@ -425,7 +438,7 @@ def main(): sv_ttk.set_theme("light") - app = App(root) + app = App(root, root_path) app.pack(fill="both", expand=True) root.update_idletasks() # Make sure every screen redrawing is done diff --git a/src/tools.py b/src/tools.py index fbeee02..3e2c22b 100644 --- a/src/tools.py +++ b/src/tools.py @@ -72,17 +72,14 @@ def __init__(self, name, iban, bic, id): class Config: def __init__(self, configPath): + self._config_path = configPath self._config = configparser.ConfigParser() self._config.read(configPath) # Update ensures that all necessary fields are avialable in the config ini file self.update_config() def save(self): - save_path = '../config.ini' - # Different path if application got build - if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): - save_path = 'config.ini' - with open(save_path, 'w') as configfile: + with open(self._config_path, 'w') as configfile: self._config.write(configfile) def get_nami_username(self): @@ -220,4 +217,4 @@ def update_config(self): if (self._config.has_option('Creditor ID', 'bic')) is False: self._config.set('Creditor ID', 'bic', '') if (self._config.has_option('Creditor ID', 'id')) is False: - self._config.set('Creditor ID', 'id', '') \ No newline at end of file + self._config.set('Creditor ID', 'id', '')