Skip to content

Commit

Permalink
Merge pull request #12 from f1shl/pyinstaller-bugfixes
Browse files Browse the repository at this point in the history
Pyinstaller bugfixes
  • Loading branch information
f1shl authored Jul 25, 2024
2 parents 6f4d5e9 + bdf481c commit 6a4f104
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
4 changes: 2 additions & 2 deletions build_executable_win.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
./init_venv.ps1
.venv/bin/activate
.venv/Scripts/Activate.ps1
pyinstaller main.spec
deactivate
deactivate
4 changes: 2 additions & 2 deletions init_venv.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 4 additions & 6 deletions main.spec
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
15 changes: 10 additions & 5 deletions src/accounting.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
return members_new
39 changes: 26 additions & 13 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +41,12 @@ def __init__(self, parent):
self._parent.bind('<Control-s>', 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'
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -415,17 +421,24 @@ 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:
pass

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
Expand Down
9 changes: 3 additions & 6 deletions src/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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', '')
self._config.set('Creditor ID', 'id', '')

0 comments on commit 6a4f104

Please sign in to comment.