Commit 5818abbd authored by Valentin Samir's avatar Valentin Samir
Browse files

[sip/impression] Si l'appelant est nounou ou imprimeur, on lui génère un code

parent 99b8dd44
#!/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.attributs import imprimeur, nounou
conn=lc_ldap.shortcuts.lc_ldap_admin()
code_path='/usr/scripts/var/digicode/'
try:
aid=int(sys.argv[1][1:])
except ValueError:
sys.stdout.write('NONE')
exit(0)
login=conn.search(u"aid=%s" % aid)[0]['uid'][0]
adh = conn.search(u"aid=%s" % aid)[0]
login = str(adh.get('uid',['NONE'])[0])
try:
sys.stdout.write(grep('-r',login,'/usr/scripts/var/digicode/').split('/')[-1].split(':')[0])
except ErrorReturnCode_1: sys.stdout.write('NONE')
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))
else:
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