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))
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))
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))