From 059ee91c81924c820df878f1e2944b396528fafa Mon Sep 17 00:00:00 2001
From: Bo-Chun Louis Chen <louistw@uab.edu>
Date: Fri, 14 May 2021 11:09:29 -0500
Subject: [PATCH] Fix E501 line length 79

---
 create_account.py                        |  4 +---
 dev_rmq_agents/ohpc_account_create.py    |  4 +---
 dev_rmq_agents/ood_account_create.py     |  4 +---
 flask_producer.py                        |  9 ++-------
 prod_rmq_agents/dir_verify.py            | 13 +++++--------
 prod_rmq_agents/get-next-uid-gid.py      | 24 ++++++++++++++++--------
 prod_rmq_agents/git_commit.py            | 22 ++++++++++++----------
 prod_rmq_agents/notify_user.py           |  3 ++-
 prod_rmq_agents/subscribe_mail_lists.py  |  8 +++++---
 prod_rmq_agents/user_reg_event_logger.py |  4 +---
 rc_rmq.py                                |  9 ++-------
 11 files changed, 48 insertions(+), 56 deletions(-)

diff --git a/create_account.py b/create_account.py
index b9b9067..d814780 100755
--- a/create_account.py
+++ b/create_account.py
@@ -13,9 +13,7 @@ parser.add_argument(
 parser.add_argument(
     "reason", nargs="?", default="", help="Reason of requesting"
 )
-parser.add_argument(
-    "--domain", default="localhost", help="domain of email"
-)
+parser.add_argument("--domain", default="localhost", help="domain of email")
 parser.add_argument(
     "-v", "--verbose", action="store_true", help="verbose output"
 )
diff --git a/dev_rmq_agents/ohpc_account_create.py b/dev_rmq_agents/ohpc_account_create.py
index 206c404..44c8f90 100644
--- a/dev_rmq_agents/ohpc_account_create.py
+++ b/dev_rmq_agents/ohpc_account_create.py
@@ -38,9 +38,7 @@ def ohpc_account_create(ch, method, properties, body):
 
     if success:
         # send create message to other agent
-        rc_rmq.publish_msg(
-            {"routing_key": "create." + username, "msg": msg}
-        )
+        rc_rmq.publish_msg({"routing_key": "create." + username, "msg": msg})
 
 
 print("Start Listening to queue: {}".format(task))
diff --git a/dev_rmq_agents/ood_account_create.py b/dev_rmq_agents/ood_account_create.py
index 339819e..e87124f 100644
--- a/dev_rmq_agents/ood_account_create.py
+++ b/dev_rmq_agents/ood_account_create.py
@@ -18,9 +18,7 @@ def ood_account_create(ch, method, properties, body):
     user_gid = str(msg["gid"])
     success = False
     try:
-        subprocess.call(
-            ["sudo", "groupadd", "-r", "-g", user_gid, username]
-        )
+        subprocess.call(["sudo", "groupadd", "-r", "-g", user_gid, username])
         subprocess.call(
             ["sudo", "useradd", "-u", user_uid, "-g", user_gid, username]
         )
diff --git a/flask_producer.py b/flask_producer.py
index 1ef993a..908b57f 100755
--- a/flask_producer.py
+++ b/flask_producer.py
@@ -38,9 +38,7 @@ channel.basic_publish(
 print(" [x] Sent {}: {}".format(node, json.dumps(message)))
 
 # creates a named queue
-result = channel.queue_declare(
-    queue=user_name, exclusive=False, durable=True
-)
+result = channel.queue_declare(queue=user_name, exclusive=False, durable=True)
 
 # bind the queue with exchange
 channel.queue_bind(
@@ -50,10 +48,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)
-    )
-    # queue_unbind(queue, exchange=None, routing_key=None, arguments=None, callback=None)
+    print("Received message from {}: \n\t{}".format(method.routing_key, msg))
     channel.queue_delete(method.routing_key)
 
 
diff --git a/prod_rmq_agents/dir_verify.py b/prod_rmq_agents/dir_verify.py
index 89f98a4..162dad9 100644
--- a/prod_rmq_agents/dir_verify.py
+++ b/prod_rmq_agents/dir_verify.py
@@ -44,15 +44,12 @@ def dir_verify(ch, method, properties, body):
                     mask = oct(status.st_mode)[-3:]
                     uid = str(status.st_uid)
                     gid = str(status.st_gid)
-                    if (
-                        mask != "700"
-                        or uid != msg["uid"]
-                        or gid != msg["gid"]
-                    ):
+                    if mask != "700" or uid != msg["uid"] or gid != msg["gid"]:
                         msg["success"] = False
-                        msg[
-                            "errmsg"
-                        ] = f"Error: dir {path} permissions or ownership are wrong"
+                        msg["errmsg"] = (
+                            f"Error: dir {path} permissions or ownership are"
+                            " wrong"
+                        )
 
     except Exception as exception:
         msg["success"] = False
diff --git a/prod_rmq_agents/get-next-uid-gid.py b/prod_rmq_agents/get-next-uid-gid.py
index 56b9b81..714ab8c 100644
--- a/prod_rmq_agents/get-next-uid-gid.py
+++ b/prod_rmq_agents/get-next-uid-gid.py
@@ -32,7 +32,8 @@ def create_account(msg):
 
     # Bright command to create user
     cmd = "/cm/local/apps/cmd/bin/cmsh -c "
-    cmd += f'"user; add {username}; set id {uid}; set email {email}; set commonname \\"{fullname}\\"; '
+    cmd += f'"user; add {username}; set id {uid}; set email {email};'
+    cmd += f'set commonname \\"{fullname}\\"; '
     cmd += 'commit;"'
 
     if not args.dry_run:
@@ -61,13 +62,19 @@ def resolve_uid_gid(ch, method, properties, body):
             msg["gid"] = user_exists.split(":")[3]
 
         else:
-            cmd_uid = "/usr/bin/getent passwd | \
-                awk -F: 'BEGIN { maxuid=10000 } ($3>10000) && ($3<20000) && ($3>maxuid) { maxuid=$3; } END { print maxuid+1; }'"
+            cmd_uid = (
+                "/usr/bin/getent passwd | awk -F: 'BEGIN { maxuid=10000 }"
+                " ($3>10000) && ($3<20000) && ($3>maxuid) { maxuid=$3; } END {"
+                " print maxuid+1; }'"
+            )
             msg["uid"] = popen(cmd_uid).read().rstrip()
             logger.info(f"UID query: {cmd_uid}")
 
-            cmd_gid = "/usr/bin/getent group | \
-                awk -F: 'BEGIN { maxgid=10000 } ($3>10000) && ($3<20000) && ($3>maxgid) { maxgid=$3; } END { print maxgid+1; }'"
+            cmd_gid = (
+                "/usr/bin/getent group | awk -F: 'BEGIN { maxgid=10000 }"
+                " ($3>10000) && ($3<20000) && ($3>maxgid) { maxgid=$3; } END {"
+                " print maxgid+1; }'"
+            )
             msg["gid"] = popen(cmd_gid).read().rstrip()
             logger.info(f"GID query: {cmd_gid}")
 
@@ -76,9 +83,10 @@ def resolve_uid_gid(ch, method, properties, body):
         msg["success"] = True
     except Exception as exception:
         msg["success"] = False
-        msg[
-            "errmsg"
-        ] = f"Exception raised during account creation, check logs for stack trace"
+        msg["errmsg"] = (
+            "Exception raised during account creation, check logs for stack"
+            " trace"
+        )
         logger.error("", exc_info=True)
 
     # Acknowledge message
diff --git a/prod_rmq_agents/git_commit.py b/prod_rmq_agents/git_commit.py
index a88f55c..38d6f8e 100644
--- a/prod_rmq_agents/git_commit.py
+++ b/prod_rmq_agents/git_commit.py
@@ -37,8 +37,12 @@ def git_commit(ch, method, properties, body):
     username = msg["username"]
     msg["task"] = task
     msg["success"] = False
-    branch_name = "issue-add-users-" + \
-        username.lower() + "-" + time.strftime("%Y%m%d_%H%M%S")
+    branch_name = (
+        "issue-add-users-"
+        + username.lower()
+        + "-"
+        + time.strftime("%Y%m%d_%H%M%S")
+    )
     user_ldif = users_dir + f"/{username}.ldif"
     group_ldif = groups_dir + f"/{username}.ldif"
 
@@ -55,14 +59,13 @@ def git_commit(ch, method, properties, body):
         if not branch_exists:
             logger.debug("git checkout -b %s", branch_name)
             git.checkout("-b", branch_name)
-            logger.debug(
-                "open(%s, 'w'), open(%s, 'w')", user_ldif, group_ldif
-            )
+            logger.debug("open(%s, 'w'), open(%s, 'w')", user_ldif, group_ldif)
             with open(user_ldif, "w") as ldif_u, open(
                 group_ldif, "w"
             ) as ldif_g:
                 logger.debug(
-                    f"ldapsearch -LLL -x -H ldaps://ldapserver -b 'dc=cm,dc=cluster' uid={username} > {user_ldif}"
+                    "ldapsearch -LLL -x -H ldaps://ldapserver -b 'dc=cm,dc=clu"
+                    f"ster' uid={username} > {user_ldif}"
                 )
                 ldapsearch(
                     "-LLL",
@@ -75,7 +78,8 @@ def git_commit(ch, method, properties, body):
                     _out=ldif_u,
                 )
                 logger.debug(
-                    f"ldapsearch -LLL -x -H ldapserver -b 'ou=Group,dc=cm,dc=cluster' cn={username} > {group_ldif}"
+                    "ldapsearch -LLL -x -H ldapserver -b 'ou=Group,dc=cm,dc=cl"
+                    f"uster' cn={username} > {group_ldif}"
                 )
                 ldapsearch(
                     "-LLL",
@@ -93,9 +97,7 @@ def git_commit(ch, method, properties, body):
             git.add(user_ldif)
             logger.debug("git add %s", group_ldif)
             git.add(group_ldif)
-            logger.debug(
-                "git commit -m 'Added new cheaha user: %s'", username
-            )
+            logger.debug("git commit -m 'Added new cheaha user: %s'", username)
             git.commit(m="Added new cheaha user: " + username)
             logger.debug("git checkout master")
             git.checkout("master")
diff --git a/prod_rmq_agents/notify_user.py b/prod_rmq_agents/notify_user.py
index 4f1dd3e..5e26547 100644
--- a/prod_rmq_agents/notify_user.py
+++ b/prod_rmq_agents/notify_user.py
@@ -63,7 +63,8 @@ def notify_user(ch, method, properties, body):
                     f"smtp.sendmail({rcfg.Sender}, {receivers}, message)"
                 )
                 logger.info(
-                    f"table.update({{'username': {username}, 'count': 1, 'sent_at': datetime.now()}}, ['username'])"
+                    f"table.update({{'username': {username}, 'count': 1,"
+                    " 'sent_at': datetime.now()}}, ['username'])"
                 )
 
             else:
diff --git a/prod_rmq_agents/subscribe_mail_lists.py b/prod_rmq_agents/subscribe_mail_lists.py
index f0294f7..8003ea7 100644
--- a/prod_rmq_agents/subscribe_mail_lists.py
+++ b/prod_rmq_agents/subscribe_mail_lists.py
@@ -32,8 +32,10 @@ def mail_list_subscription(ch, method, properties, body):
     mail_list_bcc = rcfg.Mail_list_bcc
     server = rcfg.Mail_server
 
-    listserv_cmd = f"QUIET ADD hpc-announce {email} {fullname} \
-                   \nQUIET ADD hpc-users {email} {fullname}"
+    listserv_cmd = (
+        f"QUIET ADD hpc-announce {email} {fullname}\n"
+        f"QUIET ADD hpc-users {email} {fullname}"
+    )
 
     logger.info("Adding user{} to mail list".format(username))
     msg["success"] = False
@@ -78,7 +80,7 @@ rc_rmq.start_consume(
     {
         "queue": task,  # Define your Queue name
         "routing_key": "verify.*",  # Define your routing key
-        "cb": mail_list_subscription,  # Pass in callback function you just define
+        "cb": mail_list_subscription,  # Pass callback function you just define
     }
 )
 
diff --git a/prod_rmq_agents/user_reg_event_logger.py b/prod_rmq_agents/user_reg_event_logger.py
index 1f14ca4..3223255 100644
--- a/prod_rmq_agents/user_reg_event_logger.py
+++ b/prod_rmq_agents/user_reg_event_logger.py
@@ -17,9 +17,7 @@ def log_user_reg_events(ch, method, properties, body):
     routing_key = method.routing_key
     action = routing_key.split(".")[0]
     user = routing_key.split(".")[1]
-    print(
-        f"Got a {action} message for {user} with routing key: {routing_key}"
-    )
+    print(f"Got a {action} message for {user} with routing key: {routing_key}")
     print(msg)
 
     # Acknowledge message
diff --git a/rc_rmq.py b/rc_rmq.py
index daa61c2..c6fdf70 100644
--- a/rc_rmq.py
+++ b/rc_rmq.py
@@ -123,10 +123,7 @@ class RCRMQ(object):
 
         if self.DEBUG:
             print(
-                "Queue: "
-                + self.QUEUE
-                + "\nRouting_key: "
-                + self.ROUTING_KEY
+                "Queue: " + self.QUEUE + "\nRouting_key: " + self.ROUTING_KEY
             )
 
         if self._connection is None:
@@ -134,9 +131,7 @@ class RCRMQ(object):
 
         self.bind_queue()
 
-        self._consumer_tag = self._channel.basic_consume(
-            self.QUEUE, obj["cb"]
-        )
+        self._consumer_tag = self._channel.basic_consume(self.QUEUE, obj["cb"])
         self._consuming = True
         try:
             self._channel.start_consuming()
-- 
GitLab