
l'imprimante) darcs-hash:20060310160253-4ec08-4605443cba5bfa4c3d6c809f8368a8a9ae7a8422.gz
48 lines
1.3 KiB
Python
Executable file
48 lines
1.3 KiB
Python
Executable file
#! /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__)))
|