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 @@
#
#where X is the n'th attachment of that type in the bug
import urllib
import feedparser
import base64
import re
import os, os.path
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.sax.saxutils import escape
......@@ -32,7 +38,7 @@ def urlopen_retry(url):
maxretries = 3
for i in range(maxretries + 1):
try:
return urllib.urlopen(url)
return urlopen(url)
except IOError as e:
print("caught IOError: " + e)
if maxretries == i:
......@@ -67,7 +73,7 @@ def get_from_bug_url_via_xml(url, mimetype, prefix, suffix):
download = suffix + '/' +prefix + id + '-' + str(attachmentid) + '.' + suffix
print('downloading as ' + download)
f = open(download, 'w')
f = open(download, 'wb')
f.write(base64.b64decode(node.firstChild.nodeValue))
f.close()
break
......@@ -98,7 +104,11 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix):
continue
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)
if remoteMime != mimetype:
print("skipping")
......@@ -106,11 +116,15 @@ def get_novell_bug_via_xml(url, mimetype, prefix, suffix):
download = suffix + '/' + prefix + id + '-' + str(attachmentid) + '.' + suffix
print('downloading as ' + download)
f = open(download, 'w')
f = open(download, 'wb')
f.write(handle.read())
f.close()
def get_through_rpc_query(rpcurl, showurl, mimetype, prefix, suffix):
try:
os.mkdir(suffix)
except:
pass
try:
proxy = xmlrpclib.ServerProxy(rpcurl)
query = dict()
......@@ -144,6 +158,8 @@ def get_through_rss_query_url(url, mimetype, prefix, suffix):
for entry in d['entries']:
try:
get_bug_function(entry['id'], mimetype, prefix, suffix)
except KeyboardInterrupt:
raise # Ctrl+C should work
except:
print(entry['id'] + " failed: " + sys.exc_info()[0])
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