[sip/impression] Si l'appelant est nounou ou imprimeur, on lui génère un code
This commit is contained in:
parent
99b8dd44aa
commit
5818abbd8f
1 changed files with 18 additions and 3 deletions
|
@ -1,19 +1,34 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import random
|
||||||
from sh import grep,ErrorReturnCode_1
|
from sh import grep,ErrorReturnCode_1
|
||||||
sys.path.append('/usr/scripts/')
|
sys.path.append('/usr/scripts/')
|
||||||
|
|
||||||
import lc_ldap.shortcuts
|
import lc_ldap.shortcuts
|
||||||
|
from lc_ldap.attributs import imprimeur, nounou
|
||||||
|
|
||||||
conn=lc_ldap.shortcuts.lc_ldap_admin()
|
conn=lc_ldap.shortcuts.lc_ldap_admin()
|
||||||
|
code_path='/usr/scripts/var/digicode/'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
aid=int(sys.argv[1][1:])
|
aid=int(sys.argv[1][1:])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
sys.stdout.write('NONE')
|
sys.stdout.write('NONE')
|
||||||
exit(0)
|
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:
|
try:
|
||||||
sys.stdout.write(grep('-r',login,'/usr/scripts/var/digicode/').split('/')[-1].split(':')[0])
|
sys.stdout.write(grep('-rl',login, code_path).split('/')[-1])
|
||||||
except ErrorReturnCode_1: sys.stdout.write('NONE')
|
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')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue