[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
59
lib/impression/digicode.py → impression/digicode.py
Normal file → Executable file
59
lib/impression/digicode.py → impression/digicode.py
Normal file → Executable file
|
@ -1,28 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# #############################################################
|
||||
# ..
|
||||
# .... ............ ........
|
||||
# . ....... . .... ..
|
||||
# . ... .. .. .. .. ..... . ..
|
||||
# .. .. ....@@@. .. . ........ .
|
||||
# .. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. ....
|
||||
# .@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... ....
|
||||
# @@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. ..
|
||||
# .@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. .....
|
||||
# ...@@@.... @@@ .@@.......... ........ ..... ..
|
||||
# . ..@@@@.. . .@@@@. .. ....... . .............
|
||||
# . .. .... .. .. . ... ....
|
||||
# . . .... ............. .. ...
|
||||
# .. .. ... ........ ... ...
|
||||
# ................................
|
||||
#
|
||||
# ..
|
||||
# .... ............ ........
|
||||
# . ....... . .... ..
|
||||
# . ... .. .. .. .. ..... . ..
|
||||
# .. .. ....@@@. .. . ........ .
|
||||
# .. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. ....
|
||||
# .@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... ....
|
||||
# @@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. ..
|
||||
# .@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. .....
|
||||
# ...@@@.... @@@ .@@.......... ........ ..... ..
|
||||
# . ..@@@@.. . .@@@@. .. ....... . .............
|
||||
# . .. .... .. .. . ... ....
|
||||
# . . .... ............. .. ...
|
||||
# .. .. ... ........ ... ...
|
||||
# ................................
|
||||
#
|
||||
# #############################################################
|
||||
"""
|
||||
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
|
||||
|
@ -50,18 +51,18 @@ if socket.gethostname() != CODES_SERVER:
|
|||
#raise EnvironmentError, "La manipulation des codes pour le digicode n'est possible que sur %s" % CODES_SERVER
|
||||
else:
|
||||
FAKE_DIR = False
|
||||
|
||||
|
||||
def __del__():
|
||||
if FAKE_DIR:
|
||||
os.rmdir(CODES_DIR)
|
||||
|
||||
|
||||
|
||||
def __init__():
|
||||
pass
|
||||
# ###############################
|
||||
# save_code
|
||||
# ###############################
|
||||
# enregistre le codes avec "monString" dans le fichier
|
||||
# enregistre le codes avec "monString" dans le fichier
|
||||
#
|
||||
def save_code(code, monString=""):
|
||||
"""enregistre le codes avec "monString" dans le fichier """
|
||||
|
@ -80,7 +81,7 @@ def save_code(code, monString=""):
|
|||
# gen_code
|
||||
# ###############################
|
||||
# genere un code aleatoire
|
||||
# et l'enregistre
|
||||
# et l'enregistre
|
||||
#
|
||||
def gen_code(user_name):
|
||||
""" Genere un code au hasard l'enregistre avec user_name dans le fichier"""
|
||||
|
@ -88,14 +89,14 @@ def gen_code(user_name):
|
|||
rand=random.Random()
|
||||
# Graine automatique avec le temps
|
||||
rand.seed()
|
||||
|
||||
|
||||
for i in range(1000):
|
||||
# On genere un code
|
||||
code = rand.randint(100000, 999999)
|
||||
# Si le code est libre, on sort de la boucle
|
||||
if not os.path.exists( os.path.join( CODES_DIR, str( code ) ) ):
|
||||
break
|
||||
|
||||
|
||||
else:
|
||||
# Pas de code disponible
|
||||
print ("ERROR: Il n'y a pas de code disponible" )
|
||||
|
@ -131,15 +132,15 @@ 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')
|
||||
lineStr = myfile.readline()
|
||||
myfile.close()
|
||||
return lineStr.replace('\n','')
|
||||
|
||||
|
||||
|
||||
|
||||
# ###############################
|
||||
# menage
|
||||
# ###############################
|
|
@ -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