Skip to content

Commit

Permalink
jk0gh-42 plugins pep8 pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
pschwartz committed Aug 27, 2013
1 parent bf50987 commit 9cf7edd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 43 deletions.
12 changes: 7 additions & 5 deletions pyhole/plugins/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ def keyword_k(self, message, params=None, **kwargs):

try:
status = soup.find("span", {"id":
"static_bug_status"}).string.strip().capitalize()
"static_bug_status"}
).string.strip().capitalize()
assignee = utils.decode_entities(soup.findAll("span",
{"class": "vcard"})[0].contents[0].string)
{"class": "vcard"})[0]
.contents[0].string)

message.dispatch("Kernel.org %s [Status: %s, Assignee: %s] %s" %
(desc, status, assignee, url))
message.dispatch("Kernel.org %s [Status: %s, Assignee: %s] %s"
% (desc, status, assignee, url))
except TypeError:
return

@plugin.hook_add_msg_regex(
"https?:\/\/bugzilla\.kernel\.org\/show\_bug\.cgi\?id\=")
"https?:\/\/bugzilla\.kernel\.org\/show\_bug\.cgi\?id\=")
def _watch_for_k_bug_url(self, message, params=None, **kwargs):
"""Watch for kernel.org Bugzilla bug URLs"""
try:
Expand Down
18 changes: 10 additions & 8 deletions pyhole/plugins/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, irc):
self.irc = irc
self.name = self.__class__.__name__
self.launchpad = LP.login_anonymously("pyhole", "production",
utils.get_directory(self.name))
utils.get_directory(self.name))

@plugin.hook_add_command("lbugs")
@utils.spawn
Expand All @@ -47,11 +47,12 @@ def lbugs(self, message, params=None, **kwargs):
if i <= 4:
self._find_bugs(message, person, proj, False)
else:
message.dispatch("[...] truncated last %d users" % (
len(members.members) - i))
message.dispatch("[...] truncated last %d users" %
(len(members.members) - i))
break
except KeyError:
message.dispatch("Unable to find user '%s' in Launchpad" % team)
message.dispatch("Unable to find user '%s' in Launchpad" %
team)
else:
message.dispatch(self.lbugs.__doc__)

Expand All @@ -69,8 +70,9 @@ def keyword_lp(self, message, params=None, **kwargs):
task = bug.bug_tasks[len(bug.bug_tasks) - 1]

message.dispatch("LP %s [Status: %s, Assignee: %s] %s" % (
task.title, task.status,
self._find_name(task.assignee_link), bug.web_link))
task.title, task.status,
self._find_name(task.assignee_link),
bug.web_link))
except Exception:
return

Expand Down Expand Up @@ -111,10 +113,10 @@ def _find_bugs(self, message, person, project, single=True):
for i, bug in enumerate(bugs):
if i <= 4:
message.dispatch("LP %s [Assignee: %s] %s" % (bug.title,
person.display_name, bug.web_link))
person.display_name, bug.web_link))
else:
message.dispatch("[...] truncated last %d bugs" % (
len(bugs) - i))
len(bugs) - i))
break

if single and i < 1:
Expand Down
18 changes: 9 additions & 9 deletions pyhole/plugins/redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, irc):
self.redmine_domain = self.redmine.get("domain")
self.redmine_key = self.redmine.get("key")
self.redmine_url = "https://%s:password@%s" % (
self.redmine_key, self.redmine_domain)
self.redmine_key, self.redmine_domain)
except Exception:
self.disabled = True

Expand All @@ -54,7 +54,7 @@ def rbugs(self, message, params=None, **kwargs):
self._find_issue(message, issue["id"])
else:
message.dispatch("[...] truncated last %d bugs" % (
len(issues) - i))
len(issues) - i))
break
else:
if i <= 0:
Expand Down Expand Up @@ -86,7 +86,7 @@ def _watch_for_rm_bug_url(self, message, params=None, **kwargs):
def _find_issues(self, user_id):
"""Find all issues for a Redmine user"""
url = "%s/issues.json?assigned_to_id=%s" % (
self.redmine_url, user_id)
self.redmine_url, user_id)
response = self.irc.fetch_url(url, self.name)
if not response:
return
Expand All @@ -107,7 +107,7 @@ def _find_users(self, offset=None):
"""Find all Redmine users"""
if offset:
url = "%s/users.json?limit=100&offset=%d" % (
self.redmine_url, offset)
self.redmine_url, offset)
else:
url = "%s/users.json?limit=100" % self.redmine_url
response = self.irc.fetch_url(url, self.name)
Expand All @@ -129,8 +129,8 @@ def _find_issue(self, message, issue_id):
return

