def pkginfo_for_unpacked(path): with open(path + '/debian/changelog', 'r', encoding='UTF-8') as file: for line in file: break match = re.match(r'^(\S+) [(]([^)]+)[)]', line) if match is None: raise ValueError (source, version) = match.groups() if not deblogic.is_package_name(source): raise ValueError if not deblogic.is_package_version(version): raise ValueError return (source, version)
def pkginfo_for_deb(path): info = utils.xcmd('dpkg-deb', '-f', path, 'Package', 'Version', 'Architecture') info = info.decode('UTF-8') match = re.match( r'\A' r'Package:\s*(\S+)\n' r'Version:\s*(\S+)\n' r'Architecture:\s*(\S+)\n' r'\Z', info) if match is None: raise ValueError (package, version, architecture) = match.groups() if not deblogic.is_package_name(package): raise ValueError if not deblogic.is_package_version(version): raise ValueError if not deblogic.is_architecture(architecture): raise ValueError return (package, version, architecture)
def pkginfo_for_dsc(path): source = None version = None with open(path, 'r', encoding='UTF-8') as file: for line in file: match = re.match(r'^(?:(source)|(version)):\s*(\S+)$', line, re.IGNORECASE) if not match: continue if match.group(1) is not None: source = match.group(3) else: version = match.group(3) if source and version: break if source and version: if not deblogic.is_package_name(source): raise ValueError if not deblogic.is_package_version(version): raise ValueError return (source, version) else: raise ValueError
def run(options): debsoap_client = debsoap.Client(session=options.session) queries = [] for selection in options.selections: bugno = None try: bugno = deblogic.parse_bugspec(selection) except ValueError: pass if bugno is not None: queries += [bugno] elif ':' in selection: selector, value = selection.split(':', 1) selector = selectors[selector] if callable(selector): queries += selector(value) else: queries += [{selector: value}] elif deblogic.is_package_name(selection): queries += [dict(package=selection)] else: path = selection try: os.stat(path) except OSError: options.error('{0!r} is not a valid package name'.format(selection)) if os.path.isdir(path): queries += select_for_unpacked(path) elif path.endswith('.deb'): queries += select_for_deb(path) elif path.endswith('.dsc'): queries += select_for_dsc(path) else: options.error('{0!r} is not a valid package name'.format(selection)) bugs = debsoap_client.get_bugs(*queries) bugs = sorted(bugs, key=(lambda bug: -bug.id)) for bug in bugs: package = bug.package subject = bug.subject or '' default_severity = 'normal' if package == 'wnpp': for wnpp_tag in deblogic.wnpp_tags: if subject.startswith(wnpp_tag + ': '): if wnpp_tag[-1] == 'P': default_severity = 'wishlist' package = None break elif package == 'sponsorship-requests': if subject.startswith('RFS:'): package = None template = '' source = None subject_color = '{t.green}' if bug.done else '{t.bold}' if package is not None: if package.startswith('src:'): source = package[4:] new_subject = strip_package_prefix(subject, source) if subject != new_subject: subject = new_subject template += '[src:' + subject_color + '{src}{t.off}] ' else: template += '[src:{src}] ' else: new_subject = strip_package_prefix(subject, package) if subject != new_subject: subject = new_subject template += '[' + subject_color + '{pkg}{t.off}] ' else: template += '[{pkg}] ' if subject: template += subject_color + '{subject}{t.off}' else: template += '{t.red}(no subject){t.off}' colorterm.print(template, pkg=package, src=source, subject=subject, ) indent = ' ' template = indent + '{t.cyan}https://bugs.debian.org/{n}{t.off}' if bug.forwarded: template += ' -> {t.cyan}{forwarded}{t.off}' colorterm.print(template, n=bug.id, forwarded=bug.forwarded) template = indent + '{user}; {date}-00:00' user = bug.submitter if package == 'wnpp' and bug.owner is not None: user = bug.owner colorterm.print(template, user=user, date=bug.date, ) template = '' if bug.severity != default_severity: severity_color = ( '{t.bold}{t.red}' if bug.severity in deblogic.rc_severities else '' ) template = severity_color + '{severity}{t.off}' if bug.tags: if template: template += ' ' template += '{tags}' if template: template = indent + template colorterm.print(template, tags=' '.join('+' + t for t in bug.tags), severity=bug.severity, ) template = '' if bug.found_versions: template = 'found in {found}' if bug.fixed_versions: if template: template += '; ' template += 'fixed in {fixed}' if template: template = indent + template colorterm.print(template, found=', '.join(bug.found_versions), fixed=', '.join(bug.fixed_versions), ) print()
def run(options): utils.reset_SIGPIPE() debsoap_client = debsoap.Client(session=options.session) queries = [] for selection in options.selections: bugno = None try: bugno = deblogic.parse_bugspec(selection) except ValueError: pass if bugno is not None: queries += [bugno] elif utils.looks_like_path(selection): path = selection try: os.stat(path) except OSError: options.error('{0!r} is not a package'.format(path)) if os.path.isdir(path + '/debian'): queries += select_for_unpacked(path) elif path.endswith('.dsc'): queries += select_for_dsc(path) elif path.endswith('.deb'): queries += select_for_deb(path) else: options.error('{0!r} is not a package'.format(path)) elif ':' in selection: selector, value = selection.split(':', 1) try: selector = selectors[selector] except KeyError: options.error('{0!r} is not a valid selector'.format(selector)) if callable(selector): queries += selector(value) else: queries += [{selector: value}] elif deblogic.is_package_name(selection): queries += [dict(package=selection)] else: options.error( '{0!r} is not a valid package name'.format(selection)) bugs = debsoap_client.get_bugs(*queries) bugs = sorted(bugs, key=(lambda bug: -bug.id)) for bug in bugs: package = bug.package subject = bug.subject or '' default_severity = 'normal' if package == 'wnpp': for wnpp_tag in deblogic.wnpp_tags: if subject.startswith(wnpp_tag + ': '): if wnpp_tag[-1] == 'P': default_severity = 'wishlist' package = None break elif package == 'sponsorship-requests': if subject.startswith('RFS:'): package = None template = '' source = None subject_color = '{t.green}' if bug.done else '{t.bold}' if package is not None: if package.startswith('src:'): source = package[4:] new_subject = strip_package_prefix(subject, source) if subject != new_subject: subject = new_subject template += '[src:' + subject_color + '{src}{t.off}] ' else: template += '[src:{src}] ' else: new_subject = strip_package_prefix(subject, package) if subject != new_subject: subject = new_subject template += '[' + subject_color + '{pkg}{t.off}] ' else: template += '[{pkg}] ' if subject: template += subject_color + '{subject}{t.off}' else: template += '{t.red}(no subject){t.off}' colorterm.print( template, pkg=package, src=source, subject=subject, ) indent = ' ' template = indent + '{t.cyan}https://bugs.debian.org/{n}{t.off}' if bug.forwarded: template += ' -> {t.cyan}{forwarded}{t.off}' colorterm.print(template, n=bug.id, forwarded=bug.forwarded) template = indent + '{user}; {date}-00:00' user = bug.submitter if package == 'wnpp' and bug.owner is not None: user = bug.owner colorterm.print( template, user=user, date=bug.date, ) template = '' if bug.severity != default_severity: severity_color = ('{t.bold}{t.red}' if bug.severity in deblogic.rc_severities else '') template = severity_color + '{severity}{t.off}' if bug.tags: if template: template += ' ' template += '{tags}' if template: template = indent + template colorterm.print( template, tags=' '.join('+' + t for t in bug.tags), severity=bug.severity, ) template = '' if bug.found_versions: template = 'found in {found}' if bug.fixed_versions: if template: template += '; ' template += 'fixed in {fixed}' if template: template = indent + template colorterm.print( template, found=', '.join(bug.found_versions), fixed=', '.join(bug.fixed_versions), ) print()
def f(self, s): ok = M.is_package_name(s) assert_false(ok)
def t(self, s): ok = M.is_package_name(s) assert_true(ok)