.conf file writing added - devnocam mode added

This commit is contained in:
Jordan ERNST 2018-04-18 16:31:48 +02:00
parent 09fd78f425
commit 040e3e9033
2 changed files with 44 additions and 31 deletions

View File

@ -1,4 +1,5 @@
[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
[DEFAULT]
IFPassdir = \\192.168.1.1\ssic\04-Projets\IFPass
printername = XPS Pink Card Printer
AcrobatReader = C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe

View File

@ -22,36 +22,44 @@ from colorama import init
from termcolor import colored
version = 'dev'
version = 'devnocam' # dev/devnocam
configfile = 'IFPass.conf'
if not os.path.exists(configfile):
print('Erreur : Fichier de configuration introuvable !')
sys.exit()
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')
config = 'IFPass.conf'
def initialisation():
if not os.path.exists(imgdir):
conf = configparser.ConfigParser()
conf.optionxform = str # For case sensitive config file
if not os.path.exists(config): # Check if config file exists
print('Fichier de configuration introuvable.')
IFPassdir = input(r'Quel est le répertoire IFPass ? (Ex : \\192.168.1.1\IFPass) : ')
printername = input("Quel est le nom de l'imprimante à cartes ? : " )
AcrobatReader = input(r"Quel est le chemain vers Acrobat Reader ? ( Ex : C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe) : ")
conf['DEFAULT'] = {'IFPassdir': IFPassdir, 'printername': printername, 'AcrobatReader': AcrobatReader}
with open(config, 'w') as configfile:
conf.write(configfile)
else:
conf.read(config)
IFPassdir = conf['DEFAULT']['IFPassdir']
printername = conf['DEFAULT']['printername']
AcrobatReader = conf['DEFAULT']['AcrobatReader']
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')
if not os.path.exists(imgdir): # Cartes dir creation if it doesn't exist
os.makedirs(imgdir)
if not os.path.exists(clientsfile):
if not os.path.exists(clientsfile): # Creation Clients_File if it doesn't exist
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"])
return IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate
def get_fullname():
@ -190,7 +198,9 @@ def fillcard(barcode):
# Barcode + picture embedding :
im.paste(barcode,(556, 460))
im.paste(picture,(47, 49))
if version != 'devnocam':
im.paste(picture,(47, 49))
# Create PDF :
im = im.convert("RGB")
@ -221,7 +231,6 @@ def mergepdf():
def printcard(cartefilename):
# 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)
@ -231,6 +240,8 @@ while "the informations are incorrect": # Loop Filling informations
f = Figlet(font='big')
print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold']))
print('Version : ', version)
if version in ('dev', 'devnocam'):
print(colored("\nATTENTION : Il s'agit d'une version en cours de développement, potentiellement instable !", 'red'))
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()
@ -259,13 +270,14 @@ while "the informations are incorrect": # Loop Filling informations
if correct:
os.system('cls')
initialisation()
picture = getpic()
IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
if version != 'devnocam':
picture = getpic()
clientID = getclientID()
barcode = barcode_gen(clientID)
fillcard(barcode)
cartefilename = mergepdf()
if version != 'dev' :
if version not in ('dev', 'devnocam'):
bkpdb()
printcard(cartefilename)
sys.exit()