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