digicode: clean up vieux bouts de codes
This commit is contained in:
parent
14993b4b39
commit
9e8f697a23
1 changed files with 9 additions and 30 deletions
|
@ -21,7 +21,7 @@
|
|||
"""
|
||||
digicode.py
|
||||
|
||||
Fonctions pour controler le digicode du 4@J (simulation)
|
||||
Fonctions pour controler le digicode du 4@J
|
||||
|
||||
Copyright (c) 2006, 2007, 2008, 2009 by Cr@ns (http://www.crans.org)
|
||||
"""
|
||||
|
@ -35,45 +35,29 @@ import random
|
|||
import requests
|
||||
if not '/usr/scripts' in sys.path:
|
||||
sys.path.append("/usr/scripts")
|
||||
import cranslib.utils.files
|
||||
|
||||
import gestion.secrets_new as secrets_new
|
||||
from cranslib.deprecated import deprecated
|
||||
|
||||
digicode_pass = secrets_new.get("digicode_pass")
|
||||
# #############################################################
|
||||
# CONSTANTES
|
||||
# #############################################################
|
||||
CODES_SERVERS = ["zamok", "asterisk"]
|
||||
CODES_SERVERS = ["zamok", "asterisk", "vo"]
|
||||
CODES_DIR = "/usr/scripts/var/digicode/"
|
||||
CREATION_LINK = "https://intranet2.crans.org/digicode/create/"
|
||||
LIST_LINK = "https://intranet2.crans.org/digicode/list/"
|
||||
CERTIFICATE = "/etc/ssl/certs/cacert.org.pem"
|
||||
|
||||
# #############################################################
|
||||
# EXCEPTIONS
|
||||
# #############################################################
|
||||
def CodeAlreadyExists(Exception):
|
||||
pass
|
||||
|
||||
# #############################################################
|
||||
# FONCTIONS
|
||||
# #############################################################
|
||||
# test pour voir si on est bien sur la bonne machine
|
||||
import socket
|
||||
if socket.gethostname() not in CODES_SERVERS:
|
||||
CODES_DIR = tempfile.mkdtemp(prefix='fake_digicode')
|
||||
FAKE_DIR = True
|
||||
raise EnvironmentError("La manipulation des codes pour le digicode n'est possible que sur %s" %
|
||||
', '.join(CODES_SERVERS))
|
||||
else:
|
||||
FAKE_DIR = False
|
||||
|
||||
def __del__():
|
||||
if FAKE_DIR:
|
||||
os.rmdir(CODES_DIR)
|
||||
|
||||
|
||||
def __init__():
|
||||
pass
|
||||
# ###############################
|
||||
# save_code
|
||||
# ###############################
|
||||
|
@ -122,15 +106,13 @@ def list_code(login=None):
|
|||
def get_codes(login):
|
||||
return [code for (code, age, uid) in list_code(login)]
|
||||
|
||||
@deprecated
|
||||
def read_code_file(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','')
|
||||
return "dummy"
|
||||
|
||||
|
||||
# ###############################
|
||||
|
@ -138,13 +120,10 @@ def read_code_file(code):
|
|||
# ###############################
|
||||
# supprime les codes vieux de plus de 24h
|
||||
#
|
||||
@deprecated
|
||||
def menage():
|
||||
"""
|
||||
Supprime les codes vieux de plus de 24h
|
||||
dummy fun
|
||||
"""
|
||||
fileList = os.listdir(CODES_DIR)
|
||||
for aFile in fileList:
|
||||
aFilePath = os.path.join(CODES_DIR, aFile)
|
||||
if os.path.isfile(aFilePath):
|
||||
if cranslib.utils.files.fileIsOlderThan(aFilePath, days=1):
|
||||
os.remove(aFilePath)
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue