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

get-bugzilla-attachments-by-mimetype: make this run on Python 3

Change-Id: I27cf30c62122ea191c852a1a298a40ef64d35ba9
üst 1b82dba6
...@@ -18,13 +18,19 @@ ...@@ -18,13 +18,19 @@
# #
#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
import urllib
import feedparser import feedparser
import base64 import base64
import re import re
import os, os.path import os, os.path
import sys import sys
import xmlrpclib try:
from urllib.request import urlopen
except:
from urllib import urlopen
try:
import xmlrpc.client as xmlrpclib
except:
import xmlrpclib
from xml.dom import minidom from xml.dom import minidom
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
...@@ -32,7 +38,7 @@ def urlopen_retry(url): ...@@ -32,7 +38,7 @@ def urlopen_retry(url):
maxretries = 3 maxretries = 3
for i in range(maxretries + 1): for i in range(maxretries + 1):
try: try:
return urllib.urlopen(url) return urlopen(url)
except IOError as e: except IOError as e:
print("caught IOError: " + e) print("caught IOError: " + e)
if maxretries == i: if maxretries == i:
...@@ -67,7 +73,7 @@ def get_from_bug_url_via_xml(url, mimetype, prefix, suffix): ...@@ -67,7 +73,7 @@ def get_from_bug_url_via_xml(url, mimetype, prefix, suffix):
download = suffix + '/' +prefix + id + '-' + str(attachmentid) + '.' + suffix download = suffix + '/' +prefix + id + '-' + str(attachmentid) + '.' + suffix
print('downloading as ' + download) print('downloading as ' + download)
f = open(download, 'w') f = open(download, 'wb')
f.write(base64.b64decode(node.firstChild.nodeValue)) f.write(base64.b64decode(node.firstChild.nodeValue))
f.close() f.close()
break break
...@@ -98,7 +104,11 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix): ...@@ -98,7 +104,11 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix):
continue continue
print(" mimetype is") print(" mimetype is")
remoteMime = handle.info().gettype() info = handle.info()
if info.get_content_type:
remoteMime = info.get_content_type()
else:
remoteMime = info.gettype()
print(remoteMime) print(remoteMime)
if remoteMime != mimetype: if remoteMime != mimetype:
print("skipping") print("skipping")
...@@ -106,11 +116,15 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix): ...@@ -106,11 +116,15 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix):
download = suffix + '/' + prefix + id + '-' + str(attachmentid) + '.' + suffix download = suffix + '/' + prefix + id + '-' + str(attachmentid) + '.' + suffix
print('downloading as ' + download) print('downloading as ' + download)
f = open(download, 'w') f = open(download, 'wb')
f.write(handle.read()) f.write(handle.read())
f.close() f.close()
def get_through_rpc_query(rpcurl, showurl, mimetype, prefix, suffix): def get_through_rpc_query(rpcurl, showurl, mimetype, prefix, suffix):
try:
os.mkdir(suffix)
except:
pass
try: try:
proxy = xmlrpclib.ServerProxy(rpcurl) proxy = xmlrpclib.ServerProxy(rpcurl)
query = dict() query = dict()
...@@ -144,6 +158,8 @@ def get_through_rss_query_url(url, mimetype, prefix, suffix): ...@@ -144,6 +158,8 @@ def get_through_rss_query_url(url, mimetype, prefix, suffix):
for entry in d['entries']: for entry in d['entries']:
try: try:
get_bug_function(entry['id'], mimetype, prefix, suffix) get_bug_function(entry['id'], mimetype, prefix, suffix)
except KeyboardInterrupt:
raise # Ctrl+C should work
except: except:
print(entry['id'] + " failed: " + sys.exc_info()[0]) print(entry['id'] + " failed: " + sys.exc_info()[0])
pass pass
......
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