[client,dump_creds] Passage à argparse
This commit is contained in:
parent
5180bb4b53
commit
05c4ead03d
2 changed files with 42 additions and 41 deletions
40
client.py
40
client.py
|
@ -9,27 +9,9 @@ import random
|
||||||
import datetime
|
import datetime
|
||||||
import string
|
import string
|
||||||
from lc_ldap import crans_utils
|
from lc_ldap import crans_utils
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
|
|
||||||
import sys
|
import sys
|
||||||
if '--debug' in sys.argv[1:]:
|
|
||||||
CREDS = pika.credentials.PlainCredentials('rasputin', secrets.get('rabbitmq_rasputin'), True)
|
|
||||||
|
|
||||||
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
|
|
||||||
port=5671, credentials=CREDS, ssl=True)
|
|
||||||
rabbit_c = pika.BlockingConnection(PARAMS)
|
|
||||||
|
|
||||||
ch = rabbit_c.channel()
|
|
||||||
if '--debug' in sys.argv[1:]:
|
|
||||||
QUEUE_NAME = 'CransTicketDebug'
|
|
||||||
print("Debug")
|
|
||||||
elif '--aux' in sys.argv[1:]:
|
|
||||||
QUEUE_NAME = config.AUXQUEUE
|
|
||||||
else:
|
|
||||||
QUEUE_NAME = config.MAINQUEUE
|
|
||||||
ch.queue_declare(QUEUE_NAME)
|
|
||||||
|
|
||||||
def gen_password():
|
def gen_password():
|
||||||
"""Génère un mot de passe aléatoire"""
|
"""Génère un mot de passe aléatoire"""
|
||||||
|
@ -39,8 +21,10 @@ def gen_password():
|
||||||
return ''.join([random.choice(chars) for _ in xrange(length)])
|
return ''.join([random.choice(chars) for _ in xrange(length)])
|
||||||
|
|
||||||
class Ticket(object):
|
class Ticket(object):
|
||||||
|
def __init__(self, debug=False, aux=False):
|
||||||
data = []
|
self.data = []
|
||||||
|
self.debug = debug
|
||||||
|
self.aux = aux
|
||||||
|
|
||||||
def add_entry(self, x):
|
def add_entry(self, x):
|
||||||
self.data.append(x)
|
self.data.append(x)
|
||||||
|
@ -115,7 +99,21 @@ class Ticket(object):
|
||||||
if not self.data:
|
if not self.data:
|
||||||
print("Nothing to print !")
|
print("Nothing to print !")
|
||||||
return
|
return
|
||||||
ch.basic_publish(exchange='', routing_key=QUEUE_NAME,
|
creds = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
|
||||||
|
if self.debug:
|
||||||
|
queue_name = 'CransTicketDebug'
|
||||||
|
creds = pika.credentials.PlainCredentials('rasputin', secrets.get('rabbitmq_rasputin'), True)
|
||||||
|
print("Debug")
|
||||||
|
elif self.aux:
|
||||||
|
queue_name = config.AUXQUEUE
|
||||||
|
else:
|
||||||
|
queue_name = config.MAINQUEUE
|
||||||
|
params = pika.ConnectionParameters(host='rabbitmq.crans.org',
|
||||||
|
port=5671, credentials=creds, ssl=True)
|
||||||
|
rabbit_c = pika.BlockingConnection(params)
|
||||||
|
ch = rabbit_c.channel()
|
||||||
|
ch.queue_declare(queue_name)
|
||||||
|
ch.basic_publish(exchange='', routing_key=queue_name,
|
||||||
body=json.dumps(self.data))
|
body=json.dumps(self.data))
|
||||||
print("Un nouveau ticket est en cours d'impression ...")
|
print("Un nouveau ticket est en cours d'impression ...")
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from __future__ import print_function
|
||||||
import pika
|
import pika
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
from lc_ldap.shortcuts import lc_ldap_admin
|
from lc_ldap.shortcuts import lc_ldap_admin
|
||||||
from affich_tools import prompt
|
from affich_tools import prompt
|
||||||
import lc_ldap.filter2 as filter
|
import lc_ldap.filter2 as filter
|
||||||
|
@ -19,27 +19,30 @@ conf_wifi_only = True
|
||||||
conf_reset_password = False
|
conf_reset_password = False
|
||||||
conf_filter = None
|
conf_filter = None
|
||||||
|
|
||||||
for arg in sys.argv[1:]:
|
|
||||||
if arg == '--all':
|
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
|
conf_wifi_only = False
|
||||||
elif arg == '--pass':
|
elif args.pwd:
|
||||||
conf_reset_password = True
|
conf_reset_password = True
|
||||||
elif arg == '--debug':
|
elif args.debug:
|
||||||
pass
|
pass
|
||||||
elif arg == '--aux':
|
elif args.aux:
|
||||||
pass
|
pass
|
||||||
elif arg.startswith('--'):
|
|
||||||
print("Unknown arg")
|
conf_filter = args.conf_filter
|
||||||
exit(12)
|
|
||||||
else:
|
|
||||||
conf_filter = arg
|
|
||||||
|
|
||||||
f = filter.human_to_ldap(conf_filter.decode('utf-8'))
|
f = filter.human_to_ldap(conf_filter.decode('utf-8'))
|
||||||
res = ldap.search(f, mode='rw')
|
res = ldap.search(f, mode='rw')
|
||||||
if not conf_filter:
|
if len(res) > 1:
|
||||||
print("Give a filter !")
|
|
||||||
exit(3)
|
|
||||||
elif len(res) > 1:
|
|
||||||
print("More than one result")
|
print("More than one result")
|
||||||
exit(1)
|
exit(1)
|
||||||
elif not res:
|
elif not res:
|
||||||
|
@ -61,7 +64,7 @@ else:
|
||||||
elif c == 'o':
|
elif c == 'o':
|
||||||
break
|
break
|
||||||
|
|
||||||
ticket = Ticket()
|
ticket = Ticket(args.debug,args.aux)
|
||||||
if 'uid' in item and conf_reset_password:
|
if 'uid' in item and conf_reset_password:
|
||||||
ticket.reset_password(item)
|
ticket.reset_password(item)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue