Merlijn van Deen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/181054

Change subject: Flake8-ify everything
......................................................................

Flake8-ify everything

Also re-enable W191 (tab indentation) and E128 (continuaton
line under-indented) and fix violations of the latter.

Set max line length to 160 chars, which is more reasonable for modern editors.

Change-Id: I737912c0a3f862454fe71537f4df976d61438b72
---
M .pep8
M adminlog.py
M adminlogbot.py
A tox.ini
4 files changed, 86 insertions(+), 70 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/adminbot 
refs/changes/54/181054/1

diff --git a/.pep8 b/.pep8
index 45e02b5..376619a 100644
--- a/.pep8
+++ b/.pep8
@@ -1,3 +1,2 @@
 [pep8]
-# W191: indentation contains tabs
-ignore=W191,E128
+max-line-length=160
diff --git a/adminlog.py b/adminlog.py
index 3c2503d..0a0ac7c 100644
--- a/adminlog.py
+++ b/adminlog.py
@@ -22,7 +22,7 @@
 
     page = site.Pages[pagename]
     if page.redirect:
-        page = next(p.links())
+        page = next(page.links())
 
     text = page.edit()
     lines = text.split('\n')
@@ -43,21 +43,24 @@
         lines.insert(0, "")
         lines.insert(0, logline)
         lines.insert(0, "%s %s %d %s" % (header, months[now.month - 1],
-            now.day, header))
+                     now.day, header))
     else:
         lines.insert(position, logline)
     if config.wiki_category:
         if not re.search('\[\[Category:' + config.wiki_category + '\]\]', 
text):
             lines.append('<noinclude>[[Category:' +
-                    config.wiki_category + ']]</noinclude>')
-    saveresult = page.save('\n'.join(lines), "%s (%s)" % (message, author), 
bot=False)
+                         config.wiki_category +
+                         ']]</noinclude>')
+    page.save('\n'.join(lines), "%s (%s)" % (message, author), bot=False)
 
     micro_update = ("%s: %s" % (author, message))[:140]
 
     if config.enable_identica:
-        snapi = statusnet.StatusNet({'user': config.identica_username,
+        snapi = statusnet.StatusNet({
+            'user': config.identica_username,
             'passwd': config.identica_password,
-            'api': 'https://identi.ca/api'})
+            'api': 'https://identi.ca/api'
+        })
         snapi.update(micro_update)
 
     if config.enable_twitter:
diff --git a/adminlogbot.py b/adminlogbot.py
index e144095..c1ca065 100755
--- a/adminlogbot.py
+++ b/adminlogbot.py
@@ -13,8 +13,6 @@
 import time
 import urllib
 
-import traceback
-
 
 LOG_FORMAT = "%(asctime)-15s %(levelname)s: %(message)s"
 
@@ -25,8 +23,10 @@
         self.name = name
         sasl_password = config.nick + ':' + config.nick_password
         server = [config.network, config.port, sasl_password]
-        ircbot.SingleServerIRCBot.__init__(self, [server], config.nick,
-                config.nick)
+        ircbot.SingleServerIRCBot.__init__(
+            self, [server],
+            config.nick, config.nick
+        )
 
     def connect(self, *args, **kwargs):
         kwargs.update(ssl=True)
@@ -112,32 +112,35 @@
                                           ldap.SCOPE_SUBTREE,
                                           "(objectclass=groupofnames)")
                 if not projectdata:
-                    self.connection.privmsg(event.target(),
-                                        "Can't contact LDAP"
-                                        " for project list.")
+                    self.connection.privmsg(
+                        event.target(),
+                        "Can't contact LDAP for project list."
+                    )
                 for obj in projectdata:
                     projects.append(obj[1]["cn"][0])
 
-
                 if self.config.service_group_rdn:
-                    sgdata = ds.search_s(self.config.service_group_rdn +
-                                              "," + base,
-                                              ldap.SCOPE_SUBTREE,
-                                              "(objectclass=groupofnames)")
+                    sgdata = ds.search_s(
+                        self.config.service_group_rdn + "," + base,
+                        ldap.SCOPE_SUBTREE,
+                        "(objectclass=groupofnames)"
+                    )
                     if not sgdata:
-                        self.connection.privmsg(event.target(),
-                                            "Can't contact LDAP"
-                                            " for service group list.")
+                        self.connection.privmsg(
+                            event.target(),
+                            "Can't contact LDAP for service group list."
+                        )
                     for obj in sgdata:
                         projects.append(obj[1]["cn"][0])
 
                 project_cache_file.write(','.join(projects))
             except Exception:
                 try:
-                    self.connection.privmsg(event.target(),
-                                        "Error reading project"
-                                        " list from LDAP.")
-                except irclib.ServerNotConnectedError, e:
+                    self.connection.privmsg(
+                        event.target(),
+                        "Error reading project list from LDAP."
+                    )
+                except irclib.ServerNotConnectedError:
                     logging.debug("Server connection error"
                                   " when sending message")
         return projects
@@ -157,19 +160,25 @@
             logging.debug("'%s' got '%s'; displaying help message." %
                           (self.name, line))
             try:
-                self.connection.privmsg(event.target(),
-                                    "I am a logbot running on %s." %
-                                    gethostname())
-                self.connection.privmsg(event.target(),
-                                    "Messages are logged to %s." %
-                                    self.config.log_url)
-                self.connection.privmsg(event.target(),
-                                    "To log a message, type !log <msg>.")
+                self.connection.privmsg(
+                    event.target(),
+                    "I am a logbot running on %s." % gethostname()
+                )
+                self.connection.privmsg(
+                    event.target(),
+                    "Messages are logged to %s." % self.config.log_url
+                )
+                self.connection.privmsg(
+                    event.target(),
+                    "To log a message, type !log <msg>."
+                )
             except Exception:
                 try:
-                    self.connection.privmsg(event.target(),
-                                        "To log a message, type !log <msg>.")
-                except irclib.ServerNotConnectedError, e:
+                    self.connection.privmsg(
+                        event.target(),
+                        "To log a message, type !log <msg>."
+                    )
+                except irclib.ServerNotConnectedError:
                     logging.debug("Server connection error "
                                   "when sending message")
         elif line.lower().startswith("!log "):
@@ -205,39 +214,37 @@
                 else:
                     try:
                         if self.config.required_users_mode == "warn":
-                            self.connection.privmsg(event.target(),
-                                                "Not a trusted nick or cloak."
-                                                " This is just a warning,"
-                                                " for now."
-                                                " Please add your nick"
-                                                " or cloak added"
-                                                " to the trust list"
-                                                " or your user page.")
+                            self.connection.privmsg(
+                                event.target(),
+                                "Not a trusted nick or cloak. This is just a 
warning, for now. "
+                                "Please add your nick or cloak added to the 
trust list or your user page."
+                            )
                         if self.config.required_users_mode == "error":
-                            self.connection.privmsg(event.target(),
-                                                "Not a trusted nick"
-                                                " or cloak. Not logging."
-                                                " Please add your nick"
-                                                " or cloak added"
-                                                " to the trust list"
-                                                " or your user page.")
+                            self.connection.privmsg(
+                                event.target(),
+                                "Not a trusted nick or cloak. Not logging. "
+                                "Please add your nick or cloak added to the 
trust list or your user page."
+                            )
                             return
-                    except irclib.ServerNotConnectedError, e:
+                    except irclib.ServerNotConnectedError:
                         logging.debug("Server connection error"
                                       " when sending message")
             if self.config.enable_projects:
                 arr = line.split(" ", 2)
                 try:
                     if len(arr) < 2:
-                        self.connection.privmsg(event.target(),
-                                            "Project not found, O.o. Try !log"
-                                            " <project> <message> next time.")
+                        self.connection.privmsg(
+                            event.target(),
+                            "Project not found, O.o. Try !log <project> 
<message> next time."
+                        )
                         return
                     if len(arr) < 3:
-                        self.connection.privmsg(event.target(),
-                                            "Message missing. Nothing logged.")
+                        self.connection.privmsg(
+                            event.target(),
+                            "Message missing. Nothing logged."
+                        )
                         return
-                except irclib.ServerNotConnectedError, e:
+                except irclib.ServerNotConnectedError:
                     logging.debug("Server connection error"
                                   " when sending message")
                 project = arr[1]
@@ -245,10 +252,11 @@
 
                 if project not in projects:
                     try:
-                        self.connection.privmsg(event.target(),
-                                            project +
-                                            " is not a valid project.")
-                    except irclib.ServerNotConnectedError, e:
+                        self.connection.privmsg(
+                            event.target(),
+                            "{} is not a valid project.".format(project)
+                        )
+                    except irclib.ServerNotConnectedError:
                         logging.debug("Server connection error"
                                       " when sending message")
                     return
@@ -257,9 +265,11 @@
                 arr = line.split(" ", 1)
                 if len(arr) < 2:
                     try:
-                        self.connection.privmsg(event.target(),
-                                            "Message missing. Nothing logged.")
-                    except irclib.ServerNotConnectedError, e:
+                        self.connection.privmsg(
+                            event.target(),
+                            "Message missing. Nothing logged."
+                        )
+                    except irclib.ServerNotConnectedError:
                         logging.debug("Server connection error"
                                       " when sending message")
                     return
@@ -272,11 +282,13 @@
                 else:
                     title = "Master"
                 try:
-                    self.connection.privmsg(event.target(),
+                    self.connection.privmsg(
+                        event.target(),
                         "Logged the message at {url}, {author}".format(
                             url=pageurl, author=title
-                    ))
-                except irclib.ServerNotConnectedError, e:
+                        )
+                    )
+                except irclib.ServerNotConnectedError:
                     logging.debug("Server connection error"
                                   " when sending message")
             except Exception:
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..331cb8d
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,2 @@
+[flake8]
+max-line-length=160

-- 
To view, visit https://gerrit.wikimedia.org/r/181054
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I737912c0a3f862454fe71537f4df976d61438b72
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/adminbot
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to