[lib/impression] on déplace tout dans impression
Ignore-this: f8064e9bceb8818911dcdaf73cb9f0ec darcs-hash:20090518184018-bd074-ae9530b4d2aba374d34d5a9e26e422c649d9e8db.gz
This commit is contained in:
parent
9e2cd076f5
commit
788012f862
7 changed files with 32 additions and 67 deletions
7
lib/impression/digicode.py → impression/digicode.py
Normal file → Executable file
7
lib/impression/digicode.py → impression/digicode.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# #############################################################
|
||||
# ..
|
||||
|
@ -18,11 +19,11 @@
|
|||
#
|
||||
# #############################################################
|
||||
"""
|
||||
fake_digicode.py
|
||||
digicode.py
|
||||
|
||||
Fonctions pour controler le digicode du 4@J (simulation)
|
||||
|
||||
Copyright (c) 2006 by www.crans.org
|
||||
Copyright (c) 2006, 2007, 2008, 2009 by Cr@ns (http://www.crans.org)
|
||||
"""
|
||||
import sys, time, tempfile, os, commands, string, random
|
||||
import crans.utils.files
|
||||
|
@ -131,7 +132,7 @@ def list_code():
|
|||
|
||||
def read_code_file(code):
|
||||
"""
|
||||
Lis le fichier correspondant à code.
|
||||
Lis le fichier correspondant au code.
|
||||
Renvoie le contenu du fichier.
|
||||
"""
|
||||
myfile = open(os.path.join(CODES_DIR, code ), 'r')
|
|
@ -1,48 +1,12 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# import des modules
|
||||
################################################################################
|
||||
|
||||
import os, sys
|
||||
|
||||
import random
|
||||
rand=random.Random()
|
||||
rand.seed()
|
||||
|
||||
sys.path.append('/usr/scripts/impression')
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
from digicode import gen_code
|
||||
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