message.dispatch("RM %s #%s: %s [Status: %s, Assignee: %s] "
"https://%s/issues/show/%s" % (
issue["tracker"]["name"], issue["id"], issue["subject"],
issue["status"]["name"],
issue.get("assigned_to", {}).get("name", "N/A"),
self.redmine_domain, issue["id"]))
"https://%s/issues/show/%s" % (
issue["tracker"]["name"], issue["id"],
issue["subject"], issue["status"]["name"],
issue.get("assigned_to", {}).get("name", "N/A"),
self.redmine_domain, issue["id"]))
24 changes: 13 additions & 11 deletions pyhole/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def google(self, message, params=None, **kwargs):
if params:
query = urllib.urlencode({"q": params})
url = ("http://ajax.googleapis.com/ajax/"
"services/search/web?v=1.0&%s" % query)
"services/search/web?v=1.0&%s" % query)
response = self.irc.fetch_url(url, self.name)
if not response:
return
Expand All @@ -48,8 +48,9 @@ def google(self, message, params=None, **kwargs):
if results:
for r in results:
message.dispatch("%s: %s" % (
r["titleNoFormatting"].encode("ascii", "ignore"),
r["unescapedUrl"]))
r["titleNoFormatting"]
.encode("ascii", "ignore"),
r["unescapedUrl"]))
else:
message.dispatch("No results found: '%s'" % params)
else:
Expand Down Expand Up @@ -78,13 +79,13 @@ def imdb(self, message, params=None, **kwargs):
for result in results:
if len(result) > 3 and len(result.contents[2].attrs) > 0:
id = result.contents[2].attrs[0][1]
title = utils.decode_entities(
result.contents[2].contents[0])
title = utils.decode_entities(result.contents[2]
.contents[0])
year = result.contents[2].nextSibling.strip()[0:6]

if not title.startswith("aka") and len(year):
message.dispatch("%s %s: http://www.imdb.com%s" % (
title, year, id))
title, year, id))
i += 1
elif i >= 4:
break
Expand All @@ -110,8 +111,9 @@ def twitter(self, message, params=None, **kwargs):
if results:
for r in results:
message.dispatch("@%s: %s" % (r["from_user"],
utils.decode_entities(
r["text"].encode("ascii", "ignore"))))
utils.decode_entities(
r["text"]
.encode("ascii", "ignore"))))
else:
message.dispatch("No results found: '%s'" % params)
else:
Expand Down Expand Up @@ -154,8 +156,8 @@ def wikipedia(self, message, params=None, **kwargs):
"""Search Wikipedia (ex: .wikipedia <query>)"""
if params:
query = urllib.urlencode({"action": "query",
"generator": "allpages", "gaplimit": 4,
"gapfrom": params, "format": "xml"})
"generator": "allpages", "gaplimit": 4,
"gapfrom": params, "format": "xml"})
url = "http://en.wikipedia.org/w/api.php?%s" % query
response = self.irc.fetch_url(url, self.name)
if not response:
Expand All @@ -175,7 +177,7 @@ def youtube(self, message, params=None, **kwargs):
"""Search YouTube (ex: .youtube <query>)"""
if params:
query = urllib.urlencode({"q": params, "v": 2, "max-results": 4,
"alt": "jsonc"})
"alt": "jsonc"})
url = "http://gdata.youtube.com/feeds/api/videos?%s" % query
response = self.irc.fetch_url(url, self.name)
if not response:
Expand Down
7 changes: 4 additions & 3 deletions pyhole/plugins/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _watch_for_url(self, message, params=None, **kwargs):
host = self.url[7:]

lookup_sites = ("open.spotify.com", "/open.spotify.com",
"www.youtube.com", "/www.youtube.com")
"www.youtube.com", "/www.youtube.com")

if host.startswith(lookup_sites):
self._find_title(message, self.url)
Expand All @@ -65,10 +65,11 @@ def _find_title(self, message, url):
if soup.head:
title = utils.decode_entities(soup.head.title.string)
content_type = response.headers.get("Content-Type").split(";",
1)[0]
1)[0]
content_size = response.headers.get("Content-Length")
content_size = content_size + " bytes" if content_size else "N/A"

message.dispatch("%s (%s, %s)" % (title, content_type, content_size))
message.dispatch("%s (%s, %s)" % (title, content_type,
content_size))
else:
message.dispatch("No title found for %s" % url)
13 changes: 7 additions & 6 deletions pyhole/plugins/versionone.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2011 Johannes Erdfelt
# Copyright 2011 Johannes Erdfelt
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,9 +36,10 @@ def __init__(self, irc):
self.versionone_username = self.versionone.get("username")
self.versionone_password = self.versionone.get("password")
self.versionone_url = ("https://%s:%s@%s/%s/VersionOne/"
"rest-1.v1") % (
self.versionone_username, self.versionone_password,
self.versionone_domain, self.versionone_key)
"rest-1.v1") % (self.versionone_username,
self.versionone_password,
self.versionone_domain,
self.versionone_key)
except Exception:
self.disabled = True

Expand Down Expand Up @@ -141,7 +142,7 @@ def _find_asset(self, message, type, number):
msg += " [%s]" % ", ".join(attrs)

msg += " https://%s/%s/%s.mvc/Summary?oidToken=%s" % (
self.versionone_domain, self.versionone_key,
type, id)
self.versionone_domain, self.versionone_key,
type, id)

message.dispatch(msg)
6 changes: 5 additions & 1 deletion pyhole/plugins/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def weather(self, message, params=None, **kwargs):
humidity = "N/A%" if len(humidity) > 3 else humidity

result = ("%s%s: %s Humidity: %s Wind: %s %s") % (city,
zip_code, temp, humidity, wind, condition)
zip_code,
temp,
humidity,
wind,
condition)

message.dispatch(result)
else:
Expand Down

0 comments on commit 9cf7edd

Please sign in to comment.