[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 string
|
||||
from lc_ldap import crans_utils
|
||||
|
||||
import config
|
||||
|
||||
CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
|
||||
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():
|
||||
"""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)])
|
||||
|
||||
class Ticket(object):
|
||||
|
||||
data = []
|
||||
def __init__(self, debug=False, aux=False):
|
||||
self.data = []
|
||||
self.debug = debug
|
||||
self.aux = aux
|
||||
|
||||
def add_entry(self, x):
|
||||
self.data.append(x)
|
||||
|
@ -115,7 +99,21 @@ class Ticket(object):
|
|||
if not self.data:
|
||||
print("Nothing to print !")
|
||||
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))
|
||||
print("Un nouveau ticket est en cours d'impression ...")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue