[client,dump_creds] Passage à argparse
This commit is contained in:
parent
5180bb4b53
commit
05c4ead03d
2 changed files with 42 additions and 41 deletions
|
@ -6,7 +6,7 @@ from __future__ import print_function
|
|||
import pika
|
||||
import json
|
||||
import sys
|
||||
|
||||
import argparse
|
||||
from lc_ldap.shortcuts import lc_ldap_admin
|
||||
from affich_tools import prompt
|
||||
import lc_ldap.filter2 as filter
|
||||
|
@ -19,27 +19,30 @@ conf_wifi_only = True
|
|||
conf_reset_password = False
|
||||
conf_filter = None
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
if arg == '--all':
|
||||
conf_wifi_only = False
|
||||
elif arg == '--pass':
|
||||
conf_reset_password = True
|
||||
elif arg == '--debug':
|
||||
pass
|
||||
elif arg == '--aux':
|
||||
pass
|
||||
elif arg.startswith('--'):
|
||||
print("Unknown arg")
|
||||
exit(12)
|
||||
else:
|
||||
conf_filter = arg
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--all", help="Affiche toutes les machines, fixe et mobiles", action="store_true")
|
||||
parser.add_argument("--pwd", help="Réinitialise le mot de passe de l'adhérent", action="store_true")
|
||||
parser.add_argument("--debug", help="Réinitialise le mot de passe de l'adhérent", action="store_true")
|
||||
parser.add_argument("--aux", help="Choisir l'imprimante auxilliaire", action="store_true")
|
||||
parser.add_argument("conf_filter", help="Filtre pour la recherche d'un adhérent dans la bas")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if args.all:
|
||||
conf_wifi_only = False
|
||||
elif args.pwd:
|
||||
conf_reset_password = True
|
||||
elif args.debug:
|
||||
pass
|
||||
elif args.aux:
|
||||
pass
|
||||
|
||||
conf_filter = args.conf_filter
|
||||
|
||||
f = filter.human_to_ldap(conf_filter.decode('utf-8'))
|
||||
res = ldap.search(f, mode='rw')
|
||||
if not conf_filter:
|
||||
print("Give a filter !")
|
||||
exit(3)
|
||||
elif len(res) > 1:
|
||||
if len(res) > 1:
|
||||
print("More than one result")
|
||||
exit(1)
|
||||
elif not res:
|
||||
|
@ -61,7 +64,7 @@ else:
|
|||
elif c == 'o':
|
||||
break
|
||||
|
||||
ticket = Ticket()
|
||||
ticket = Ticket(args.debug,args.aux)
|
||||
if 'uid' in item and conf_reset_password:
|
||||
ticket.reset_password(item)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue