.conf file reading aded - beautify paths

This commit is contained in:
Jordan ERNST 2018-04-18 12:05:44 +02:00
parent 13cfdf630c
commit 09fd78f425
2 changed files with 33 additions and 28 deletions

4
IFPass.conf Normal file
View File

@ -0,0 +1,4 @@
[DEFAULT]
IFPassdir = \\192.168.1.1\SSIC\04-Projets\IFPass
printername = XPS card printer
AcrobatReader = C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe

View File

@ -3,6 +3,7 @@
# Written by Jordan ERNST Q1 2018.
# Contact : pro.ernst@gmail.com
import configparser
import sys
import os
import re
@ -23,26 +24,26 @@ from termcolor import colored
version = 'dev'
computer = '' # 'mediatheque' or 'accueil'
configfile = 'IFPass.conf'
if version == 'dev':
IFPassdir = '\\\\192.168.1.1\SSIC\\04-Projets\IFPass\\'
elif computer == 'mediatheque':
IFPassdir = '\\\\192.168.1.1\IFPass\\'
printername = ' XPS Pink Card Printer'
elif computer == 'accueil':
IFPassdir = '\\\\192.168.1.1\IFPass\\'
printername = ' XPS Blue Card Printer'
else:
print('La variable "computer" est mal définie.')
if not os.path.exists(configfile):
print('Erreur : Fichier de configuration introuvable !')
sys.exit()
clientsfile = IFPassdir + 'Clients_IFPass.csv'
clientsbkpfile = IFPassdir + 'Clients_IFPass_backup.csv'
imgdir = IFPassdir + 'Cartes\\'
pdftemplate = IFPassdir + 'Templates\IFPass_PDF_Template.pdf'
pngtemplate = IFPassdir + 'Templates\IFPass_PNG_Template.png'
fonttemplate = IFPassdir + 'Templates\Roboto-Bold.ttf'
config = configparser.ConfigParser()
config.read(configfile)
IFPassdir = config['DEFAULT']['IFPassdir']
printername = config['DEFAULT']['printername']
clientsfile = os.path.join(IFPassdir, 'Clients_IFPass.csv')
clientsbkpfile = os.path.join(IFPassdir, 'Clients_IFPass_backup.csv')
imgdir = os.path.join(IFPassdir, 'Cartes')
pdftemplate = os.path.join(IFPassdir, 'Templates', 'IFPass_PDF_Template.pdf')
pngtemplate = os.path.join(IFPassdir, 'Templates', 'IFPass_PNG_Template.png')
fonttemplate = os.path.join(IFPassdir, 'Templates', 'Roboto-Bold.ttf')
def initialisation():
if not os.path.exists(imgdir):
@ -50,7 +51,7 @@ def initialisation():
if not os.path.exists(clientsfile):
with open(clientsfile, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile, delimiter=';')
writer.writerow(['Titre', 'Prénom', 'Nom', 'Numéro de client', 'Date d\'inscription', 'Date d\'expiration'])
writer.writerow(['Titre', 'Prénom', 'Nom', 'Numéro de client', "Date d'inscription", "Date d'expiration"])
def get_fullname():
@ -124,7 +125,7 @@ def getpic():
if k == 27: # Echap
print(colored('[OK]', 'green'))
cv2.destroyAllWindows()
defaultpicture = IFPassdir + 'Templates\default_avatar.jpg'
defaultpicture = os.path.join(IFPassdir, 'Templates', 'default_avatar.jpg')
picture = Image.open(defaultpicture)
return picture
elif k & 0xFF == ord(' '): # Space
@ -199,7 +200,7 @@ def fillcard(barcode):
def mergepdf():
cartefilename = imgdir + clientID + '.pdf'
cartefilename = os.path.join(imgdir, clientID + '.pdf')
output = PdfFileWriter()
pdf1 = PdfFileReader(imgdir + clientID + '_Front.pdf', 'rb')
@ -219,9 +220,9 @@ def mergepdf():
def printcard(cartefilename):
# CMD : "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t Carte.pdf "XPS Pink Card Printer"
subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + printername, shell=False)
print('test')
# Working : subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + ' '+ printername, shell=False)
AcrobatReader = config['DEFAULT']['AcrobatReader']
subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' '+ printername, shell=False)
while "the informations are incorrect": # Loop Filling informations
@ -229,7 +230,7 @@ while "the informations are incorrect": # Loop Filling informations
init()
f = Figlet(font='big')
print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold']))
print('Version :', version)
print('Version : ', version)
print('\nLe programme IFPass à été écrit par Jordan ERNST Q1 2018.')
print('Pour toute question ou problème contactez-moi à pro.ernst@gmail.com.\n')
titre, firstname, surname, fullname = get_fullname()
@ -238,10 +239,10 @@ while "the informations are incorrect": # Loop Filling informations
dateinsc = dateinsc.strftime('%d/%m/%Y')
dateexp = dateexp.strftime('%d/%m/%Y')
changeexp = yes_or_no('Voulez-vous choisir la date d\'expiration ?')
changeexp = yes_or_no("Voulez-vous choisir la date d'expiration ?")
if changeexp:
while True:
dateexp = input('Quelle date d\'expiration voulez-vous mettre (Format : JJ/MM/AAAA)? : ')
dateexp = input("Quelle date d'expiration voulez-vous mettre (Format : JJ/MM/AAAA)? : ")
match = re.fullmatch(r'^(0[1-9]|1[0-9]|2[0-9]|3[0-1])/(0[1-9]|1[0-2])/([0-9]){4}$', dateexp)
if match:
break
@ -264,7 +265,7 @@ while "the informations are incorrect": # Loop Filling informations
barcode = barcode_gen(clientID)
fillcard(barcode)
cartefilename = mergepdf()
bkpdb()
if computer == 'mediatheque' or computer == 'accueil':
if version != 'dev' :
bkpdb()
printcard(cartefilename)
sys.exit()