Commit e0d37eb6 authored by Valentin Samir's avatar Valentin Samir

[sip/impression] On utilise l'api impression/digicode

parent 0e5fa7d1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import random
from sh import grep,ErrorReturnCode_1
sys.path.append('/usr/scripts/')
import lc_ldap.shortcuts
from lc_ldap.shortcuts import lc_ldap_admin
from lc_ldap.attributs import imprimeur, nounou
from impression import digicode
conn=lc_ldap.shortcuts.lc_ldap_admin()
code_path='/usr/scripts/var/digicode/'
conn=lc_ldap_admin()
try:
aid=int(sys.argv[1][1:])
except ValueError:
sys.stdout.write('NONE')
exit(0)
adh = conn.search(u"aid=%s" % aid)[0]
login = str(adh.get('uid',['NONE'])[0])
try:
sys.stdout.write(grep('-rl',login, code_path).split('/')[-1])
except ErrorReturnCode_1:
droits = [str(d) for d in adh.get('droits', [])]
if imprimeur in droits or nounou in droits:
code = str(random.randint(100000, 999999))
while os.path.isfile(code_path + code):
code = str(random.randint(100000, 999999))
with open(code_path + code, 'w') as f:
f.write(login + '\n')
sys.stdout.write(str(code))
adh = conn.search(u"aid=%s" % aid)[0]
login = str(adh.get('uid',['NONE'])[0])
codes = digicode.get_codes(login)
if codes:
sys.stdout.write(codes[0])
else:
sys.stdout.write('NONE')
droits = [str(d) for d in adh.get('droits', [])]
if imprimeur in droits or nounou in droits:
code = digicode.gen_code(login)
sys.stdout.write(str(code))
else:
sys.stdout.write('NONE')
except ValueError, IndexError:
sys.stdout.write('NONE')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment