Example #1
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))
Example #2
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))
Example #3
0
File: cli.py Project: CMB/pybugz
	def attach(self, conn):
		""" Attach a file to a bug given a filename. """
		filename = conn.filename
		content_type = conn.content_type
		bugid = conn.bugid
		summary = conn.summary
		is_patch = conn.is_patch
		comment = conn.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'] = xmlrpc.client.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.call_bz(self.bz.Bug.add_attachment, params)
		log_info("'%s' has been attached to bug %s" % (filename, bugid))
Example #4
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']))
Example #5
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)
Example #6
0
File: cli.py Project: CMB/pybugz
	def modify(self, conn):
		"""Modify an existing bug (eg. adding a comment or changing resolution.)"""
		if getattr(conn, 'comment_from', None) is not None:
			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 conn.comment_editor:
			conn.comment = block_edit('Enter comment:')

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

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

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

		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']))
Example #7
0
File: cli.py Project: CMB/pybugz
	def post(self, conn):
		"""Post a new bug"""

		# load description from file if possible
		if getattr(conn, 'description_from', None) is not None:
			try:
					if conn.description_from == '-':
						conn.description = sys.stdin.read()
					else:
						conn.description = open(conn.description_from, 'r').read()
			except IOError as e:
				raise BugzError('Unable to read from file: %s: %s' %
					(conn.description_from, e))

		if not conn.batch:
			log_info('Press Ctrl+C at any time to abort.')

			#  Check all bug fields.
			#

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

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

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

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

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

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

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

			# check for default priority
			if not hasattr(conn, 'priority'):
				priority_msg = 'Enter priority (eg. Normal) (optional): '
				line = input(priority_msg)
				if len(line):
					conn.priority = line
			else:
				log_info('Enter priority (optional): %s' % conn.priority)

			# check for default severity
			if not hasattr(conn, 'severity'):
				severity_msg = 'Enter severity (eg. normal) (optional): '
				line = input(severity_msg)
				if len(line):
					conn.severity = line
			else:
				log_info('Enter severity (optional): %s' % conn.severity)

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

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

			# check for CC list
			if not hasattr(conn, 'cc'):
				cc_msg = 'Enter a CC list (comma separated) (optional): '
				line = input(cc_msg)
				if len(line):
					conn.cc = line.split(', ')
			else:
				log_info('Enter a CC list (optional): %s' % conn.cc)

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

			# fixme: groups

			# fixme: status

			# fixme: milestone

			if not hasattr(conn, 'append_command'):
				line = input('Append the output of the'
				' following command (leave blank for none): ')
				if len(line):
					conn.append_command = line
			else:
				log_info('Append command (optional): %s' % conn.append_command)

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

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

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

		if not getattr(conn, 'batch', None):
			if conn.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 = conn.default_confirm
			if confirm[0] not in ('y', 'Y'):
				log_info('Submission aborted')
				return

		params = {}
		params['product'] = conn.product
		params['component'] = conn.component
		params['version'] = conn.version
		params['summary'] = conn.summary
		if getattr(conn, 'description', None) is not None:
			params['description'] = conn.description
		if getattr(conn, 'op_sys', None) is not None:
			params['op_sys'] = conn.op_sys
		if getattr(conn, 'platform', None) is not None:
			params['platform'] = conn.platform
		if getattr(conn, 'priority', None) is not None:
			params['priority'] = conn.priority
		if getattr(conn, 'severity', None) is not None:
			params['severity'] = conn.severity
		if getattr(conn, 'alias', None) is not None:
			params['alias'] = conn.alias
		if getattr(conn, 'assigned_to', None) is not None:
			params['assigned_to'] = conn.assigned_to
		if getattr(conn, 'cc', None) is not None:
			params['cc'] = conn.cc
		if getattr(conn, 'url', None) is not None:
			params['url'] = conn.url

		result = self.call_bz(self.bz.Bug.create, params)
		log_info('Bug %d submitted' % result['id'])
Example #8
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, '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')
    check_auth(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']))
Example #9
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)
Example #10
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']))