Adapted script for distribution
This commit is contained in:
parent
a758d36a08
commit
d77465265c
50
IFPass.py
50
IFPass.py
@ -16,42 +16,42 @@ from pywinauto.win32functions import SetForegroundWindow
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from PyPDF2 import PdfFileReader, PdfFileWriter
|
||||
import subprocess
|
||||
from shutil import copyfile
|
||||
from shutil import copyfile, move
|
||||
from pyfiglet import Figlet
|
||||
from colorama import init
|
||||
from termcolor import colored
|
||||
|
||||
|
||||
version = '2.2'
|
||||
version = '2.5' # dev/devnocam
|
||||
|
||||
config = 'IFPass.conf'
|
||||
|
||||
|
||||
def initialisation():
|
||||
global clientsfile, IFPassdir, clientsfile, clientID, imgdir, dateexp, titre, dateinsc, firstname, surname, clientsbkpfile, pngtemplate, fonttemplate, fullname, picture, pdftemplate, printername, AcrobatReader
|
||||
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) : ')
|
||||
IFPassDBdir = input(r'Quel est le répertoire de la base de données 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}
|
||||
conf['DEFAULT'] = {'IFPassDBdir': IFPassDBdir, 'printername': printername, 'AcrobatReader': AcrobatReader}
|
||||
with open(config, 'w') as configfile:
|
||||
conf.write(configfile)
|
||||
move('Templates', IFPassDBdir)
|
||||
else:
|
||||
conf.read(config)
|
||||
IFPassdir = conf['DEFAULT']['IFPassdir']
|
||||
IFPassDBdir = conf['DEFAULT']['IFPassDBdir']
|
||||
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')
|
||||
clientsfile = os.path.join(IFPassDBdir, 'Clients_IFPass.csv')
|
||||
clientsbkpfile = os.path.join(IFPassDBdir, 'Clients_IFPass_backup.csv')
|
||||
imgdir = os.path.join(IFPassDBdir, 'Cartes')
|
||||
pdftemplate = os.path.join(IFPassDBdir, 'Templates', 'IFPass_PDF_Template.pdf')
|
||||
pngtemplate = os.path.join(IFPassDBdir, 'Templates', 'IFPass_PNG_Template.png')
|
||||
fonttemplate = os.path.join(IFPassDBdir, 'Templates', 'Roboto-Bold.ttf')
|
||||
|
||||
if not os.path.exists(imgdir): # Cartes dir creation if it doesn't exist
|
||||
os.makedirs(imgdir)
|
||||
@ -59,11 +59,17 @@ def initialisation():
|
||||
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
|
||||
return IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate
|
||||
|
||||
|
||||
def get_fullname():
|
||||
while "Empty firstname":
|
||||
firstname = input("Prénom : ").strip()
|
||||
if len(firstname) == 0:
|
||||
os.system('cls')
|
||||
print(colored("\nLe Prénom ne peut pas être vide.", 'red'))
|
||||
else:
|
||||
break
|
||||
firstname = firstname[0].upper() + firstname[1:].lower()
|
||||
if '-' in firstname:
|
||||
pos = firstname.find("-")
|
||||
@ -73,7 +79,13 @@ def get_fullname():
|
||||
pos = firstname.find(" ")
|
||||
firstname = firstname[:pos + 1] + firstname[pos + 1].upper() + \
|
||||
firstname[pos + 2:] # Check if compound name
|
||||
while "Empty surname":
|
||||
surname = input("Nom : ").upper().strip()
|
||||
if len(surname) == 0:
|
||||
os.system('cls')
|
||||
print(colored("\nLe Nom ne peut pas être vide.", 'red'))
|
||||
else:
|
||||
break
|
||||
docteur = yes_or_no('Est-ce un Docteur ?')
|
||||
if docteur:
|
||||
titre = 'Dr.'
|
||||
@ -131,19 +143,20 @@ def getpic():
|
||||
'pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.'))
|
||||
k = cv2.waitKey(1)
|
||||
if k == 27: # Echap
|
||||
cap.release()
|
||||
print(colored('[OK]', 'green'))
|
||||
cv2.destroyAllWindows()
|
||||
defaultpicture = os.path.join(IFPassdir, 'Templates', 'default_avatar.jpg')
|
||||
defaultpicture = os.path.join(IFPassDBdir, 'Templates', 'default_avatar.jpg')
|
||||
picture = Image.open(defaultpicture)
|
||||
return picture
|
||||
elif k & 0xFF == ord(' '): # Space
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
break
|
||||
elif k & 0xFF == ord('q'): # Q or q to quit
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
sys.exit()
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
cropped = frame[75:405, 172:468]
|
||||
cv2.imshow('IFCamera - Espace pour valider, Echap pour modifier, Q pour quitter', cropped)
|
||||
while True:
|
||||
@ -288,9 +301,10 @@ def membersearch():
|
||||
|
||||
|
||||
def main():
|
||||
global titre, firstname, surname, fullname, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader
|
||||
while "The program is running":
|
||||
init() # Initialisation of colorama
|
||||
IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
||||
IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
||||
|
||||
os.system('cls')
|
||||
f = Figlet(font='big')
|
||||
@ -305,7 +319,6 @@ def main():
|
||||
if choix == '1':
|
||||
while "the informations are incorrect": # Loop Filling informations
|
||||
os.system('cls')
|
||||
|
||||
titre, firstname, surname, fullname = get_fullname()
|
||||
dateinsc = date.today()
|
||||
dateexp = dateinsc + timedelta(days=365)
|
||||
@ -343,6 +356,7 @@ def main():
|
||||
bkpdb()
|
||||
printcard(cartefilename)
|
||||
break
|
||||
|
||||
elif choix == '2':
|
||||
os.system('cls')
|
||||
membersearch()
|
||||
|
Loading…
Reference in New Issue
Block a user