[gen_code.py] strip-trailing-ws
Ignore-this: 20199bd05d92bf9d4f2b2c396bce9ca2 darcs-hash:20090514155532-bd074-aa4f11eeaab255dff821dcf37878c35b9e277bd5.gz
This commit is contained in:
parent
35cc9fa3d3
commit
03955ca315
1 changed files with 7 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso8859-15 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# import des modules
|
||||
################################################################################
|
||||
|
@ -13,7 +13,7 @@ rand.seed()
|
|||
sys.path.append('/usr/scripts/gestion')
|
||||
from user_tests import getuser
|
||||
|
||||
# définition des exemptions
|
||||
# définition des exemptions
|
||||
################################################################################
|
||||
|
||||
class NoCodeError(Exception):
|
||||
|
@ -23,19 +23,19 @@ class NoCodeError(Exception):
|
|||
|
||||
def new_code(msg=''):
|
||||
"""
|
||||
Génération d'un nouveau code
|
||||
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
|
||||
# On enregistre le fichier avec le code pour numéro
|
||||
codefichier = open("/var/impression/codes/%d" % code, 'w')
|
||||
codefichier.write(msg+'\n')
|
||||
codefichier.close()
|
||||
|
@ -44,5 +44,5 @@ def new_code(msg=''):
|
|||
################################################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
# génère un nouveau code et l'affiche
|
||||
# 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