summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-11-09 23:30:55 +0100
committerMichael Stahl <mstahl@redhat.com>2013-11-10 00:03:23 +0100
commit4855946a5e40747a4ccecf17ba80c8bdbdd8c969 (patch)
tree594eab0d6cf44871c4354e63d5043a6febde5182 /bin
parent1b82dba6f7c11eeb48dae690052ec56ef37f41e4 (diff)
get-bugzilla-attachments-by-mimetype: make this run on Python 3
Change-Id: I27cf30c62122ea191c852a1a298a40ef64d35ba9
Diffstat (limited to 'bin')
-rwxr-xr-xbin/get-bugzilla-attachments-by-mimetype28
1 files changed, 22 insertions, 6 deletions
diff --git a/bin/get-bugzilla-attachments-by-mimetype b/bin/get-bugzilla-attachments-by-mimetype
index 100e78eb1994..994e0839811c 100755
--- a/bin/get-bugzilla-attachments-by-mimetype
+++ b/bin/get-bugzilla-attachments-by-mimetype
@@ -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,12 +116,16 @@ 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()
query['column_list']='bug_id'
@@ -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