contrib/bzutil: print list of excluded bugs from --no-bz

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-02-26 18:24:08 +01:00
parent de3985a0ce
commit d27c81961e

View file

@ -12,6 +12,7 @@ import termcolor
from sets import Set from sets import Set
import ast import ast
import datetime import datetime
import itertools
devnull = open(os.devnull, 'w') devnull = open(os.devnull, 'w')
@ -365,7 +366,7 @@ class BzInfo:
def __hash__(self): def __hash__(self):
return hash( (self.bztype, self.bzid) ) return hash( (self.bztype, self.bzid) )
def __str__(self): def __str__(self):
return "%s #%s" % (self.bztype, self.bzid) return "%s#%s" % (self.bztype, self.bzid)
def __repr__(self): def __repr__(self):
return "(\"%s\", \"%s\")" % (self.bztype, self.bzid) return "(\"%s\", \"%s\")" % (self.bztype, self.bzid)
@ -546,6 +547,7 @@ class UtilParseCommitMessage:
if self._result is None and self._git_backend: if self._result is None and self._git_backend:
message = git_commit_message(self.commit) message = git_commit_message(self.commit)
data = [] data = []
no_bz_skipped = []
while message: while message:
match = None; match = None;
@ -567,6 +569,8 @@ class UtilParseCommitMessage:
if m: if m:
if self._no_bz is None or m not in self._no_bz: if self._no_bz is None or m not in self._no_bz:
data.append(m) data.append(m)
else:
no_bz_skipped.append(m)
# remove everything before the end of the match 'replace' group. # remove everything before the end of the match 'replace' group.
group = match.group('replace') group = match.group('replace')
@ -574,7 +578,14 @@ class UtilParseCommitMessage:
message = message[match.end('replace'):]; message = message[match.end('replace'):];
self._result = list(set(data)) self._result = list(set(data))
self._no_bz_skipped = list(set(no_bz_skipped))
return self._result return self._result
@property
def no_bz_skipped(self):
r = self.result
if not hasattr(self, "_no_bz_skipped"):
self._no_bz_skipped = []
return self._no_bz_skipped
def filter_out(self, filter): def filter_out(self, filter):
res = [] res = []
@ -904,6 +915,7 @@ class CmdParseCommitMessage(CmdBase):
def _parse_bz(self, obz, no_bz): def _parse_bz(self, obz, no_bz):
bz_tuples = [bz for bz in re.split('[,; ]', obz) if bz] bz_tuples = [bz for bz in re.split('[,; ]', obz) if bz]
result_man2 = [] result_man2 = []
no_bz_skipped = []
has_any = False has_any = False
for bzii in bz_tuples: for bzii in bz_tuples:
bzi = bzii.partition(':') bzi = bzii.partition(':')
@ -924,39 +936,48 @@ class CmdParseCommitMessage(CmdBase):
raise Exception('invalid bug specifier \"%s\"' % obz) raise Exception('invalid bug specifier \"%s\"' % obz)
if no_bz is None or bz not in no_bz: if no_bz is None or bz not in no_bz:
result_man2.append(bz) result_man2.append(bz)
else:
no_bz_skipped.append(bz)
has_any = True has_any = True
if not has_any: if not has_any:
raise Exception('invalid bug specifier \"%s\": contains no bugs' % obz) raise Exception('invalid bug specifier \"%s\": contains no bugs' % obz)
return result_man2 return result_man2, no_bz_skipped
def _parse_bzlist(self, bzlist, no_bz=None): def _parse_bzlist(self, bzlist, no_bz=None):
i = 0 i = 0
result_man = [] result_man = []
no_bz_skipped = []
for obz in (bzlist if bzlist else []): for obz in (bzlist if bzlist else []):
result_man2 = self._parse_bz(obz, no_bz) result_man2, no_bz_skipped2 = self._parse_bz(obz, no_bz)
result_man.append(UtilParseCommitMessage('bz:\"%s\"' % obz, result_man2, git_backend=False, commit_date=-1000+i)) result_man.append(UtilParseCommitMessage('bz:\"%s\"' % obz, result_man2, git_backend=False, commit_date=-1000+i))
no_bz_skipped.extend(no_bz_skipped2)
i = i + 1 i = i + 1
return result_man return result_man, list(set(no_bz_skipped))
def _rh_search(self, params, no_bz=None): def _rh_search(self, params, no_bz=None):
searches = BzInfoRhbz.BzClient.search(params) searches = BzInfoRhbz.BzClient.search(params)
result = [] result = []
no_bz_skipped = []
for s in searches: for s in searches:
bz = BzInfoRhbz(s['id'], bzdata=s) bz = BzInfoRhbz(s['id'], bzdata=s)
if no_bz is None or bz not in no_bz: if no_bz is None or bz not in no_bz:
result.append(bz) result.append(bz)
return result else:
no_bz_skipped.append(bz)
return result, no_bz_skipped
def _rh_searchlist(self, rh_searches, no_bz=None): def _rh_searchlist(self, rh_searches, no_bz=None):
i = 0 i = 0
result = [] result = []
no_bz_skipped = []
for (name,params) in rh_searches: for (name,params) in rh_searches:
result2 = self._rh_search(params, no_bz) result2, no_bz_skipped2 = self._rh_search(params, no_bz)
if not name: if not name:
name = ' ' + repr(params) name = ' ' + repr(params)
else: else:
name = name + ': ' + repr(params) name = name + ': ' + repr(params)
result.append(UtilParseCommitMessage('srch:' + name, result2, git_backend=False, commit_date=-2000+i)) result.append(UtilParseCommitMessage('srch:' + name, result2, git_backend=False, commit_date=-2000+i))
no_bz_skipped.extend(no_bz_skipped2)
i = i + 1 i = i + 1
return result return result, list(set(no_bz_skipped))
def filter_out(self, result, filter): def filter_out(self, result, filter):
exc = [] exc = []
@ -993,7 +1014,7 @@ class CmdParseCommitMessage(CmdBase):
if self.options.list_by_bz is None: if self.options.list_by_bz is None:
self.options.list_by_bz = False self.options.list_by_bz = False
no_bz = self._parse_bzlist(self.options.no_bz) no_bz, dummy = self._parse_bzlist(self.options.no_bz)
no_bz = set([bz for commit_data in no_bz for bz in commit_data.result]) no_bz = set([bz for commit_data in no_bz for bz in commit_data.result])
rh_searches = [] rh_searches = []
@ -1021,9 +1042,17 @@ class CmdParseCommitMessage(CmdBase):
'last_change_time': d.strftime('%Y%m%d'), 'last_change_time': d.strftime('%Y%m%d'),
})) }))
result_man = self._parse_bzlist(self.options.bz, no_bz) result_man, no_bz_skipped_man = self._parse_bzlist(self.options.bz, no_bz)
result_all = [ (ref, [UtilParseCommitMessage(commit, no_bz=no_bz) for commit in git_ref_list(ref)]) for ref in (self.options.ref if self.options.ref else [])] result_all = [ (ref, [UtilParseCommitMessage(commit, no_bz=no_bz) for commit in git_ref_list(ref)]) for ref in (self.options.ref if self.options.ref else [])]
result_search = self._rh_searchlist(rh_searches, no_bz) result_search, no_bz_skipped_search = self._rh_searchlist(rh_searches, no_bz)
no_bz_skipped = [no_bz_skipped for ref_data in result_all for commit_data in ref_data[1] for no_bz_skipped in commit_data.no_bz_skipped]
no_bz_skipped = sorted(list(set(itertools.chain(no_bz_skipped, no_bz_skipped_man, no_bz_skipped_search))))
if no_bz_skipped:
print("=== Excluded by --no-bz option: %s" % (" ".join(self.options.no_bz)))
for bz in no_bz_skipped:
print(bz.to_string(" ", 0, self.options.color))
if filter is not None: if filter is not None:
print("=== Excluded by filter: %s" % (repr(filter))) print("=== Excluded by filter: %s" % (repr(filter)))
@ -1036,11 +1065,12 @@ class CmdParseCommitMessage(CmdBase):
for commit_data in ref_data[1]: for commit_data in ref_data[1]:
excluded = excluded + commit_data.filter_out(filter) excluded = excluded + commit_data.filter_out(filter)
excluded =sorted(list(set(excluded))) if excluded:
for result in excluded: excluded =sorted(list(set(excluded)))
print(result.to_string(" ", 0, self.options.color)) for result in excluded:
print(result.to_string(" ", 0, self.options.color))
print(" --no-bz '%s'" % ",".join([str(result) for result in excluded]))
if self.options.list_refs or (self.options.list_refs is None and result_all): if self.options.list_refs or (self.options.list_refs is None and result_all):
print("=== List commit refs (%s) ===" % (len(result_all))) print("=== List commit refs (%s) ===" % (len(result_all)))