Kaydet (Commit) fdb747ff authored tarafından Michael Stahl's avatar Michael Stahl

get-bugzilla-attachments-by-mimetype: more Python 3 in exception handler

... and also fix the print functions that shouldn't output a newline.

Change-Id: Ifd866cb33b3ef9a2e83625ed03d5cb836c1ba56b
üst 5181dc02
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# #
#where X is the n'th attachment of that type in the bug #where X is the n'th attachment of that type in the bug
from __future__ import print_function
import feedparser import feedparser
import base64 import base64
import re import re
...@@ -40,7 +41,7 @@ def urlopen_retry(url): ...@@ -40,7 +41,7 @@ def urlopen_retry(url):
try: try:
return urlopen(url) return urlopen(url)
except IOError as e: except IOError as e:
print("caught IOError: " + e) print("caught IOError: " + str(e))
if maxretries == i: if maxretries == i:
raise raise
print("retrying...") print("retrying...")
...@@ -51,17 +52,17 @@ def get_from_bug_url_via_xml(url, mimetype, prefix, suffix): ...@@ -51,17 +52,17 @@ def get_from_bug_url_via_xml(url, mimetype, prefix, suffix):
if os.path.isfile(suffix + '/' + prefix + id + '-1.' + suffix): if os.path.isfile(suffix + '/' + prefix + id + '-1.' + suffix):
print("assuming " + id + " is up to date") print("assuming " + id + " is up to date")
else: else:
print("parsing", id) print("parsing " + id)
sock = urlopen_retry(url+"&ctype=xml") sock = urlopen_retry(url+"&ctype=xml")
dom = minidom.parse(sock) dom = minidom.parse(sock)
sock.close() sock.close()
attachmentid=0 attachmentid=0
for attachment in dom.getElementsByTagName('attachment'): for attachment in dom.getElementsByTagName('attachment'):
attachmentid += 1 attachmentid += 1
print(" mimetype is") print(" mimetype is", end=' ')
for node in attachment.childNodes: for node in attachment.childNodes:
if node.nodeName == 'type': if node.nodeName == 'type':
print(node.firstChild.nodeValue) print(node.firstChild.nodeValue, end=' ')
if node.firstChild.nodeValue.lower() != mimetype.lower(): if node.firstChild.nodeValue.lower() != mimetype.lower():
print('skipping') print('skipping')
break break
...@@ -102,14 +103,14 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix): ...@@ -102,14 +103,14 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix):
if not handle: if not handle:
print("attachment %s is not accessible" % realAttachmentId) print("attachment %s is not accessible" % realAttachmentId)
continue continue
print(" mimetype is") print(" mimetype is", end=' ')
info = handle.info() info = handle.info()
if info.get_content_type: if info.get_content_type:
remoteMime = info.get_content_type() remoteMime = info.get_content_type()
else: else:
remoteMime = info.gettype() remoteMime = info.gettype()
print(remoteMime) print(remoteMime, end=' ')
if remoteMime != mimetype: if remoteMime != mimetype:
print("skipping") print("skipping")
continue continue
...@@ -161,7 +162,7 @@ def get_through_rss_query_url(url, mimetype, prefix, suffix): ...@@ -161,7 +162,7 @@ def get_through_rss_query_url(url, mimetype, prefix, suffix):
except KeyboardInterrupt: except KeyboardInterrupt:
raise # Ctrl+C should work raise # Ctrl+C should work
except: except:
print(entry['id'] + " failed: " + sys.exc_info()[0]) print(entry['id'] + " failed: " + str(sys.exc_info()[0]))
pass pass
def get_through_rss_query(queryurl, mimetype, prefix, suffix): def get_through_rss_query(queryurl, mimetype, prefix, suffix):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment