on evite que l'impression garde longtemps un utilisateur locke en ecriture + fonctions pour la gestion des codes du digicode par l'intranet
darcs-hash:20061009172138-f46e9-a6141b3b4fa7cb02d9253b4436632bccf7859208.gz
This commit is contained in:
parent
ab37a42fe0
commit
b4965161f1
2 changed files with 89 additions and 16 deletions
|
@ -26,13 +26,9 @@
|
|||
"""
|
||||
__version__ = '1'
|
||||
|
||||
|
||||
import sys, syslog, os.path
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
import config
|
||||
#def __init__():
|
||||
# pass
|
||||
|
||||
import cout
|
||||
# ######################################################## #
|
||||
# CONSTANTES #
|
||||
|
@ -54,8 +50,7 @@ NB_AGRAPHES = {
|
|||
UNE_AGRAPHE: 1,
|
||||
DEUX_AGRAPHE: 2,
|
||||
TROIS_AGRAPHE: 3,
|
||||
STITCHING: 6,
|
||||
|
||||
STITCHING: 6,
|
||||
}
|
||||
|
||||
PAPIER_A4 = "A4"
|
||||
|
@ -161,7 +156,7 @@ class impression:
|
|||
|
||||
def __init__(self, path_to_pdf, adh = None):
|
||||
self._fichier = path_to_pdf
|
||||
self._adh = self._get_adh(adh)
|
||||
self._adh = adh
|
||||
# calcule le prix de l'encre tout de suite
|
||||
self._base_prix_couleurs, self._nb_pages = cout.base_prix_couleurs(path_to_pdf)
|
||||
self._base_prix_nb, self._nb_pages = cout.base_prix_nb(path_to_pdf)
|
||||
|
@ -234,10 +229,12 @@ class impression:
|
|||
def imprime(self):
|
||||
# debite l'adherent si adherent il y a
|
||||
if (self._adh != None):
|
||||
if (self._prix > (self._adh.solde() - DECOUVERT_AUTHORISE)):
|
||||
adh = self._get_adh(self._adh)
|
||||
if (self._prix > (adh.solde() - DECOUVERT_AUTHORISE)):
|
||||
raise SoldeInsuffisant
|
||||
self._adh.solde(-self._prix, "impression: " + self._fichier)
|
||||
self._adh.save()
|
||||
adh.solde(-self._prix, "impression: " + self._fichier)
|
||||
adh.save()
|
||||
del adh
|
||||
# imprime le document
|
||||
self._exec_imprime()
|
||||
|
||||
|
|
|
@ -23,9 +23,54 @@
|
|||
# Copyright (c) 2006 by www.crans.org
|
||||
# #############################################################
|
||||
import sys, time, tempfile, os, commands, string, random
|
||||
import crans.utils.files
|
||||
def __init__():
|
||||
pass
|
||||
# #############################################################
|
||||
# CONSTANTES
|
||||
# #############################################################
|
||||
CODES_SERVER = "zamok"
|
||||
CODES_DIR = "/var/impression/codes/"
|
||||
|
||||
# test pour voir si on est bien sur la bonne machine
|
||||
import socket
|
||||
if socket.gethostname() != CODES_SERVER:
|
||||
raise EnvironmentError, "La manipulation des codes pour le digicode n'est possible que sur %s" % CODES_SERVER
|
||||
|
||||
# #############################################################
|
||||
# EXCEPTIONS
|
||||
# #############################################################
|
||||
def CodeAlreadyExists(Exception):
|
||||
pass
|
||||
|
||||
# #############################################################
|
||||
# FONCTIONS
|
||||
# #############################################################
|
||||
|
||||
|
||||
# ###############################
|
||||
# save_code
|
||||
# ###############################
|
||||
# enregistre le codes avec "monString" dans le fichier
|
||||
#
|
||||
def save_code(code, monString=""):
|
||||
code = str(code)
|
||||
if os.path.exists( os.path.join( CODES_DIR, code ) ):
|
||||
raise CodeAlreadyExists
|
||||
# On enregistre le fichier avec le code pour numero
|
||||
codefichier = open( os.path.join( CODES_DIR, code ) , 'w')
|
||||
codefichier.write(monString)
|
||||
codefichier.write("\n")
|
||||
codefichier.close()
|
||||
return code
|
||||
|
||||
|
||||
# ###############################
|
||||
# gen_code
|
||||
# ###############################
|
||||
# genere un code aleatoire
|
||||
# et l'enregistre
|
||||
#
|
||||
def gen_code(user_name):
|
||||
""" Genere le code et l'enregistre dans /var/impression/codes pour radius """
|
||||
# Generation du code et ecriture du code
|
||||
|
@ -37,7 +82,7 @@ def gen_code(user_name):
|
|||
# On genere un code
|
||||
code = rand.randint(100000, 999999)
|
||||
# Si le code est libre, on sort de la boucle
|
||||
if not os.path.exists("/var/impression/codes/%d" % code):
|
||||
if not os.path.exists( os.path.join( CODES_DIR, str( code ) ) ):
|
||||
break
|
||||
|
||||
else:
|
||||
|
@ -51,9 +96,40 @@ def gen_code(user_name):
|
|||
sys.stderr.write("ERROR: Plus de codes disponibles.\n")
|
||||
sys.stderr.write("ERROR: Penser a ouvrir a l'adherent debite...\n")
|
||||
return
|
||||
|
||||
# On enregistre le fichier avec le code pour numero
|
||||
codefichier = open("/var/impression/codes/%d" % code, 'w')
|
||||
codefichier.write("Utilisateur %s\n" % user_name)
|
||||
codefichier.close()
|
||||
save_code(code, user_name)
|
||||
return code
|
||||
|
||||
|
||||
# ###############################
|
||||
# list_code
|
||||
# ###############################
|
||||
# liste les codes et leur age en secondes
|
||||
#
|
||||
def list_code():
|
||||
files = os.listdir(CODES_DIR)
|
||||
code_list = []
|
||||
for aCode in files:
|
||||
age = crans.utils.files.ageOfFile(os.path.join(CODES_DIR, aCode ) )
|
||||
content = read_code_file(aCode)
|
||||
code_list.append((aCode, age, content ) )
|
||||
return code_list
|
||||
|
||||
def read_code_file(code):
|
||||
myfile = open(os.path.join(CODES_DIR, code ), 'r')
|
||||
lineStr = myfile.readline()
|
||||
myfile.close()
|
||||
return lineStr.replace('\n','')
|
||||
|
||||
|
||||
# ###############################
|
||||
# menage
|
||||
# ###############################
|
||||
# supprime les codes vieux de plus de 24h
|
||||
#
|
||||
def menage():
|
||||
fileList = os.listdir(CODES_DIR)
|
||||
for aFile in fileList:
|
||||
aFilePath = os.path.join(CODES_DIR, aFile)
|
||||
if os.path.isfile(aFilePath):
|
||||
if crans.utils.files.fileIsOlderThan(aFilePath, days=1):
|
||||
os.remove(aFilePath)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue