Beispiel #1
0
	def login(self, args=None):
		# Authenticate a session.
		# perform login
		params = {}
		params['login'] = self.user
		params['password'] = self.password
		if args is not None:
			params['remember'] = True
		log_info('Logging in')
		try:
			self.bz.User.login(params)
		except xmlrpc.client.Fault as fault:
			raise BugzError("Can't login: " + fault.faultString)
		log_info('Logging in')
		result = self.bz.User.login(params)
		if 'token' in result:
			self.token = result['token']

		if args is not None:
			if self.token:
				fd = open(self.token_file, 'w')
				fd.write(self.token)
				fd.write('\n')
				fd.close()
				os.chmod(self.token_file, 0o600)
			else:
				self.cookiejar.save()
				os.chmod(self.cookiejar.filename, 0o600)
Beispiel #2
0
	def __init__(self, args):
		self.columns = args.columns or terminal_width()
		self.user = args.user
		self.password = args.password
		self.passwordcmd = args.passwordcmd
		self.skip_auth = args.skip_auth

		cookie_file = os.path.join(os.environ['HOME'], DEFAULT_COOKIE_FILE)
		self.cookiejar = LWPCookieJar(cookie_file)

		try:
			self.cookiejar.load()
		except IOError:
			pass

		if getattr(args, 'encoding'):
			self.enc = args.encoding
		else:
			try:
				self.enc = locale.getdefaultlocale()[1]
			except:
				self.enc = 'utf-8'
			if not self.enc:
				self.enc = 'utf-8'

		log_info("Using %s " % args.base)
		self.bz = BugzillaProxy(args.base, cookiejar=self.cookiejar)
Beispiel #3
0
def main():
    ArgParser = make_arg_parser()
    args = ArgParser.parse_args()

    ConfigParser = load_config(getattr(args, 'config_file', None))

    check_bugz_token()
    settings = Settings(args, ConfigParser)

    if not hasattr(args, 'func'):
        ArgParser.print_usage()
        return 1

    try:
        args.func(settings)
    except BugzError as error:
        log_error(error)
        return 1
    except RuntimeError as error:
        log_error(error)
        return 1
    except KeyboardInterrupt:
        log_info('Stopped due to keyboard interrupt')
        return 1

    return 0
Beispiel #4
0
def main():
    ArgParser = make_arg_parser()
    args = ArgParser.parse_args()

    ConfigParser = load_config(getattr(args, 'config_file', None))

    check_bugz_token()
    settings = Settings(args, ConfigParser)

    if not hasattr(args, 'func'):
        ArgParser.print_usage()
        return 1

    try:
        args.func(settings)
    except BugzError as error:
        log_error(error)
        return 1
    except RuntimeError as error:
        log_error(error)
        return 1
    except KeyboardInterrupt:
        log_info('Stopped due to keyboard interrupt')
        return 1

    return 0
Beispiel #5
0
	def listbugs(self, buglist, show_status=False):
		FIELDS = (
			('id', 'Id', '%5s', lambda(s) : s),
			('priority', 'PRI', '%-4s', lambda(s) : s),
			('status', 'Status', '%-10s', lambda(s) : s),
			('severity', 'Severity', '%-15s', lambda(s) : s),
			('assigned_to', 'Assigned', '%-10s', lambda(s) : str.split(s, "@")[0]),
			('qa_contact', 'QA', '%-20s', lambda(s) : str.split(s, "@")[0]),
			('summary', 'Summary', '%s', lambda(s) : s),
		)

		line = ''
		for field in FIELDS:
			line = ('%s ' + field[2]) % (line, field[1])
		print line
		for bug in buglist:
			line = ''
			for field in FIELDS:
				line = ('%s ' + field[2]) % (line, field[3](bug[field[0]]))
			try:
				print line.encode(self.enc)[:self.columns]
			except UnicodeDecodeError:
				print line[:self.columns]

		log_info("%i bug(s) found." % len(buglist))
Beispiel #6
0
def attachment(settings):
    """ Download or view an attachment given the id."""
    log_info('Getting attachment %s' % settings.attachid)

    params = {}
    params['attachment_ids'] = [settings.attachid]

    login(settings)

    result = settings.call_bz(settings.bz.Bug.attachments, params)
    result = result['attachments'][settings.attachid]
    view = hasattr(settings, 'view')

    action = {True: 'Viewing', False: 'Saving'}
    log_info('%s attachment: "%s"' % (action[view], result['file_name']))
    safe_filename = os.path.basename(re.sub(r'\.\.', '', result['file_name']))

    if view:
        print(result['data'].data.decode('utf-8'))
    else:
        if os.path.exists(result['file_name']):
            raise RuntimeError('Filename already exists')

        fd = open(safe_filename, 'wb')
        fd.write(result['data'].data)
        fd.close()
Beispiel #7
0
	def __init__(self, args):
		self.columns = args.columns or terminal_width()
		self.user = args.user
		self.password = args.password
		self.passwordcmd = args.passwordcmd
		self.skip_auth = args.skip_auth

		cookie_file = os.path.join(os.environ['HOME'], DEFAULT_COOKIE_FILE)
		self.cookiejar = LWPCookieJar(cookie_file)

		try:
			self.cookiejar.load()
		except IOError:
			pass

		self.token_file = os.path.join(os.environ['HOME'], DEFAULT_TOKEN_FILE)
		try:
			self.token = open(self.token_file).read().strip()
		except IOError:
			self.token = None

		if getattr(args, 'encoding'):
			log_info("The --encoding option is deprecated.");

		log_info("Using %s " % args.base)
		self.bz = BugzillaProxy(args.base, cookiejar=self.cookiejar)
Beispiel #8
0
	def __init__(self, args):
		self.columns = args.columns or terminal_width()
		self.user = args.user
		self.password = args.password
		self.passwordcmd = args.passwordcmd
		self.skip_auth = args.skip_auth

		cookie_file = os.path.join(os.environ['HOME'], DEFAULT_COOKIE_FILE)
		self.cookiejar = LWPCookieJar(cookie_file)

		try:
			self.cookiejar.load()
		except IOError:
			pass

		if getattr(args, 'encoding'):
			self.enc = args.encoding
		else:
			try:
				self.enc = locale.getdefaultlocale()[1]
			except:
				self.enc = 'utf-8'
			if not self.enc:
				self.enc = 'utf-8'

		log_info("Using %s " % args.base)
		self.bz = BugzillaProxy(args.base, cookiejar=self.cookiejar)
Beispiel #9
0
Datei: cli.py Projekt: CMB/pybugz
	def attachment(self, conn):
		""" Download or view an attachment given the id."""
		log_info('Getting attachment %s' % conn.attachid)

		params = {}
		params['attachment_ids'] = [conn.attachid]
		result = self.call_bz(self.bz.Bug.attachments, params)
		result = result['attachments'][conn.attachid]
		view = getattr(conn, 'view', False)

		action = {True: 'Viewing', False: 'Saving'}
		log_info('%s attachment: "%s"' %
			(action[view], result['file_name']))
		safe_filename = os.path.basename(re.sub(r'\.\.', '',
												result['file_name']))

		if view:
			print(result['data'].data)
		else:
			if os.path.exists(result['file_name']):
				raise RuntimeError('Filename already exists')

			fd = open(safe_filename, 'wb')
			fd.write(result['data'].data)
			fd.close()
Beispiel #10
0
def get(conn):
	""" Fetch bug details given the bug id """
	login(conn)
	log_info('Getting bug %s ..' % conn.bugid)
	params = {'ids': [conn.bugid]}
	result = conn.call_bz(conn.bz.Bug.get, params)

	for bug in result['bugs']:
		show_bug_info(bug, conn)
Beispiel #11
0
def get(settings):
    """ Fetch bug details given the bug id """
    check_auth(settings)

    log_info('Getting bug %s ..' % settings.bugid)
    params = {'ids': [settings.bugid]}
    result = settings.call_bz(settings.bz.Bug.get, params)

    for bug in result['bugs']:
        show_bug_info(bug, settings)
Beispiel #12
0
    def get(self, args):
        """ Fetch bug details given the bug id """
        log_info("Getting bug %s .." % args.bugid)
        try:
            result = self.bzcall(self.bz.Bug.get, {"ids": [args.bugid]})
        except xmlrpclib.Fault as fault:
            raise BugzError("Can't get bug #" + str(args.bugid) + ": " + fault.faultString)

        for bug in result["bugs"]:
            self.showbuginfo(bug, args.attachments, args.comments)
Beispiel #13
0
def get(settings):
    """ Fetch bug details given the bug id """
    login(settings)

    log_info('Getting bug %s ..' % settings.bugid)
    params = {'ids': [settings.bugid]}
    result = settings.call_bz(settings.bz.Bug.get, params)

    for bug in result['bugs']:
        show_bug_info(bug, settings)
Beispiel #14
0
	def get(self, args):
		""" Fetch bug details given the bug id """
		log_info('Getting bug %s ..' % args.bugid)
		try:
			result = self.bzcall(self.bz.Bug.get, {'ids':[args.bugid]})
		except xmlrpclib.Fault as fault:
			raise BugzError("Can't get bug #" + str(args.bugid) + ": " \
					+ fault.faultString)

		for bug in result['bugs']:
			self.showbuginfo(bug, args.attachments, args.comments)
Beispiel #15
0
	def get(self, args):
		""" Fetch bug details given the bug id """
		log_info('Getting bug %s ..' % args['bugid'])
		try:
			result = self.call_bz(self.bz.Bug.get, {'ids':[args['bugid']]})
		except xmlrpc.client.Fault as fault:
			raise BugzError("Can't get bug #" + str(args['bugid']) + ": " \
					+ fault.faultString)

		for bug in result['bugs']:
			self.show_bug_info(bug, args.attachments, args.comments)
Beispiel #16
0
def get(conn):
    """ Fetch bug details given the bug id """
    if not conn.skip_auth:
        login(conn)

    log_info('Getting bug %s ..' % conn.bugid)
    params = {'ids': [conn.bugid]}
    result = conn.call_bz(conn.bz.Bug.get, params)

    for bug in result['bugs']:
        show_bug_info(bug, conn)
Beispiel #17
0
Datei: cli.py Projekt: CMB/pybugz
	def get(self, conn):
		""" Fetch bug details given the bug id """
		log_info('Getting bug %s ..' % conn.bugid)
		try:
			params = {'ids': [conn.bugid]}
			result = self.call_bz(self.bz.Bug.get, params)
		except xmlrpc.client.Fault as fault:
			raise BugzError("Can't get bug #" + str(conn.bugid) + ": "
					+ fault.faultString)

		for bug in result['bugs']:
			self.show_bug_info(bug, conn)
Beispiel #18
0
def get(settings):
    """ Fetch bug details given the bug id """
    if not settings.skip_auth:
        login(settings)

    log_info('Getting bug %s ..' % settings.bugid)
    params = {'ids': [settings.bugid]}
    result = settings.call_bz(settings.bz.Bug.get, params)

    if settings.json:
        json_records(result['bugs'])
    else:
        for bug in result['bugs']:
            show_bug_info(bug, settings)
Beispiel #19
0
	def post(self, args):
		"""Post a new bug"""

		params={}
		params['product'] = args['product']
		params['component'] = args['component']
		params['summary'] = args['summary']
		params['description'] = args['description']
		#params['assigned_to'] = args['assigned_to']
		params['version'] = args['version']
		
		result = self.call_bz(self.bz.Bug.create, params)
		log_info('Bug %d submitted' % result['id'])
		return result
Beispiel #20
0
	def search(self, args):
		"""Performs a search on the bugzilla database with the keywords given on the title (or the body if specified).
		"""
		valid_keys = ['alias', 'assigned_to', 'component', 'creator',
			'limit', 'offset', 'op_sys', 'platform',
			'priority', 'product', 'resolution',
			'severity', 'status', 'version', 'whiteboard',
			'qa_contact', 'cf_branch', 'cf_autotest']

		search_opts = sorted([(opt, val) for opt, val in args.__dict__.items()
			if val is not None and opt in valid_keys])

		params = {}
		for key in args.__dict__.keys():
			if key in valid_keys and getattr(args, key) is not None:
				params[key] = getattr(args, key)
		if getattr(args, 'terms'):
			params['summary'] = args.terms

		search_term = ' '.join(args.terms).strip()

		if not (params or search_term):
			raise BugzError('Please give search terms or options.')

		if search_term:
			log_msg = 'Searching for \'%s\' ' % search_term
		else:
			log_msg = 'Searching for bugs '

		if search_opts:
			log_info(log_msg + 'with the following options:')
			for opt, val in search_opts:
				log_info('   %-20s = %s' % (opt, val))
		else:
			log_info(log_msg)

		if not 'status' in params.keys():
			params['status'] = ['NEW', 'ASSIGNED', 'REOPENED']
		elif 'ALL' in params['status']:
			del params['status']
		elif 'FORAUTOTEST' in params['status']:
			params['status'] = ['RESOLVED', 'NEEDMERGE', 'TESTING']

		if 'VMmanager-KVM' in params['product']:
			params['product'] = ['VMmanager']
			params['version'] = ['KVM', 'Cloud']
		elif 'VMmanager-OVZ' in params['product']:
			params['product'] = ['Vmmanager']
			params['version'] = ['OVZ']

		result = self.bzcall(self.bz.Bug.search, params)['bugs']

		if not len(result):
			log_info('No bugs found.')
		else:
			if args.tree:
				self.add_missed_blocking(result)
				self.show(result)
			else:
				self.listbugs(result, args.show_status, args.show_branch, args.show_teststatus)
Beispiel #21
0
	def modify(self, args):
		"""Modify an existing bug (eg. adding a comment or changing resolution.)"""

		params = {}
		if args['cc_add'] is not None:
			params['cc'] = {}
		if args['comment'] is not None:
			params['comment'] = {}
		params['ids'] = args['bugid']
		# if args['assigned_to'] is not None:
		# params['assigned_to'] = args['assigned_to']
		if args['cc_add'] is not None:
			params['cc']['add'] = args['cc_add']
		if args['comment'] is not None:
			params['comment']['body'] = args['comment']

		if len(params) < 2:
			raise BugzError('No changes were specified')
		result = self.call_bz(self.bz.Bug.update, params)
		for bug in result['bugs']:
			changes = bug['changes']
			if not len(changes):
				log_info('Added comment to bug %s' % bug['id'])
			else:
				log_info('Modified the following fields in bug %s' % bug['id'])
				for key in changes:
					log_info('%-12s: removed %s' %(key, changes[key]['removed']))
					log_info('%-12s: added %s' %(key, changes[key]['added']))
Beispiel #22
0
    def search(self, args):
        """Performs a search on the bugzilla database with the keywords given on the title (or the body if specified).
		"""
        valid_keys = [
            "alias",
            "assigned_to",
            "component",
            "creator",
            "limit",
            "offset",
            "op_sys",
            "platform",
            "priority",
            "product",
            "resolution",
            "severity",
            "status",
            "version",
            "whiteboard",
        ]

        search_opts = sorted(
            [(opt, val) for opt, val in args.__dict__.items() if val is not None and opt in valid_keys]
        )

        params = {}
        for key in args.__dict__.keys():
            if key in valid_keys and getattr(args, key) is not None:
                params[key] = getattr(args, key)
        if getattr(args, "terms"):
            params["summary"] = args.terms

        search_term = " ".join(args.terms).strip()

        if not (params or search_term):
            raise BugzError("Please give search terms or options.")

        if search_term:
            log_msg = "Searching for '%s' " % search_term
        else:
            log_msg = "Searching for bugs "

        if search_opts:
            log_info(log_msg + "with the following options:")
            for opt, val in search_opts:
                log_info("   %-20s = %s" % (opt, val))
        else:
            log_info(log_msg)

        if not "status" in params.keys():
            params["status"] = ["CONFIRMED", "IN_PROGRESS", "UNCONFIRMED"]
        elif "ALL" in params["status"]:
            del params["status"]

        result = self.bzcall(self.bz.Bug.search, params)["bugs"]

        if not len(result):
            log_info("No bugs found.")
        else:
            self.listbugs(result, args.show_status)
Beispiel #23
0
def get(settings):
    """ Fetch bug details given the bug id """
    check_auth(settings)

    log_info('Getting bug %s ..' % settings.bugid)
    params = {'ids': settings.bugid}
    result = settings.call_bz(settings.bz.Bug.get, params)

    bugs = result['bugs']
    if settings.summary:
        settings.show_status = True
        list_bugs(bugs, settings)
    else:
        bugCount = len(bugs)
        for idx, bug in enumerate(bugs):
            show_bug_info(bug, settings)
            if idx + 1 != bugCount:
                print()
Beispiel #24
0
def list_bugs(buglist, settings):
    fmt = settings.format
    if fmt is None:
        fmt = '{bug[id]}'
        if hasattr(settings, 'show_status'):
            fmt += ' {bug[status]:>12}'
        if hasattr(settings, 'show_priority'):
            fmt += ' {bug[priority]:>12}'
        if hasattr(settings, 'show_severity'):
            fmt += ' {bug[severity]:>12}'
        fmt += ' {bug[short_assigned_to]:>20}'
        fmt += ' {bug[summary]}'

    for bug in buglist:
        bug['short_assigned_to'] = bug['assigned_to'].split('@')[0]

        write(fmt.format(bug=bug)[:settings.columns])
    log_info("%i bug(s) found." % len(buglist))
Beispiel #25
0
	def listbugs(self, buglist, show_status=False):
		for bug in buglist:
			bugid = bug['id']
			status = bug['status']
			assignee = bug['assigned_to'].split('@')[0]
			desc = bug['summary']
			line = '%s' % (bugid)
			if show_status:
				line = '%s %-12s' % (line, status)
			line = '%s %-20s' % (line, assignee)
			line = '%s %s' % (line, desc)

			try:
				print line.encode(self.enc)[:self.columns]
			except UnicodeDecodeError:
				print line[:self.columns]

		log_info("%i bug(s) found." % len(buglist))
Beispiel #26
0
	def listbugs(self, buglist, show_status=False):
		for bug in buglist:
			bugid = bug['id']
			status = bug['status']
			assignee = bug['assigned_to'].split('@')[0]
			desc = bug['summary']
			line = '%s' % (bugid)
			if show_status:
				line = '%s %-12s' % (line, status)
			line = '%s %-20s' % (line, assignee)
			line = '%s %s' % (line, desc)

			try:
				print line.encode(self.enc)[:self.columns]
			except UnicodeDecodeError:
				print line[:self.columns]

		log_info("%i bug(s) found." % len(buglist))
Beispiel #27
0
    def listbugs(self, buglist, show_status=False):
        for bug in buglist:
            bugid = bug["id"]
            status = bug["status"]
            assignee = bug["assigned_to"].split("@")[0]
            desc = bug["summary"]
            line = "%s" % (bugid)
            if show_status:
                line = "%s %-12s" % (line, status)
            line = "%s %-20s" % (line, assignee)
            line = "%s %s" % (line, desc)

            try:
                print line.encode(self.enc)[: self.columns]
            except UnicodeDecodeError:
                print line[: self.columns]

        log_info("%i bug(s) found." % len(buglist))
Beispiel #28
0
def list_bugs(buglist, settings):
    for bug in buglist:
        bugid = bug['id']
        status = bug['status']
        priority = bug['priority']
        severity = bug['severity']
        assignee = bug['assigned_to'].split('@')[0]
        desc = bug['summary']
        line = '%s' % (bugid)
        if hasattr(settings, 'show_status'):
            line = '%s %-12s' % (line, status)
        if hasattr(settings, 'show_priority'):
            line = '%s %-12s' % (line, priority)
        if hasattr(settings, 'show_severity'):
            line = '%s %-12s' % (line, severity)
        line = '%s %-20s' % (line, assignee)
        line = '%s %s' % (line, desc)
        print(line[:settings.columns])

    log_info("%i bug(s) found." % len(buglist))
Beispiel #29
0
Datei: cli.py Projekt: CMB/pybugz
	def list_bugs(self, buglist, conn):
		for bug in buglist:
			bugid = bug['id']
			status = bug['status']
			priority = bug['priority']
			severity = bug['severity']
			assignee = bug['assigned_to'].split('@')[0]
			desc = bug['summary']
			line = '%s' % (bugid)
			if conn.show_status:
				line = '%s %-12s' % (line, status)
			if conn.show_priority:
				line = '%s %-12s' % (line, priority)
			if conn.show_severity:
				line = '%s %-12s' % (line, severity)
			line = '%s %-20s' % (line, assignee)
			line = '%s %s' % (line, desc)
			print(line[:conn.columns])

		log_info("%i bug(s) found." % len(buglist))
Beispiel #30
0
def list_bugs(buglist, settings):
    for bug in buglist:
        bugid = bug['id']
        status = bug['status']
        priority = bug['priority']
        severity = bug['severity']
        assignee = bug['assigned_to'].split('@')[0]
        desc = bug['summary']
        line = '%s' % (bugid)
        if hasattr(settings, 'show_status'):
            line = '%s %-12s' % (line, status)
        if hasattr(settings, 'show_priority'):
            line = '%s %-12s' % (line, priority)
        if hasattr(settings, 'show_severity'):
            line = '%s %-12s' % (line, severity)
        line = '%s %-20s' % (line, assignee)
        line = '%s %s' % (line, desc)
        print(line[:settings.columns])

    log_info("%i bug(s) found." % len(buglist))
Beispiel #31
0
	def __init__(self, args):
		self.user = args['user']
		self.password = args['password']
		self.skip_auth = args['skip_auth']

		cookie_file = os.path.join(os.environ['HOME'], DEFAULT_COOKIE_FILE)
		self.cookiejar = LWPCookieJar(cookie_file)

		try:
			self.cookiejar.load()
		except IOError:
			pass

		self.token_file = os.path.join(os.environ['HOME'], DEFAULT_TOKEN_FILE)
		try:
			self.token = open(self.token_file).read().strip()
		except IOError:
			self.token = None

		log_info("Using %s " % args['url'])
		self.bz = BugzillaProxy(args['url'], cookiejar=self.cookiejar)
Beispiel #32
0
	def login(self, args=None):
		"""Authenticate a session.
		"""
		# prompt for username if we were not supplied with it
		if not self.user:
			log_info('No username given.')
			self.user = self.get_input('Username: '******'No password given.')
				self.password = getpass.getpass()
			else:
				process = subprocess.Popen(self.passwordcmd.split(), shell=False,
					stdout=subprocess.PIPE)
				self.password, _ = process.communicate()

		# perform login
		params = {}
		params['login'] = self.user
		params['password'] = self.password
		if args is not None:
			params['remember'] = True
		log_info('Logging in')
		try:
			self.bz.User.login(params)
		except xmlrpclib.Fault as fault:
			raise BugzError("Can't login: " + fault.faultString)

		if args is not None:
			self.cookiejar.save()
			os.chmod(self.cookiejar.filename, 0600)
Beispiel #33
0
def search(settings):
    """Performs a search on the bugzilla database with
the keywords given on the title (or the body if specified).
    """
    valid_keys = ['alias', 'assigned_to', 'component', 'creator',
                  'limit', 'offset', 'op_sys', 'platform',
                  'priority', 'product', 'resolution', 'severity',
                  'version', 'whiteboard', 'cc']

    params = {}
    d = vars(settings)
    for key in d:
        if key in valid_keys:
            params[key] = d[key]
    if 'search_statuses' in d:
        if 'all' not in d['search_statuses']:
            params['status'] = d['search_statuses']
    if 'terms' in d:
        params['summary'] = d['terms']

    if not params:
        raise BugzError('Please give search terms or options.')

    log_info('Searching for bugs meeting the following criteria:')
    for key in params:
        log_info('   {0:<20} = {1}'.format(key, params[key]))

    check_auth(settings)

    result = settings.call_bz(settings.bz.Bug.search, params)['bugs']

    if not len(result):
        log_info('No bugs found.')
    else:
        list_bugs(result, settings)
Beispiel #34
0
	def login(self, args=None):
		"""Authenticate a session.
		"""
		# prompt for username if we were not supplied with it
		if not self.user:
			log_info('No username given.')
			self.user = self.get_input('Username: '******'No password given.')
				self.password = getpass.getpass()
			else:
				process = subprocess.Popen(self.passwordcmd.split(), shell=False,
					stdout=subprocess.PIPE)
				self.password, _ = process.communicate()

		# perform login
		params = {}
		params['login'] = self.user
		params['password'] = self.password
		if args is not None:
			params['remember'] = True
		log_info('Logging in')
		try:
			self.bz.User.login(params)
		except xmlrpclib.Fault as fault:
			raise BugzError("Can't login: " + fault.faultString)

		if args is not None:
			self.cookiejar.save()
			os.chmod(self.cookiejar.filename, 0600)
Beispiel #35
0
def login(conn):
	"""Authenticate a session.
	"""
	conn.load_token()
	if conn.bz_token is not None:
		return

	# prompt for username if we were not supplied with it
	if not hasattr(conn, 'user'):
		log_info('No username given.')
		user = input('Username: '******'password'):
		if not hasattr(conn, 'passwordcmd'):
			log_info('No password given.')
			password = getpass.getpass()
		else:
			process = subprocess.Popen(conn.passwordcmd, shell=True,
				stdout=subprocess.PIPE)
			password, _ = process.communicate()
			password = password.splitlines()[0]
	else:
		password = conn.password

	# perform login
	params = {}
	params['login'] = user
	params['password'] = password
	log_info('Logging in')
	result = conn.call_bz(conn.bz.User.login, params)
	if 'token' in result:
		conn.save_token(result['token'])
Beispiel #36
0
def search(conn):
	"""Performs a search on the bugzilla database with
the keywords given on the title (or the body if specified).
	"""
	valid_keys = ['alias', 'assigned_to', 'component', 'creator',
		'limit', 'offset', 'op_sys', 'platform',
		'priority', 'product', 'resolution',
		'severity', 'status', 'version', 'whiteboard']

	search_opts = sorted([(opt, val) for opt, val in list(conn.__dict__.items())
		if val is not None and opt in valid_keys])

	params = {}
	for key in conn.__dict__:
		if key in valid_keys and getattr(conn, key) is not None:
			params[key] = getattr(conn, key)
	if getattr(conn, 'terms'):
		params['summary'] = conn.terms

	search_term = ' '.join(conn.terms).strip()

	if not (params or search_term):
		raise BugzError('Please give search terms or options.')

	if search_term:
		log_msg = 'Searching for \'%s\' ' % search_term
	else:
		log_msg = 'Searching for bugs '

	if search_opts:
		log_info(log_msg + 'with the following options:')
		for opt, val in search_opts:
			log_info('   %-20s = %s' % (opt, val))
	else:
		log_info(log_msg)

	if 'status' not in params:
		params['status'] = ['CONFIRMED', 'IN_PROGRESS', 'UNCONFIRMED']
	else:
		for x in params['status'][:]:
			if x in ['all', 'ALL']:
				del params['status']

	login(conn)
	result = conn.call_bz(conn.bz.Bug.search, params)['bugs']

	if not len(result):
		log_info('No bugs found.')
	else:
		list_bugs(result, conn)
Beispiel #37
0
def attach(settings):
    """ Attach a file to a bug given a filename. """
    filename = getattr(settings, 'filename', None)
    content_type = getattr(settings, 'content_type', None)
    bugid = getattr(settings, 'bugid', None)
    summary = getattr(settings, 'summary', None)
    is_patch = getattr(settings, 'is_patch', None)
    comment = getattr(settings, 'comment', None)

    if not os.path.exists(filename):
        raise BugzError('File not found: %s' % filename)

    if content_type is None:
        content_type = get_content_type(filename)

    if comment is None:
        comment = block_edit('Enter optional long description of attachment')

    if summary is None:
        summary = os.path.basename(filename)

    params = {}
    params['ids'] = [bugid]

    fd = open(filename, 'rb')
    params['data'] = xmlrpc.client.Binary(fd.read())
    fd.close()

    params['file_name'] = os.path.basename(filename)
    params['summary'] = summary
    params['content_type'] = content_type
    params['comment'] = comment
    if is_patch is not None:
        params['is_patch'] = is_patch
    check_auth(settings)
    result = settings.call_bz(settings.bz.Bug.add_attachment, params)
    attachid = result['ids'][0]
    log_info('{0} ({1}) has been attached to bug {2}'.format(
        filename, attachid, bugid))
Beispiel #38
0
    def attachment(self, args):
        """ Download or view an attachment given the id."""
        log_info("Getting attachment %s" % args.attachid)

        params = {}
        params["attachment_ids"] = [args.attachid]
        result = self.bzcall(self.bz.Bug.attachments, params)
        result = result["attachments"][args.attachid]

        action = {True: "Viewing", False: "Saving"}
        log_info('%s attachment: "%s"' % (action[args.view], result["file_name"]))
        safe_filename = os.path.basename(re.sub(r"\.\.", "", result["file_name"]))

        if args.view:
            print result["data"].data
        else:
            if os.path.exists(result["file_name"]):
                raise RuntimeError("Filename already exists")

            fd = open(safe_filename, "wb")
            fd.write(result["data"].data)
            fd.close()
Beispiel #39
0
def login(settings):
    """Authenticate a session.
    """

    if settings.skip_auth or hasattr(settings, 'key'):
        return

    # prompt for username if we were not supplied with it
    if not hasattr(settings, 'user'):
        log_info('No username given.')
        settings.user = input('Username: '******'password'):
        if not hasattr(settings, 'passwordcmd'):
            log_info('No password given.')
            settings.password = getpass.getpass()
        else:
            process = subprocess.Popen(settings.passwordcmd, shell=True,
                                       stdout=subprocess.PIPE)
            password, _ = process.communicate()
            settings.password = password.splitlines()[0]
Beispiel #40
0
def attach(settings):
    """ Attach a file to a bug given a filename. """
    filename = getattr(settings, 'filename', None)
    content_type = getattr(settings, 'content_type', None)
    bugid = getattr(settings, 'bugid', None)
    summary = getattr(settings, 'summary', None)
    is_patch = getattr(settings, 'is_patch', None)
    comment = getattr(settings, 'comment', None)

    if not os.path.exists(filename):
        raise BugzError('File not found: %s' % filename)

    if content_type is None:
        content_type = get_content_type(filename)

    if comment is None:
        comment = block_edit('Enter optional long description of attachment')

    if summary is None:
        summary = os.path.basename(filename)

    params = {}
    params['ids'] = [bugid]

    fd = open(filename, 'rb')
    params['data'] = xmlrpc.client.Binary(fd.read())
    fd.close()

    params['file_name'] = os.path.basename(filename)
    params['summary'] = summary
    params['content_type'] = content_type
    params['comment'] = comment
    if is_patch is not None:
        params['is_patch'] = is_patch
    login(settings)
    result = settings.call_bz(settings.bz.Bug.add_attachment, params)
    attachid = result['ids'][0]
    log_info('{0} ({1}) has been attached to bug {2}'.format(
        filename, attachid, bugid))
Beispiel #41
0
	def attach(self, args):
		""" Attach a file to a bug given a filename. """
		filename = args['filename']
		summary = os.path.basename(filename)
		comment = args['comment']

		if not os.path.exists(filename):
			raise BugzError('File not found: %s' % filename)

		params = {}
		params['ids'] = args['bugid']

		fd = open(filename, 'rb')
		params['data'] = xmlrpc.client.Binary(fd.read())
		fd.close()

		params['file_name'] = os.path.basename(filename)
		params['summary'] = summary
		params['content_type'] = args['content_type']
		params['comment'] = comment
		#params['is_patch'] = is_patch
		result =  self.call_bz(self.bz.Bug.add_attachment, params)
		log_info("'%s' has been attached to bug %s" % (filename, args['bugid']))
Beispiel #42
0
def login(settings):
    """Authenticate a session.
    """

    if settings.skip_auth or hasattr(settings, 'key'):
        return

    # prompt for username if we were not supplied with it
    if not hasattr(settings, 'user'):
        log_info('No username given.')
        settings.user = input('Username: '******'password'):
        if not hasattr(settings, 'passwordcmd'):
            log_info('No password given.')
            settings.password = getpass.getpass()
        else:
            process = subprocess.Popen(settings.passwordcmd,
                                       shell=True,
                                       stdout=subprocess.PIPE)
            password, _ = process.communicate()
            settings.password = password.splitlines()[0]
Beispiel #43
0
def check_auth(settings):
    """Authenticate a session.
    """
    if settings.skip_auth:
        for x in ['key', 'user', 'password']:
            if hasattr(settings, x):
                delattr(settings, x)
    elif settings.interactive:
        # prompt for username if we were not supplied with it
        if not hasattr(settings, 'user'):
            log_info('No username given.')
            settings.user = input('Username: '******'password'):
            if not hasattr(settings, 'passwordcmd'):
                log_info('No password given.')
                settings.password = getpass.getpass()
            else:
                process = subprocess.Popen(settings.passwordcmd, shell=True,
                        stdout=subprocess.PIPE)
                password, _ = process.communicate()
                settings.password = password.splitlines()[0]
Beispiel #44
0
	def attach(self, args):
		""" Attach a file to a bug given a filename. """
		filename = args.filename
		content_type = args.content_type
		bugid = args.bugid
		summary = args.summary
		is_patch = args.is_patch
		comment = args.comment

		if not os.path.exists(filename):
			raise BugzError('File not found: %s' % filename)

		if content_type is None:
			content_type = get_content_type(filename)

		if comment is None:
			comment = block_edit('Enter optional long description of attachment')

		if summary is None:
			summary = os.path.basename(filename)

		params = {}
		params['ids'] = [bugid]

		fd = open(filename, 'rb')
		params['data'] = xmlrpclib.Binary(fd.read())
		fd.close()

		params['file_name'] = os.path.basename(filename)
		params['summary'] = summary
		if not is_patch:
			params['content_type'] = content_type;
		params['comment'] = comment
		params['is_patch'] = is_patch
		result =  self.bzcall(self.bz.Bug.add_attachment, params)
		log_info("'%s' has been attached to bug %s" % (filename, bugid))
Beispiel #45
0
def check_auth(settings):
    """Authenticate a session.
    """
    if settings.skip_auth:
        for x in ['key', 'user', 'password']:
            if hasattr(settings, x):
                delattr(settings, x)
    elif settings.interactive:
        # prompt for username if we were not supplied with it
        if not hasattr(settings, 'user'):
            log_info('No username given.')
            settings.user = input('Username: '******'password'):
            if not hasattr(settings, 'passwordcmd'):
                log_info('No password given.')
                settings.password = getpass.getpass()
            else:
                process = subprocess.Popen(settings.passwordcmd,
                                           shell=True,
                                           stdout=subprocess.PIPE)
                password, _ = process.communicate()
                settings.password = password.splitlines()[0]
Beispiel #46
0
	def search(self, args):
		"""Performs a search on the bugzilla database with the keywords given on the title (or the body if specified).
		"""
		valid_keys = ['alias', 'assigned_to', 'component', 'creator',
			'limit', 'offset', 'op_sys', 'platform',
			'priority', 'product', 'resolution',
			'severity', 'status', 'version', 'whiteboard']

		search_opts = sorted([(opt, val) for opt, val in args.__dict__.items()
			if val is not None and opt in valid_keys])

		params = {}
		for key in args.__dict__.keys():
			if key in valid_keys and getattr(args, key) is not None:
				params[key] = getattr(args, key)
		if getattr(args, 'terms'):
			params['summary'] = args.terms

		search_term = ' '.join(args.terms).strip()

		if not (params or search_term):
			raise BugzError('Please give search terms or options.')

		if search_term:
			log_msg = 'Searching for \'%s\' ' % search_term
		else:
			log_msg = 'Searching for bugs '

		if search_opts:
			log_info(log_msg + 'with the following options:')
			for opt, val in search_opts:
				log_info('   %-20s = %s' % (opt, val))
		else:
			log_info(log_msg)

		if not 'status' in params.keys():
			params['status'] = ['CONFIRMED', 'IN_PROGRESS', 'UNCONFIRMED']
		elif 'ALL' in params['status']:
			del params['status']

		result = self.bzcall(self.bz.Bug.search, params)['bugs']

		if not len(result):
			log_info('No bugs found.')
		else:
			self.listbugs(result, args.show_status)
Beispiel #47
0
	def attach(self, args):
		""" Attach a file to a bug given a filename. """
		filename = args.filename
		content_type = args.content_type
		bugid = args.bugid
		summary = args.summary
		is_patch = args.is_patch
		comment = args.comment

		if not os.path.exists(filename):
			raise BugzError('File not found: %s' % filename)

		if content_type is None:
			content_type = get_content_type(filename)

		if comment is None:
			comment = block_edit('Enter optional long description of attachment')

		if summary is None:
			summary = os.path.basename(filename)

		params = {}
		params['ids'] = [bugid]

		fd = open(filename, 'rb')
		params['data'] = xmlrpclib.Binary(fd.read())
		fd.close()

		params['file_name'] = os.path.basename(filename)
		params['summary'] = summary
		if not is_patch:
			params['content_type'] = content_type;
		params['comment'] = comment
		params['is_patch'] = is_patch
		result =  self.bzcall(self.bz.Bug.add_attachment, params)
		log_info("'%s' has been attached to bug %s" % (filename, bugid))
Beispiel #48
0
	def attachment(self, args):
		""" Download or view an attachment given the id."""
		log_info('Getting attachment %s' % args.attachid)

		params = {}
		params['attachment_ids'] = [args.attachid]
		result = self.bzcall(self.bz.Bug.attachments, params)
		result = result['attachments'][args.attachid]

		action = {True:'Viewing', False:'Saving'}
		log_info('%s attachment: "%s"' %
			(action[args.view], result['file_name']))
		safe_filename = os.path.basename(re.sub(r'\.\.', '',
												result['file_name']))

		if args.view:
			print result['data'].data
		else:
			if os.path.exists(result['file_name']):
				raise RuntimeError('Filename already exists')

			fd = open(safe_filename, 'wb')
			fd.write(result['data'].data)
			fd.close()
Beispiel #49
0
def search(settings):
    """Performs a search on the bugzilla database with
the keywords given on the title (or the body if specified).
    """
    valid_keys = [
        'alias', 'assigned_to', 'component', 'creator', 'limit', 'offset',
        'op_sys', 'platform', 'priority', 'product', 'resoluion', 'severity',
        'version', 'whiteboard'
    ]

    params = {}
    d = vars(settings)
    for key in d:
        if key in valid_keys:
            params[key] = d[key]

    if 'after' in d:
        # This seem to break when you include a time - but work for days
        params['creation_time'] = d['after'].strftime("%Y%m%d")

    if 'status' in d:
        if 'all' not in d['status']:
            params['status'] = d['status']
    elif 'search_statuses' in d:
        params['status'] = [
            urllib.parse.unquote(s) for s in d['search_statuses']
        ]
    if 'terms' in d:
        params['summary'] = d['terms']

    log_info('Searching for bugs meeting the following criteria:')
    for key in params:
        log_info('   {0:<20} = {1}'.format(key, params[key]))

    if not settings.skip_auth:
        login(settings)

    result = settings.call_bz(settings.bz.Bug.search, params)['bugs']

    if hasattr(settings, 'not_status'):
        result = list(b for b in result
                      if b['status'] not in settings.not_status)

    if settings.sort:
        result.sort(key=lambda r: tuple(r.get(k) for k in settings.sort))

    if not len(result):
        log_info('No bugs found.')
    elif settings.json:
        json_records(result)
    else:
        list_bugs(result, settings)
Beispiel #50
0
def search(conn):
    """Performs a search on the bugzilla database with
the keywords given on the title (or the body if specified).
	"""
    valid_keys = [
        'alias', 'assigned_to', 'component', 'creator', 'limit', 'offset',
        'op_sys', 'platform', 'priority', 'product', 'resolution', 'severity',
        'version', 'whiteboard'
    ]

    params = {}
    d = vars(conn)
    for key in d:
        if key in valid_keys:
            params[key] = d[key]
    if 'status' in d:
        if 'all' not in d['status']:
            params['status'] = d['status']
    elif 'search_statuses' in d:
        params['status'] = d['search_statuses']
    if 'terms' in d:
        params['summary'] = d['terms']
        search_term = ' '.join(d['terms']).strip()

    if not params:
        raise BugzError('Please give search terms or options.')

    log_info('Searching for bugs meeting the following criteria:')
    for key in params:
        log_info('   {0:<20} = {1}'.format(key, params[key]))

    if not conn.skip_auth:
        login(conn)

    result = conn.call_bz(conn.bz.Bug.search, params)['bugs']

    if not len(result):
        log_info('No bugs found.')
    else:
        list_bugs(result, conn)
Beispiel #51
0
def login(settings):
    """Authenticate a session.
    """
    settings.load_token()
    if settings.bz_token is not None:
        return

    # prompt for username if we were not supplied with it
    if not hasattr(settings, 'user'):
        log_info('No username given.')
        user = input('Username: '******'password'):
        if not hasattr(settings, 'passwordcmd'):
            log_info('No password given.')
            password = getpass.getpass()
        else:
            process = subprocess.Popen(settings.passwordcmd,
                                       shell=True,
                                       stdout=subprocess.PIPE)
            password, _ = process.communicate()
            password = password.splitlines()[0]
    else:
        password = settings.password

    # perform login
    params = {}
    params['login'] = user
    params['password'] = password
    log_info('Logging in')
    result = settings.call_bz(settings.bz.User.login, params)
    if 'token' in result:
        settings.save_token(result['token'])
Beispiel #52
0
def logout(conn):
    conn.load_token()
    params = {}
    log_info('logging out')
    conn.call_bz(conn.bz.User.logout, params)
    conn.destroy_token()
Beispiel #53
0
def modify(conn):
    """Modify an existing bug (eg. adding a comment or changing resolution.)"""
    if hasattr(conn, 'comment_from'):
        try:
            if conn.comment_from == '-':
                conn.comment = sys.stdin.read()
            else:
                conn.comment = open(conn.comment_from, 'r').read()
        except IOError as e:
            raise BugzError('unable to read file: %s: %s' %
                            (conn.comment_from, e))

    if hasattr(conn, 'comment_editor'):
        conn.comment = block_edit('Enter comment:')

    params = {}
    params['ids'] = [conn.bugid]
    if hasattr(conn, 'alias'):
        params['alias'] = conn.alias
    if hasattr(conn, 'assigned_to'):
        params['assigned_to'] = conn.assigned_to
    if hasattr(conn, 'blocks_add'):
        if 'blocks' not in params:
            params['blocks'] = {}
        params['blocks']['add'] = conn.blocks_add
    if hasattr(conn, 'blocks_remove'):
        if 'blocks' not in params:
            params['blocks'] = {}
        params['blocks']['remove'] = conn.blocks_remove
    if hasattr(conn, 'depends_on_add'):
        if 'depends_on' not in params:
            params['depends_on'] = {}
        params['depends_on']['add'] = conn.depends_on_add
    if hasattr(conn, 'depends_on_remove'):
        if 'depends_on' not in params:
            params['depends_on'] = {}
        params['depends_on']['remove'] = conn.depends_on_remove
    if hasattr(conn, 'cc_add'):
        if 'cc' not in params:
            params['cc'] = {}
        params['cc']['add'] = conn.cc_add
    if hasattr(conn, 'cc_remove'):
        if 'cc' not in params:
            params['cc'] = {}
        params['cc']['remove'] = conn.cc_remove
    if hasattr(conn, 'comment'):
        if 'comment' not in params:
            params['comment'] = {}
        params['comment']['body'] = conn.comment
    if hasattr(conn, 'component'):
        params['component'] = conn.component
    if hasattr(conn, 'dupe_of'):
        params['dupe_of'] = conn.dupe_of
    if hasattr(conn, 'groups_add'):
        if 'groups' not in params:
            params['groups'] = {}
        params['groups']['add'] = conn.groups_add
    if hasattr(conn, 'groups_remove'):
        if 'groups' not in params:
            params['groups'] = {}
        params['groups']['remove'] = conn.groups_remove
    if hasattr(conn, 'keywords_set'):
        if 'keywords' not in params:
            params['keywords'] = {}
        params['keywords']['set'] = conn.keywords_set
    if hasattr(conn, 'op_sys'):
        params['op_sys'] = conn.op_sys
    if hasattr(conn, 'platform'):
        params['platform'] = conn.platform
    if hasattr(conn, 'priority'):
        params['priority'] = conn.priority
    if hasattr(conn, 'product'):
        params['product'] = conn.product
    if hasattr(conn, 'resolution'):
        if not hasattr(conn, 'dupe_of'):
            params['resolution'] = conn.resolution
    if hasattr(conn, 'see_also_add'):
        if 'see_also' not in params:
            params['see_also'] = {}
        params['see_also']['add'] = conn.see_also_add
    if hasattr(conn, 'see_also_remove'):
        if 'see_also' not in params:
            params['see_also'] = {}
        params['see_also']['remove'] = conn.see_also_remove
    if hasattr(conn, 'severity'):
        params['severity'] = conn.severity
    if hasattr(conn, 'status'):
        if not hasattr(conn, 'dupe_of'):
            params['status'] = conn.status
    if hasattr(conn, 'summary'):
        params['summary'] = conn.summary
    if hasattr(conn, 'url'):
        params['url'] = conn.url
    if hasattr(conn, 'version'):
        params['version'] = conn.version
    if hasattr(conn, 'whiteboard'):
        params['whiteboard'] = conn.whiteboard

    if hasattr(conn, 'fixed'):
        params['status'] = 'RESOLVED'
        params['resolution'] = 'FIXED'

    if hasattr(conn, 'invalid'):
        params['status'] = 'RESOLVED'
        params['resolution'] = 'INVALID'

    if len(params) < 2:
        raise BugzError('No changes were specified')
    login(conn)
    result = conn.call_bz(conn.bz.Bug.update, params)
    for bug in result['bugs']:
        changes = bug['changes']
        if not len(changes):
            log_info('Added comment to bug %s' % bug['id'])
        else:
            log_info('Modified the following fields in bug %s' % bug['id'])
            for key in changes:
                log_info('%-12s: removed %s' % (key, changes[key]['removed']))
                log_info('%-12s: added %s' % (key, changes[key]['added']))
Beispiel #54
0
def post(settings):
    """Post a new bug"""
    login(settings)
    # load description from file if possible
    if hasattr(settings, 'description_from'):
        try:
            if settings.description_from == '-':
                settings.description = sys.stdin.read()
            else:
                settings.description = \
                    open(settings.description_from, 'r').read()
        except IOError as error:
            raise BugzError('Unable to read from file: %s: %s' %
                            (settings.description_from, error))

    if not hasattr(settings, 'batch') and not hasattr(settings, 'template'):
        prompt_for_bug(settings)

    params = {}

    if hasattr(settings, 'template'):

        tmpl = configparser.ConfigParser()

        try:
            tmpl.read(settings.template)
            msection = tmpl['Default']['type']
            for key in tmpl[msection]:
                params[key] = tmpl[msection][key]
                print('%-12s: %s' % (key, params[key]))
        except configparser.DuplicateOptionError as error:
            log_error(error)
            sys.exit(1)
        except configparser.DuplicateSectionError as error:
            log_error(error)
            sys.exit(1)
        except configparser.MissingSectionHeaderError as error:
            log_error(error)
            sys.exit(1)
        except configparser.ParsingError as error:
            log_error(error)
            sys.exit(1)
    else:
        # raise an exception if mandatory fields are not specified.
        if not hasattr(settings, 'product'):
            raise RuntimeError('Product not specified')
        if not hasattr(settings, 'component'):
            raise RuntimeError('Component not specified')
        if not hasattr(settings, 'summary'):
            raise RuntimeError('Title not specified')
        if not hasattr(settings, 'description'):
            raise RuntimeError('Description not specified')
        print('-' * (settings.columns - 1))
        print('%-12s: %s' % ('Product', settings.product))
        print('%-12s: %s' % ('Component', settings.component))
        print('%-12s: %s' % ('Title', settings.summary))
        if hasattr(settings, 'version'):
            print('%-12s: %s' % ('Version', settings.version))
        print('%-12s: %s' % ('Description', settings.description))
        if hasattr(settings, 'op_sys'):
            print('%-12s: %s' % ('Operating System', settings.op_sys))
        if hasattr(settings, 'platform'):
            print('%-12s: %s' % ('Platform', settings.platform))
        if hasattr(settings, 'priority'):
            print('%-12s: %s' % ('Priority', settings.priority))
        if hasattr(settings, 'severity'):
            print('%-12s: %s' % ('Severity', settings.severity))
        if hasattr(settings, 'alias'):
            print('%-12s: %s' % ('Alias', settings.alias))
        if hasattr(settings, 'assigned_to'):
            print('%-12s: %s' % ('Assigned to', settings.assigned_to))
        if hasattr(settings, 'cc'):
            print('%-12s: %s' % ('CC', settings.cc))
        if hasattr(settings, 'url'):
            print('%-12s: %s' % ('URL', settings.url))
        print('-' * (settings.columns - 1))
        params['product'] = settings.product
        params['component'] = settings.component
        if hasattr(settings, 'version'):
            params['version'] = settings.version
        params['summary'] = settings.summary
        if hasattr(settings, 'description'):
            params['description'] = settings.description
        if hasattr(settings, 'op_sys'):
            params['op_sys'] = settings.op_sys
        if hasattr(settings, 'platform'):
            params['platform'] = settings.platform
        if hasattr(settings, 'priority'):
            params['priority'] = settings.priority
        if hasattr(settings, 'severity'):
            params['severity'] = settings.severity
        if hasattr(settings, 'alias'):
            params['alias'] = settings.alias
        if hasattr(settings, 'assigned_to'):
            params['assigned_to'] = settings.assigned_to
        if hasattr(settings, 'cc'):
            params['cc'] = settings.cc
        if hasattr(settings, 'url'):
            params['url'] = settings.url

    # append the output from append_command to the description
    append_command = getattr(settings, 'append_command', None)
    if append_command is not None and append_command != '':
        append_command_output = subprocess.getoutput(append_command)
        settings.description = settings.description + '\n\n' + \
            '$ ' + append_command + '\n' + \
            append_command_output

    if not hasattr(settings, 'batch'):
        if settings.default_confirm in ['Y', 'y']:
            confirm = input('Confirm bug submission (Y/n)? ')
        else:
            confirm = input('Confirm bug submission (y/N)? ')
        if len(confirm) < 1:
            confirm = settings.default_confirm
        if confirm[0] not in ('y', 'Y'):
            log_info('Submission aborted')
            return

    result = settings.call_bz(settings.bz.Bug.create, params)
    log_info('Bug %d submitted' % result['id'])
Beispiel #55
0
def modify(settings):
    """Modify an existing bug (eg. adding a comment or changing resolution.)"""
    if hasattr(settings, 'comment_from'):
        try:
            if settings.comment_from == '-':
                settings.comment = sys.stdin.read()
            else:
                settings.comment = open(settings.comment_from, 'r').read()
        except IOError as error:
            raise BugzError('unable to read file: %s: %s' %
                            (settings.comment_from, error))

    if hasattr(settings, 'assigned_to') and \
            hasattr(settings, 'reset_assigned_to'):
        raise BugzError('--assigned-to and --unassign cannot be used together')

    if hasattr(settings, 'comment_editor'):
        settings.comment = block_edit('Enter comment:')

    params = {}
    params['ids'] = [settings.bugid]
    if hasattr(settings, 'alias'):
        params['alias'] = settings.alias
    if hasattr(settings, 'assigned_to'):
        params['assigned_to'] = settings.assigned_to
    if hasattr(settings, 'blocks_add'):
        if 'blocks' not in params:
            params['blocks'] = {}
        params['blocks']['add'] = settings.blocks_add
    if hasattr(settings, 'blocks_remove'):
        if 'blocks' not in params:
            params['blocks'] = {}
        params['blocks']['remove'] = settings.blocks_remove
    if hasattr(settings, 'depends_on_add'):
        if 'depends_on' not in params:
            params['depends_on'] = {}
        params['depends_on']['add'] = settings.depends_on_add
    if hasattr(settings, 'depends_on_remove'):
        if 'depends_on' not in params:
            params['depends_on'] = {}
        params['depends_on']['remove'] = settings.depends_on_remove
    if hasattr(settings, 'cc_add'):
        if 'cc' not in params:
            params['cc'] = {}
        params['cc']['add'] = settings.cc_add
    if hasattr(settings, 'cc_remove'):
        if 'cc' not in params:
            params['cc'] = {}
        params['cc']['remove'] = settings.cc_remove
    if hasattr(settings, 'comment'):
        if 'comment' not in params:
            params['comment'] = {}
        params['comment']['body'] = settings.comment
    if hasattr(settings, 'component'):
        params['component'] = settings.component
    if hasattr(settings, 'dupe_of'):
        params['dupe_of'] = settings.dupe_of
    if hasattr(settings, 'deadline'):
        params['deadline'] = settings.deadline
    if hasattr(settings, 'estimated_time'):
        params['estimated_time'] = settings.estimated_time
    if hasattr(settings, 'remaining_time'):
        params['remaining_time'] = settings.remaining_time
    if hasattr(settings, 'work_time'):
        params['work_time'] = settings.work_time
    if hasattr(settings, 'groups_add'):
        if 'groups' not in params:
            params['groups'] = {}
        params['groups']['add'] = settings.groups_add
    if hasattr(settings, 'groups_remove'):
        if 'groups' not in params:
            params['groups'] = {}
        params['groups']['remove'] = settings.groups_remove
    if hasattr(settings, 'keywords_set'):
        if 'keywords' not in params:
            params['keywords'] = {}
        params['keywords']['set'] = settings.keywords_set
    if hasattr(settings, 'op_sys'):
        params['op_sys'] = settings.op_sys
    if hasattr(settings, 'platform'):
        params['platform'] = settings.platform
    if hasattr(settings, 'priority'):
        params['priority'] = settings.priority
    if hasattr(settings, 'product'):
        params['product'] = settings.product
    if hasattr(settings, 'resolution'):
        if not hasattr(settings, 'dupe_of'):
            params['resolution'] = settings.resolution
    if hasattr(settings, 'see_also_add'):
        if 'see_also' not in params:
            params['see_also'] = {}
        params['see_also']['add'] = settings.see_also_add
    if hasattr(settings, 'see_also_remove'):
        if 'see_also' not in params:
            params['see_also'] = {}
        params['see_also']['remove'] = settings.see_also_remove
    if hasattr(settings, 'severity'):
        params['severity'] = settings.severity
    if hasattr(settings, 'status'):
        if not hasattr(settings, 'dupe_of'):
            params['status'] = settings.status
    if hasattr(settings, 'summary'):
        params['summary'] = settings.summary
    if hasattr(settings, 'url'):
        params['url'] = settings.url
    if hasattr(settings, 'version'):
        params['version'] = settings.version
    if hasattr(settings, 'whiteboard'):
        params['whiteboard'] = settings.whiteboard
    if hasattr(settings, 'custom'):
        custom_options = settings.custom.split(':')
        for custom_option in custom_options:
            try:
                key, value = custom_option.split('=', 1)
                params[key] = value
            except:
                print("Badly formatted option :{}".format(custom_option))
                pass

    if hasattr(settings, 'fixed'):
        params['status'] = 'RESOLVED'
        params['resolution'] = 'FIXED'

    if hasattr(settings, 'invalid'):
        params['status'] = 'RESOLVED'
        params['resolution'] = 'INVALID'

    if len(params) < 2:
        raise BugzError('No changes were specified')
    login(settings)
    result = settings.call_bz(settings.bz.Bug.update, params)
    for bug in result['bugs']:
        changes = bug['changes']
        if not len(changes):
            log_info('Added comment to bug %s' % bug['id'])
        else:
            log_info('Modified the following fields in bug %s' % bug['id'])
            for key in changes:
                log_info('%-12s: removed %s' % (key, changes[key]['removed']))
                log_info('%-12s: added %s' % (key, changes[key]['added']))
Beispiel #56
0
def post(settings):
    """Post a new bug"""
    login(settings)
    # load description from file if possible
    if hasattr(settings, 'description_from'):
        try:
            if settings.description_from == '-':
                settings.description = sys.stdin.read()
            else:
                settings.description = open(settings.description_from,
                                            'r').read()
        except IOError as error:
            raise BugzError('Unable to read from file: %s: %s' %
                            (settings.description_from, error))

    if not hasattr(settings, 'batch'):
        prompt_for_bug(settings)

    # raise an exception if mandatory fields are not specified.
    if not hasattr(settings, 'product'):
        raise RuntimeError('Product not specified')
    if not hasattr(settings, 'component'):
        raise RuntimeError('Component not specified')
    if not hasattr(settings, 'summary'):
        raise RuntimeError('Title not specified')
    if not hasattr(settings, 'description'):
        raise RuntimeError('Description not specified')

    # append the output from append_command to the description
    append_command = getattr(settings, 'append_command', None)
    if append_command is not None and append_command != '':
        append_command_output = subprocess.getoutput(append_command)
        settings.description = settings.description + '\n\n' + \
            '$ ' + append_command + '\n' + \
            append_command_output

    # print submission confirmation
    write('-' * (settings.columns - 1))
    write('%-12s: %s' % ('Product', settings.product))
    write('%-12s: %s' % ('Component', settings.component))
    write('%-12s: %s' % ('Title', settings.summary))
    if hasattr(settings, 'version'):
        write('%-12s: %s' % ('Version', settings.version))
    write('%-12s: %s' % ('Description', settings.description))
    if hasattr(settings, 'op_sys'):
        write('%-12s: %s' % ('Operating System', settings.op_sys))
    if hasattr(settings, 'platform'):
        write('%-12s: %s' % ('Platform', settings.platform))
    if hasattr(settings, 'priority'):
        write('%-12s: %s' % ('Priority', settings.priority))
    if hasattr(settings, 'severity'):
        write('%-12s: %s' % ('Severity', settings.severity))
    if hasattr(settings, 'alias'):
        write('%-12s: %s' % ('Alias', settings.alias))
    if hasattr(settings, 'assigned_to'):
        write('%-12s: %s' % ('Assigned to', settings.assigned_to))
    if hasattr(settings, 'cc'):
        write('%-12s: %s' % ('CC', settings.cc))
    if hasattr(settings, 'url'):
        write('%-12s: %s' % ('URL', settings.url))
    # fixme: groups
    # fixme: status
    # fixme: Milestone
    write('-' * (settings.columns - 1))

    if not hasattr(settings, 'batch'):
        if settings.default_confirm in ['Y', 'y']:
            confirm = input('Confirm bug submission (Y/n)? ')
        else:
            confirm = input('Confirm bug submission (y/N)? ')
        if len(confirm) < 1:
            confirm = settings.default_confirm
        if confirm[0] not in ('y', 'Y'):
            log_info('Submission aborted')
            return

    params = {}
    params['product'] = settings.product
    params['component'] = settings.component
    if hasattr(settings, 'version'):
        params['version'] = settings.version
    params['summary'] = settings.summary
    if hasattr(settings, 'description'):
        params['description'] = settings.description
    if hasattr(settings, 'op_sys'):
        params['op_sys'] = settings.op_sys
    if hasattr(settings, 'platform'):
        params['platform'] = settings.platform
    if hasattr(settings, 'priority'):
        params['priority'] = settings.priority
    if hasattr(settings, 'severity'):
        params['severity'] = settings.severity
    if hasattr(settings, 'alias'):
        params['alias'] = settings.alias
    if hasattr(settings, 'assigned_to'):
        params['assigned_to'] = settings.assigned_to
    if hasattr(settings, 'cc'):
        params['cc'] = settings.cc
    if hasattr(settings, 'url'):
        params['url'] = settings.url

    result = settings.call_bz(settings.bz.Bug.create, params)
    log_info('Bug %d submitted' % result['id'])
Beispiel #57
0
def logout(settings):
    settings.load_token()
    params = {}
    log_info('logging out')
    settings.call_bz(settings.bz.User.logout, params)
    settings.destroy_token()
Beispiel #58
0
def prompt_for_bug(settings):
    """ Prompt for the information for a bug
    """
    log_info('Press Ctrl+C at any time to abort.')

    if not hasattr(settings, 'product'):
        product = None
        while not product or len(product) < 1:
            product = input('Enter product: ')
        settings.product = product
    else:
        log_info('Enter product: %s' % settings.product)

    if not hasattr(settings, 'component'):
        component = None
        while not component or len(component) < 1:
            component = input('Enter component: ')
        settings.component = component
    else:
        log_info('Enter component: %s' % settings.component)

    if not hasattr(settings, 'version'):
        line = input('Enter version (default: unspecified): ')
        if len(line):
            settings.version = line
        else:
            settings.version = 'unspecified'
    else:
        log_info('Enter version: %s' % settings.version)

    if not hasattr(settings, 'summary'):
        summary = None
        while not summary or len(summary) < 1:
            summary = input('Enter title: ')
        settings.summary = summary
    else:
        log_info('Enter title: %s' % settings.summary)

    if not hasattr(settings, 'description'):
        line = block_edit('Enter bug description: ')
        if len(line):
            settings.description = line
    else:
        log_info('Enter bug description: %s' % settings.description)

    if not hasattr(settings, 'op_sys'):
        op_sys_msg = 'Enter operating system where this bug occurs: '
        line = input(op_sys_msg)
        if len(line):
            settings.op_sys = line
    else:
        log_info('Enter operating system: %s' % settings.op_sys)

    if not hasattr(settings, 'platform'):
        platform_msg = 'Enter hardware platform where this bug occurs: '
        line = input(platform_msg)
        if len(line):
            settings.platform = line
    else:
        log_info('Enter hardware platform: %s' % settings.platform)

    if not hasattr(settings, 'priority'):
        priority_msg = 'Enter priority (eg. Normal) (optional): '
        line = input(priority_msg)
        if len(line):
            settings.priority = line
    else:
        log_info('Enter priority (optional): %s' % settings.priority)

    if not hasattr(settings, 'severity'):
        severity_msg = 'Enter severity (eg. normal) (optional): '
        line = input(severity_msg)
        if len(line):
            settings.severity = line
    else:
        log_info('Enter severity (optional): %s' % settings.severity)

    if not hasattr(settings, 'alias'):
        alias_msg = 'Enter an alias for this bug (optional): '
        line = input(alias_msg)
        if len(line):
            settings.alias = line
    else:
        log_info('Enter alias (optional): %s' % settings.alias)

    if not hasattr(settings, 'assigned_to'):
        assign_msg = 'Enter assignee (eg. [email protected]) (optional): '
        line = input(assign_msg)
        if len(line):
            settings.assigned_to = line
    else:
        log_info('Enter assignee (optional): %s' % settings.assigned_to)

    if not hasattr(settings, 'cc'):
        cc_msg = 'Enter a CC list (comma separated) (optional): '
        line = input(cc_msg)
        if len(line):
            settings.cc = re.split(r',\s*', line)
    else:
        log_info('Enter a CC list (optional): %s' % settings.cc)

    if not hasattr(settings, 'url'):
        url_msg = 'Enter a URL (optional): '
        line = input(url_msg)
        if len(line):
            settings.url = line
    else:
        log_info('Enter a URL (optional): %s' % settings.url)

    # fixme: groups

    # fixme: status

    # fixme: milestone

    if not hasattr(settings, 'append_command'):
        line = input('Append the output of the'
                     ' following command (leave blank for none): ')
        if len(line):
            settings.append_command = line
    else:
        log_info('Append command (optional): %s' % settings.append_command)
Beispiel #59
0
    def __init__(self, args, config):
        for key in vars(args):
            setattr(self, key, getattr(args, key))

        if not hasattr(self, 'connection'):
            if config.has_option('default', 'connection'):
                self.connection = get_config_option(config.get,
                                                    'default', 'connection')
            else:
                log_error('No default connection specified')
                sys.exit(1)

        if self.connection not in config.sections():
            log_error('connection "{0}" not found'.format(self.connection))
            sys.exit(1)

        if not hasattr(self, 'base'):
            if config.has_option(self.connection, 'base'):
                self.base = get_config_option(config.get,
                                              self.connection, 'base')
            else:
                log_error('No base URL specified')
                sys.exit(1)

        if not hasattr(self, 'component'):
            if config.has_option(self.connection, 'component'):
                self.component = get_config_option(config.get,
                                                   self.connection,
                                                   'component')

        if not hasattr(self, 'user'):
            if config.has_option(self.connection, 'user'):
                self.user = get_config_option(config.get,
                                              self.connection, 'user')

        if not hasattr(self, 'password'):
            if config.has_option(self.connection, 'password'):
                self.password = get_config_option(config.get,
                                                  self.connection, 'password')

        if not hasattr(self, 'passwordcmd'):
            if config.has_option(self.connection, 'passwordcmd'):
                self.passwordcmd = get_config_option(config.get,
                                                     self.connection,
                                                     'passwordcmd')

        if not hasattr(self, 'key'):
            if config.has_option(self.connection, 'key'):
                self.key = get_config_option(config.get,
                                             self.connection,
                                             'key')

        if not hasattr(self, 'product'):
            if config.has_option(self.connection, 'product'):
                self.product = get_config_option(config.get,
                                                 self.connection, 'product')

        if not hasattr(self, 'columns'):
            if config.has_option(self.connection, 'columns'):
                self.columns = get_config_option(config.getint,
                                                 self.connection, 'columns')
            else:
                self.columns = terminal_width()

        if not hasattr(self, 'debug'):
            if config.has_option(self.connection, 'debug'):
                self.debug = get_config_option(config.getint,
                                               self.connection, 'debug')
            else:
                self.debug = 0
        log_setDebugLevel(self.debug)

        if not hasattr(self, 'quiet'):
            if config.has_option(self.connection, 'quiet'):
                self.quiet = get_config_option(config.getboolean,
                                               self.connection, 'quiet')
            else:
                self.quiet = False
        log_setQuiet(self.quiet)

        if not hasattr(self, 'search_statuses'):
            if config.has_option(self.connection, 'search_statuses'):
                s = get_config_option(config.get, self.connection,
                        'search_statuses')
                self.search_statuses = [x.strip() for x in s.split(',')]

        if not hasattr(self, 'skip_auth'):
            if config.has_option(self.connection, 'skip_auth'):
                self.skip_auth = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'skip_auth')
            else:
                self.skip_auth = False

        if not hasattr(self, 'interactive'):
            if config.has_option(self.connection, 'interactive'):
                self.interactive = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'interactive')
            else:
                self.interactive = False

        if not hasattr(self, 'insecure'):
            if config.has_option(self.connection, 'insecure'):
                self.insecure = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'insecure')
            else:
                self.insecure = False

        if getattr(self, 'encoding', None) is not None:
            log_info('The encoding option is deprecated.')

        if self.insecure:
            context=ssl._create_unverified_context()
        else:
            context = None

        self.bz = xmlrpc.client.ServerProxy(self.base, context=context)
        self.connections = config.sections()

        parse_result = urllib.parse.urlparse(self.base)
        new_netloc = parse_result.netloc.split('@')[-1]
        self.safe_base = parse_result._replace(netloc=new_netloc).geturl()
        log_info("Using [{0}] ({1})".format(self.connection, self.safe_base))

        log_debug('Command line debug dump:', 3)
        for key in vars(args):
            log_debug('{0}, {1}'.format(key, getattr(args, key)), 3)

        log_debug('Settings debug dump:', 3)
        for key in vars(self):
            log_debug('{0}, {1}'.format(key, getattr(self, key)), 3)
Beispiel #60
0
    def __init__(self, args, config):
        for key in vars(args):
            setattr(self, key, getattr(args, key))

        if not hasattr(self, 'connection'):
            if config.has_option('default', 'connection'):
                self.connection = get_config_option(config.get, 'default',
                                                    'connection')
            else:
                log_error('No default connection specified')
                sys.exit(1)

        if self.connection not in config.sections():
            log_error('connection "{0}" not found'.format(self.connection))
            sys.exit(1)

        if not hasattr(self, 'base'):
            if config.has_option(self.connection, 'base'):
                self.base = get_config_option(config.get, self.connection,
                                              'base')
            else:
                log_error('No base URL specified')
                sys.exit(1)

        if not hasattr(self, 'component'):
            if config.has_option(self.connection, 'component'):
                self.component = get_config_option(config.get, self.connection,
                                                   'component')

        if not hasattr(self, 'user'):
            if config.has_option(self.connection, 'user'):
                self.user = get_config_option(config.get, self.connection,
                                              'user')

        if not hasattr(self, 'password'):
            if config.has_option(self.connection, 'password'):
                self.password = get_config_option(config.get, self.connection,
                                                  'password')

        if not hasattr(self, 'passwordcmd'):
            if config.has_option(self.connection, 'passwordcmd'):
                self.passwordcmd = get_config_option(config.get,
                                                     self.connection,
                                                     'passwordcmd')

        if not hasattr(self, 'product'):
            if config.has_option(self.connection, 'product'):
                self.product = get_config_option(config.get, self.connection,
                                                 'product')

        if not hasattr(self, 'columns'):
            if config.has_option(self.connection, 'columns'):
                self.columns = get_config_option(config.getint,
                                                 self.connection, 'columns')
            else:
                self.columns = terminal_width()

        if not hasattr(self, 'debug'):
            if config.has_option(self.connection, 'debug'):
                self.debug = get_config_option(config.getint, self.connection,
                                               'debug')
            else:
                self.debug = 0
        log_setDebugLevel(self.debug)

        if not hasattr(self, 'quiet'):
            if config.has_option(self.connection, 'quiet'):
                self.quiet = get_config_option(config.getboolean,
                                               self.connection, 'quiet')
            else:
                self.quiet = False
        log_setQuiet(self.quiet)

        if config.has_option(self.connection, 'search_statuses'):
            self.search_statuses = get_config_option(
                config.get, self.connection, 'search_statuses').split()

        if not hasattr(self, 'skip_auth'):
            if config.has_option(self.connection, 'skip_auth'):
                self.skip_auth = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'skip_auth')
            else:
                self.skip_auth = False

        if getattr(self, 'encoding', None) is not None:
            log_info('The encoding option is deprecated.')

        self.bz = xmlrpc.client.ServerProxy(self.base)
        self.connections = config.sections()

        parse_result = urllib.parse.urlparse(self.base)
        new_netloc = parse_result.netloc.split('@')[-1]
        self.safe_base = parse_result._replace(netloc=new_netloc).geturl()
        self.tokens = Tokens()
        self.bz_token = None

        old_token_file = os.path.join(os.environ['HOME'], '.bugz_token')
        try:
            old_token = open(old_token_file).read().strip()
            self.save_token(old_token)
            os.remove(old_token_file)
            print('Your ~/.bugz_token file was moved to ~/.bugz_tokens')
            print('The token was assigned to the {0} connection'.format(
                self.connection))
            print('If this is not correct, please edit ~/.bugz_tokens')
            print('and adjust the name of the connection.')
            print('This is the name enclosed in square brackets.')
            print('The connections command lists known connections.')
        except (IOError, OSError):
            pass

        log_info("Using [{0}] ({1})".format(self.connection, self.safe_base))

        log_debug('Command line debug dump:', 3)
        for key in vars(args):
            log_debug('{0}, {1}'.format(key, getattr(args, key)), 3)

        log_debug('Connection debug dump:', 3)
        for key in vars(self):
            log_debug('{0}, {1}'.format(key, getattr(self, key)), 3)