gnration d'un code impression pour yoann arnaud (responsable dbourage de
l'imprimante) darcs-hash:20060310160253-4ec08-4605443cba5bfa4c3d6c809f8368a8a9ae7a8422.gz
This commit is contained in:
parent
2b854ee013
commit
df940fcb08
1 changed files with 48 additions and 0 deletions
48
impression/gen_code.py
Executable file
48
impression/gen_code.py
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: iso8859-15 -*-
|
||||||
|
|
||||||
|
# import des modules
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
import os, sys
|
||||||
|
|
||||||
|
import random
|
||||||
|
rand=random.Random()
|
||||||
|
rand.seed()
|
||||||
|
|
||||||
|
sys.path.append('/usr/scripts/gestion')
|
||||||
|
from user_tests import getuser
|
||||||
|
|
||||||
|
# définition des exemptions
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
class NoCodeError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
def new_code(msg=''):
|
||||||
|
"""
|
||||||
|
Génération d'un nouveau code
|
||||||
|
"""
|
||||||
|
|
||||||
|
for i in range(1000):
|
||||||
|
code = rand.randint(100000, 999999)
|
||||||
|
if not os.path.exists("/var/impression/codes/%d" % code):
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Pas de code disponible
|
||||||
|
raise NoCodeError, 'Il n\'y a plus de code disponible'
|
||||||
|
|
||||||
|
# On enregistre le fichier avec le code pour numéro
|
||||||
|
codefichier = open("/var/impression/codes/%d" % code, 'w')
|
||||||
|
codefichier.write(msg+'\n')
|
||||||
|
codefichier.close()
|
||||||
|
return code
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# génère un nouveau code et l'affiche
|
||||||
|
print new_code('%s via %s'%(getuser(),os.path.abspath(__file__)))
|
Loading…
Add table
Add a link
Reference in a new issue