#!/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])