.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. # Written by Jordan ERNST Q1 2018.
# Contact : pro.ernst@gmail.com # Contact : pro.ernst@gmail.com
import configparser
import sys import sys
import os import os
import re import re
@ -23,26 +24,26 @@ from termcolor import colored
version = 'dev' version = 'dev'
computer = '' # 'mediatheque' or 'accueil' configfile = 'IFPass.conf'
if version == 'dev': if not os.path.exists(configfile):
IFPassdir = '\\\\192.168.1.1\SSIC\\04-Projets\IFPass\\' print('Erreur : Fichier de configuration introuvable !')
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.')
sys.exit() sys.exit()
clientsfile = IFPassdir + 'Clients_IFPass.csv' config = configparser.ConfigParser()
clientsbkpfile = IFPassdir + 'Clients_IFPass_backup.csv' config.read(configfile)
imgdir = IFPassdir + 'Cartes\\'
pdftemplate = IFPassdir + 'Templates\IFPass_PDF_Template.pdf' IFPassdir = config['DEFAULT']['IFPassdir']
pngtemplate = IFPassdir + 'Templates\IFPass_PNG_Template.png' printername = config['DEFAULT']['printername']
fonttemplate = IFPassdir + 'Templates\Roboto-Bold.ttf'
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(): def initialisation():
if not os.path.exists(imgdir): if not os.path.exists(imgdir):
@ -50,7 +51,7 @@ def initialisation():
if not os.path.exists(clientsfile): if not os.path.exists(clientsfile):
with open(clientsfile, 'w', newline='', encoding='utf-8') as csvfile: with open(clientsfile, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile, delimiter=';') 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(): def get_fullname():
@ -124,7 +125,7 @@ def getpic():
if k == 27: # Echap if k == 27: # Echap
print(colored('[OK]', 'green')) print(colored('[OK]', 'green'))
cv2.destroyAllWindows() cv2.destroyAllWindows()
defaultpicture = IFPassdir + 'Templates\default_avatar.jpg' defaultpicture = os.path.join(IFPassdir, 'Templates', 'default_avatar.jpg')
picture = Image.open(defaultpicture) picture = Image.open(defaultpicture)
return picture return picture
elif k & 0xFF == ord(' '): # Space elif k & 0xFF == ord(' '): # Space
@ -199,7 +200,7 @@ def fillcard(barcode):
def mergepdf(): def mergepdf():
cartefilename = imgdir + clientID + '.pdf' cartefilename = os.path.join(imgdir, clientID + '.pdf')
output = PdfFileWriter() output = PdfFileWriter()
pdf1 = PdfFileReader(imgdir + clientID + '_Front.pdf', 'rb') pdf1 = PdfFileReader(imgdir + clientID + '_Front.pdf', 'rb')
@ -219,9 +220,9 @@ def mergepdf():
def printcard(cartefilename): def printcard(cartefilename):
# CMD : "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t Carte.pdf "XPS Pink Card Printer" # Working : subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + ' '+ printername, shell=False)
subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + printername, shell=False) AcrobatReader = config['DEFAULT']['AcrobatReader']
print('test') subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' '+ printername, shell=False)
while "the informations are incorrect": # Loop Filling informations while "the informations are incorrect": # Loop Filling informations
@ -238,10 +239,10 @@ while "the informations are incorrect": # Loop Filling informations
dateinsc = dateinsc.strftime('%d/%m/%Y') dateinsc = dateinsc.strftime('%d/%m/%Y')
dateexp = dateexp.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: if changeexp:
while True: 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) 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: if match:
break break
@ -264,7 +265,7 @@ while "the informations are incorrect": # Loop Filling informations
barcode = barcode_gen(clientID) barcode = barcode_gen(clientID)
fillcard(barcode) fillcard(barcode)
cartefilename = mergepdf() cartefilename = mergepdf()
if version != 'dev' :
bkpdb() bkpdb()
if computer == 'mediatheque' or computer == 'accueil':
printcard(cartefilename) printcard(cartefilename)
sys.exit() sys.exit()