Page MenuHomePhabricator

script to test fetching attachments from bugzilla
ActivePublic

Authored by chasemp on Oct 22 2014, 9:25 PM.
#!/usr/bin/env python
#####################################################
# This script for retrieving attachments from bugzilla
# try bug # 72256 for a sampling of attachment types
user = ''
password = ''
save_path = './data'
######################################################
import time
import sys
import xmlrpclib
import os
import re
import os.path as p
def save_file(path, data):
with open(path, 'wb') as f:
f.write(data)
def create(bugid):
if not p.exists(save_path):
os.makedirs(save_path)
server = xmlrpclib.ServerProxy('https://bugzilla.wikimedia.org/xmlrpc.cgi', use_datetime=True)
token_data = server.User.login({'login': user,
'password': password})
token = token_data['token']
#http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#attachments
kwargs = { 'ids': [bugid], 'Bugzilla_token': token }
attached = server.Bug.attachments(kwargs)['bugs'][str(bugid)]
#print attached
for a in attached:
fqfp = p.join(save_path, a['file_name'])
print "Saving: %s" % (fqfp,)
save_file(fqfp, a['data'].data)
create(sys.argv[1])

Event Timeline

chasemp edited the content of this paste. (Show Details)Oct 22 2014, 9:25 PM
chasemp changed the title of this paste from untitled to script to test fetching attachments from bugzilla.
chasemp updated the paste's language from autodetect to python.