Server IP : 127.0.0.2 / Your IP : 52.15.242.179 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/bin/ |
Upload File : |
#! /usr/bin/python # # Copyright (C) 2007, Canonical Ltd. # Written by Daniel Holbach, # Stefano Rivera, # Brian Murray # # ################################################################## # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # See file /usr/share/common-licenses/GPL-3 for more details. # # ################################################################## from optparse import OptionParser import codecs import errno import os from lptools import config USAGE = "lp-grab-attachments <bug numbers>" def download_attachments(bug, descriptions): bug_folder_name = 'bug-%s' % bug.id try: os.mkdir(bug_folder_name) except OSError, error: if error.errno == errno.EEXIST: return if descriptions: description = bug.description filename = os.path.join(os.getcwd(), bug_folder_name, 'Description.txt') local_file = codecs.open(filename, encoding="utf-8", mode="w") local_file.write(description) local_file.close() for attachment in bug.attachments: f = attachment.data.open() filename = os.path.join(os.getcwd(), bug_folder_name, f.filename) local_file = open(filename, "w") local_file.write(f.read()) f.close() local_file.close() def main(): parser = OptionParser('Usage: %prog [options] <bug numbers>') parser.add_option('-d', '--duplicates', default=False, action='store_true', help='Download attachments from duplicates too') parser.add_option('-p', '--package', help='Download attachments from all bugs with an ' 'open task for this Ubuntu source package') parser.add_option('-P', '--project', help='Download attachments from all bugs with a ' 'open task for this project') parser.add_option('-D', '--descriptions', default=False, action='store_true', help='Also download bug descriptions as Description.txt') opts, args = parser.parse_args() if len(args) < 1 and not opts.package and not opts.project: parser.error('No bug numbers provided') launchpad = config.get_launchpad("grab-attachments") if opts.package: ubuntu = launchpad.projects['ubuntu'] src_package = ubuntu.getSourcePackage(name=opts.package) if src_package is None: parser.error('Unable to find package %s' % opts.package) for task in src_package.searchTasks(): args.append(task.bug.id) if opts.project: try: project = launchpad.projects['%s' % opts.project] except KeyError: parser.error('Unable to find project %s' % opts.project) for task in project.searchTasks(): args.append(task.bug.id) for arg in args: try: bug_number = int(arg) except ValueError: parser.error("'%s' is not a valid bug number." % arg) bug = launchpad.bugs[bug_number] download_attachments(bug, opts.descriptions) if opts.duplicates is True: for bug in bug.duplicates: download_attachments(bug, opts.descriptions) if __name__ == '__main__': main()