From a23f7ddc6bb8c6cc7286f6af96ca4e0db8a0bb46 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 30 Sep 2012 23:06:18 -0400 Subject: [PATCH] Check that we can retrieve the web view before tinyifying... ...if not, we don't go to the tinyifier and we make the URL field empty. --- irkerhook.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/irkerhook.py b/irkerhook.py index ce568be..77ca7bd 100755 --- a/irkerhook.py +++ b/irkerhook.py @@ -97,16 +97,16 @@ class GenericExtractor: sys.stderr.write('"%s", line %d: too many fields in config line\n' \ % (conf, ln)) continue - fld = fields[0].strip() - val = fields[1].strip() - if val.lower() == "true": - val = True - if val.lower() == "false": - val = False + variable = fields[0].strip() + value = fields[1].strip() + if value.lower() == "true": + value = True + elif value.lower() == "false": + value = False # User cannot set maxchannels - only a command-line arg can do that. - if fld == "maxchannels": + if variable == "maxchannels": return - setattr(self, fld, val) + setattr(self, variable, value) def do_overrides(self): "Make command-line overrides possible." booleans = ["tcp", "color"] @@ -126,7 +126,7 @@ class GenericExtractor: setattr(self, key, val) if not self.project: sys.stderr.write("irkerhook.py: no project name set!\n") - raise SystemExit,1 + raise SystemExit, 1 if not self.repo: self.repo = self.project.lower() if not self.channels: @@ -136,11 +136,19 @@ class GenericExtractor: else: self.urlprefix = urlprefixmap.get(self.urlprefix, self.urlprefix) prefix = self.urlprefix % self.__dict__ - # Try to tinyfy a reference to a web view for this commit. try: - self.url = open(urllib.urlretrieve(self.tinyifier + prefix + self.commit)[0]).read() - except: - self.url = prefix + self.commit + webview = prefix + self.commit + txt = open(urllib.urlretrieve(webview)[0]).read() + if "404" in txt or "not found" in txt: + raise IOError + try: + # Didn't get a retrieval error or 404 on the web + # view, so try to tinyify a reference to it. + self.url = open(urllib.urlretrieve(self.tinyifier + webview)[0]).read() + except IOError: + self.url = webview + except IOError: + self.url = "" if self.color: self.activate_color() -- 2.26.2