.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] [DEFAULT]
IFPassdir = \\192.168.1.1\SSIC\04-Projets\IFPass IFPassdir = \\192.168.1.1\ssic\04-Projets\IFPass
printername = XPS card printer printername = XPS Pink Card Printer
AcrobatReader = C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe 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 from termcolor import colored
version = 'dev' version = 'devnocam' # dev/devnocam
configfile = 'IFPass.conf' config = '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')
def initialisation(): 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) 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: 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"])
return IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate
def get_fullname(): def get_fullname():
@ -190,7 +198,9 @@ def fillcard(barcode):
# Barcode + picture embedding : # Barcode + picture embedding :
im.paste(barcode,(556, 460)) im.paste(barcode,(556, 460))
im.paste(picture,(47, 49))
if version != 'devnocam':
im.paste(picture,(47, 49))
# Create PDF : # Create PDF :
im = im.convert("RGB") im = im.convert("RGB")
@ -221,7 +231,6 @@ def mergepdf():
def printcard(cartefilename): def printcard(cartefilename):
# Working : subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + ' '+ printername, shell=False) # 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) 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') f = Figlet(font='big')
print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold'])) print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold']))
print('Version : ', version) 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('\nLe programme IFPass à été écrit par Jordan ERNST Q1 2018.')
print('Pour toute question ou problème contactez-moi à pro.ernst@gmail.com.\n') print('Pour toute question ou problème contactez-moi à pro.ernst@gmail.com.\n')
titre, firstname, surname, fullname = get_fullname() titre, firstname, surname, fullname = get_fullname()
@ -259,13 +270,14 @@ while "the informations are incorrect": # Loop Filling informations
if correct: if correct:
os.system('cls') os.system('cls')
initialisation() IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
picture = getpic() if version != 'devnocam':
picture = getpic()
clientID = getclientID() clientID = getclientID()
barcode = barcode_gen(clientID) barcode = barcode_gen(clientID)
fillcard(barcode) fillcard(barcode)
cartefilename = mergepdf() cartefilename = mergepdf()
if version != 'dev' : if version not in ('dev', 'devnocam'):
bkpdb() bkpdb()
printcard(cartefilename) printcard(cartefilename)
sys.exit() sys.exit()