On ajoute un identifiant unique à chaque jobs
Ignore-this: 1db012c617fb2d46109c6f401b32bc9a darcs-hash:20120618061904-3a55a-dad5b531d133a383d1abdfa9f2cf548987922444.gz
This commit is contained in:
parent
80874f187b
commit
40d688c270
1 changed files with 23 additions and 5 deletions
|
@ -120,6 +120,16 @@ class SettingsError(Exception):
|
||||||
Erreur de paramètres.
|
Erreur de paramètres.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
def _uniq_jid():
|
||||||
|
""" Alloue un jid unique """
|
||||||
|
fname = '/var/impression/fichiers/jid'
|
||||||
|
## Maybe need a lock ?
|
||||||
|
f = file(fname,'r+')
|
||||||
|
cur = int(f.read())+1
|
||||||
|
f.seek(0)
|
||||||
|
f.write(str(cur))
|
||||||
|
f.close()
|
||||||
|
return cur
|
||||||
|
|
||||||
# ######################################################## #
|
# ######################################################## #
|
||||||
# CLASSE IMPRESSION #
|
# CLASSE IMPRESSION #
|
||||||
|
@ -159,6 +169,9 @@ class impression:
|
||||||
_width = 595.28
|
_width = 595.28
|
||||||
_height = 841.89
|
_height = 841.89
|
||||||
|
|
||||||
|
# Jid unique, à définir avant l'impression
|
||||||
|
_jid = 0
|
||||||
|
|
||||||
def __init__(self, path_to_pdf, adh = None):
|
def __init__(self, path_to_pdf, adh = None):
|
||||||
"""impression(path_to_pdf [, adh])
|
"""impression(path_to_pdf [, adh])
|
||||||
|
|
||||||
|
@ -357,12 +370,14 @@ class impression:
|
||||||
imprime le document pdf. débite l'adhérent si adhérent il y a.
|
imprime le document pdf. débite l'adhérent si adhérent il y a.
|
||||||
(si il a été indiqué à l'initialisation de l'objet)
|
(si il a été indiqué à l'initialisation de l'objet)
|
||||||
"""
|
"""
|
||||||
|
self._jid = _uniq_jid()
|
||||||
|
|
||||||
# debite l'adhérent si adherent il y a
|
# debite l'adhérent si adherent il y a
|
||||||
if (self._adh != None):
|
if (self._adh != None):
|
||||||
adh = self._get_adh(self._adh)
|
adh = self._get_adh(self._adh)
|
||||||
if (self._prix > (adh.solde() - DECOUVERT_AUTHORISE)):
|
if (self._prix > (adh.solde() - DECOUVERT_AUTHORISE)):
|
||||||
raise SoldeInsuffisant
|
raise SoldeInsuffisant
|
||||||
adh.solde(-self._prix, "impression: " + self._fichier)
|
adh.solde(-self._prix, "impression(%d): %s" % (self._jid,self._fichier))
|
||||||
adh.save()
|
adh.save()
|
||||||
del adh
|
del adh
|
||||||
# imprime le document
|
# imprime le document
|
||||||
|
@ -423,6 +438,8 @@ class impression:
|
||||||
adh = CransLdap().getProprio(adh, 'w')
|
adh = CransLdap().getProprio(adh, 'w')
|
||||||
return adh
|
return adh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ################################# ##
|
## ################################# ##
|
||||||
## fonction qui imprime pour de vrai ##
|
## fonction qui imprime pour de vrai ##
|
||||||
## ################################# ##
|
## ################################# ##
|
||||||
|
@ -434,9 +451,9 @@ class impression:
|
||||||
self._pdfbook()
|
self._pdfbook()
|
||||||
|
|
||||||
if (self._adh != None):
|
if (self._adh != None):
|
||||||
self.log.info('Impression [%s] : %s' % (self._adh, self._fichier))
|
self.log.info('Impression(%d) [%s] : %s' % (self._jid, self._adh, self._fichier))
|
||||||
else:
|
else:
|
||||||
self.log.info("Impression : %s" % self._fichier)
|
self.log.info("Impression(%d) : %s" % (self._jid, self._fichier))
|
||||||
|
|
||||||
# Envoi du fichier à CUPS
|
# Envoi du fichier à CUPS
|
||||||
options = ''
|
options = ''
|
||||||
|
@ -451,8 +468,8 @@ class impression:
|
||||||
options += ' -P canon_test'
|
options += ' -P canon_test'
|
||||||
|
|
||||||
|
|
||||||
# Pour spécifier un jobname de la forme adh:nom_du_fichier
|
# Pour spécifier un jobname de la forme jid:adh:nom_du_fichier
|
||||||
jobname = '%s:%s' % (self._adh, self._fichier.split('/')[-1].replace("\"","\\\""))
|
jobname = '%d:%s:%s' % (self._jid, self._adh, self._fichier.split('/')[-1].replace("\"","\\\""))
|
||||||
# Ce nom apparaît sur l'interface d'impression de l'imprimante:
|
# Ce nom apparaît sur l'interface d'impression de l'imprimante:
|
||||||
options += " -o CNDocName=\"%s\"" %jobname
|
options += " -o CNDocName=\"%s\"" %jobname
|
||||||
|
|
||||||
|
@ -532,3 +549,4 @@ class impression:
|
||||||
self.log.error("erreur impression")
|
self.log.error("erreur impression")
|
||||||
self.log.error("lpr status:%d | rep: %s" % (status, rep))
|
self.log.error("lpr status:%d | rep: %s" % (status, rep))
|
||||||
raise PrintError, "%s \n status:%d rep: %s" % (cmd, status, rep)
|
raise PrintError, "%s \n status:%d rep: %s" % (cmd, status, rep)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue