From 63e3df8d0c5fe6651e55c8ad78cb70b36a69cad6 Mon Sep 17 00:00:00 2001 From: Bo-Chun Louis Chen <louistw@uab.edu> Date: Tue, 7 Jun 2022 17:20:03 -0500 Subject: [PATCH] Fix pylint consider-using-f-string --- agent_template.py | 4 ++-- dev_rmq_agents/ohpc_account_create.py | 8 ++++---- dev_rmq_agents/ood_account_create.py | 8 ++++---- dev_rmq_agents/slurm_agent.py | 8 ++++---- flask_producer.py | 8 ++++---- prod_rmq_agents/get-next-uid-gid.py | 6 +++--- prod_rmq_agents/subscribe_mail_lists.py | 6 +++--- prod_rmq_agents/user_reg_event_logger.py | 2 +- prod_rmq_agents/user_reg_logger.py | 2 +- rc_rmq.py | 23 ++++++++--------------- 10 files changed, 34 insertions(+), 41 deletions(-) diff --git a/agent_template.py b/agent_template.py index 16176c4..80e3eff 100644 --- a/agent_template.py +++ b/agent_template.py @@ -21,13 +21,13 @@ def on_message(ch, method, properties, body): print(msg) # Do Something - print("[{}]: Callback called.".format(task)) + print(f"[{task}]: Callback called.") # Acknowledge message ch.basic_ack(delivery_tag=method.delivery_tag) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( { "queue": task, # Define your Queue name diff --git a/dev_rmq_agents/ohpc_account_create.py b/dev_rmq_agents/ohpc_account_create.py index fa83fe6..f15a786 100644 --- a/dev_rmq_agents/ohpc_account_create.py +++ b/dev_rmq_agents/ohpc_account_create.py @@ -14,16 +14,16 @@ rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"}) def ohpc_account_create(ch, method, properties, body): msg = json.loads(body) - print("Message received {}".format(msg)) + print(f"Message received {msg}") username = msg["username"] success = False try: subprocess.call(["sudo", "useradd", username]) - print("[{}]: User {} has been added".format(task, username)) + print(f"[{task}]: User {username} has been added") success = True except Exception: e = sys.exc_info()[0] - print("[{}]: Error: {}".format(task, e)) + print(f"[{task}]: Error: {e}") ch.basic_ack(delivery_tag=method.delivery_tag) msg["uid"] = getpwnam(username).pw_uid @@ -42,7 +42,7 @@ def ohpc_account_create(ch, method, properties, body): rc_rmq.publish_msg({"routing_key": "create." + username, "msg": msg}) -print("Start Listening to queue: {}".format(task)) +print(f"Start Listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "request.*", "cb": ohpc_account_create} ) diff --git a/dev_rmq_agents/ood_account_create.py b/dev_rmq_agents/ood_account_create.py index 57e7a9b..482ba31 100644 --- a/dev_rmq_agents/ood_account_create.py +++ b/dev_rmq_agents/ood_account_create.py @@ -13,7 +13,7 @@ rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"}) def ood_account_create(ch, method, properties, body): msg = json.loads(body) - print("Message received {}".format(msg)) + print(f"Message received {msg}") username = msg["username"] user_uid = str(msg["uid"]) user_gid = str(msg["gid"]) @@ -23,11 +23,11 @@ def ood_account_create(ch, method, properties, body): subprocess.call( ["sudo", "useradd", "-u", user_uid, "-g", user_gid, username] ) - print("[{}]: User {} has been added".format(task, username)) + print(f"[{task}]: User {username} has been added") success = True except Exception: e = sys.exc_info()[0] - print("[{}]: Error: {}".format(task, e)) + print(f"[{task}]: Error: {e}") ch.basic_ack(delivery_tag=method.delivery_tag) @@ -40,7 +40,7 @@ def ood_account_create(ch, method, properties, body): ) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "create.*", "cb": ood_account_create} ) diff --git a/dev_rmq_agents/slurm_agent.py b/dev_rmq_agents/slurm_agent.py index c40dac1..859aa61 100755 --- a/dev_rmq_agents/slurm_agent.py +++ b/dev_rmq_agents/slurm_agent.py @@ -13,7 +13,7 @@ rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"}) def slurm_account_create(ch, method, properties, body): msg = json.loads(body) - print("Message received {}".format(msg)) + print(f"Message received {msg}") username = msg["username"] success = False try: @@ -39,11 +39,11 @@ def slurm_account_create(ch, method, properties, body): "-i", ] ) - print("SLURM account for user {} has been added".format(username)) + print(f"SLURM account for user {username} has been added") success = True except Exception: e = sys.exc_info()[0] - print("[{}]: Error: {}".format(task, e)) + print(f"[{task}]: Error: {e}") ch.basic_ack(delivery_tag=method.delivery_tag) @@ -56,7 +56,7 @@ def slurm_account_create(ch, method, properties, body): ) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "create.*", "cb": slurm_account_create} ) diff --git a/flask_producer.py b/flask_producer.py index 8cea3af..b44f5cb 100755 --- a/flask_producer.py +++ b/flask_producer.py @@ -8,7 +8,7 @@ import pika import rabbit_config as rcfg if len(sys.argv) < 3: - sys.stderr.write("Usage: {} TAG USERNAME ".format(sys.argv[0])) + sys.stderr.write(f"Usage: {sys.argv[0]} TAG USERNAME ") exit(1) node = sys.argv[1] @@ -37,7 +37,7 @@ channel.exchange_declare(exchange=rcfg.Exchange, exchange_type="direct") channel.basic_publish( exchange=rcfg.Exchange, routing_key=node, body=json.dumps(message) ) -print(" [x] Sent {}: {}".format(node, json.dumps(message))) +print(f" [x] Sent {node}: {json.dumps(message)}") # creates a named queue result = channel.queue_declare(queue=user_name, exclusive=False, durable=True) @@ -50,7 +50,7 @@ channel.queue_bind( def work(ch, method, properties, body): msg = json.loads(body) - print("Received message from {}: \n\t{}".format(method.routing_key, msg)) + print(f"Received message from {method.routing_key}: \n\t{msg}") channel.queue_delete(method.routing_key) @@ -58,7 +58,7 @@ def work(ch, method, properties, body): channel.basic_consume( queue=sys.argv[2], on_message_callback=work, auto_ack=True ) -print("Subscribing to queue: {}".format(sys.argv[2])) +print(f"Subscribing to queue: {sys.argv[2]}") # initiate message ingestion try: diff --git a/prod_rmq_agents/get-next-uid-gid.py b/prod_rmq_agents/get-next-uid-gid.py index fdad2e3..a6a6d53 100644 --- a/prod_rmq_agents/get-next-uid-gid.py +++ b/prod_rmq_agents/get-next-uid-gid.py @@ -53,7 +53,7 @@ def resolve_uid_gid(ch, method, properties, body): # Retrieve message msg = json.loads(body) - logger.info("Received {}".format(msg)) + logger.info(f"Received {msg}") username = msg["username"] msg["success"] = False @@ -63,7 +63,7 @@ def resolve_uid_gid(ch, method, properties, body): user_exists = popen(user_exists_cmd).read().rstrip() if user_exists: - logger.info("The user, {} already exists".format(username)) + logger.info(f"The user, {username} already exists") msg["uid"] = user_exists.split(":")[2] msg["gid"] = user_exists.split(":")[3] @@ -106,7 +106,7 @@ def resolve_uid_gid(ch, method, properties, body): logger.info("confirmation sent") -logger.info("Start listening to queue: {}".format(task)) +logger.info(f"Start listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "request.*", "cb": resolve_uid_gid} ) diff --git a/prod_rmq_agents/subscribe_mail_lists.py b/prod_rmq_agents/subscribe_mail_lists.py index 4629b10..d6b8f82 100644 --- a/prod_rmq_agents/subscribe_mail_lists.py +++ b/prod_rmq_agents/subscribe_mail_lists.py @@ -23,7 +23,7 @@ def mail_list_subscription(ch, method, properties, body): # Retrieve message msg = json.loads(body) - logger.info("Received msg {}".format(msg)) + logger.info(f"Received msg {msg}") username = msg["username"] fullname = msg["fullname"] email = msg["email"] @@ -38,7 +38,7 @@ def mail_list_subscription(ch, method, properties, body): f"QUIET ADD hpc-users {email} {fullname}" ) - logger.info("Adding user{} to mail list".format(username)) + logger.info(f"Adding user {username} to mail list") msg["success"] = False try: # Create a text/plain message @@ -76,7 +76,7 @@ def mail_list_subscription(ch, method, properties, body): logger.info("confirmation sent") -logger.info("Start listening to queue: {}".format(task)) +logger.info(f"Start listening to queue: {task}") rc_rmq.start_consume( { "queue": task, # Define your Queue name diff --git a/prod_rmq_agents/user_reg_event_logger.py b/prod_rmq_agents/user_reg_event_logger.py index 606b24f..4580743 100644 --- a/prod_rmq_agents/user_reg_event_logger.py +++ b/prod_rmq_agents/user_reg_event_logger.py @@ -26,7 +26,7 @@ def log_user_reg_events(ch, method, properties, body): ch.basic_ack(delivery_tag=method.delivery_tag) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( { "queue": task, # Define your Queue name diff --git a/prod_rmq_agents/user_reg_logger.py b/prod_rmq_agents/user_reg_logger.py index 568bee1..d95be12 100755 --- a/prod_rmq_agents/user_reg_logger.py +++ b/prod_rmq_agents/user_reg_logger.py @@ -36,7 +36,7 @@ def log_registration(ch, method, properties, body): ch.basic_ack(delivery_tag=method.delivery_tag) -logger.info("Start listening to queue: {}".format(task)) +logger.info(f"Start listening to queue: {task}") # Start consuming messages from queue with callback function rc_rmq.start_consume( diff --git a/rc_rmq.py b/rc_rmq.py index 47896f1..188cd6f 100644 --- a/rc_rmq.py +++ b/rc_rmq.py @@ -35,22 +35,15 @@ class RCRMQ(object): if self.DEBUG: print( - """ + f""" Created RabbitMQ instance with: - Exchange name: {}, - Exchange type: {}, - Host: {}, - User: {}, - VHost: {}, - Port: {} - """.format( - self.EXCHANGE, - self.EXCHANGE_TYPE, - self.HOST, - self.USER, - self.VHOST, - self.PORT, - ) + Exchange name: {self.EXCHANGE}, + Exchange type: {self.EXCHANGE_TYPE}, + Host: {self.HOST}, + User: {self.USER}, + VHost: {self.VHOST}, + Port: {self.PORT} + """ ) self._consumer_tag = None -- GitLab