You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[wishlist] Produce comparison output into the terminal instead of html #32
html is nice et al, but what I often want is just to get a quick overview on how two things differ. Now for little comparisons it is a multistage procedure requiring running pkgdiff, opening the browser, closing the browser, removing the file. If there was a mode just to print information in the output of running of pkgdiff, it would be great.
E.g. debdiff in Debian world lists files which are present in one package but not in the other, and vise versa. The same could be done by pkgdiff.
I'm experimenting with pkgdiff for my workflow and needed this too. This is the python code I wrote to extract the information; you can use it if you want.
classStatus(IntEnum):
ADDED=1CHANGED=0MOVED=3REMOVED=2RENAMED=4ERROR=99status_cmp= {
'added': Status.ADDED,
'changed': Status.CHANGED,
'moved': Status.MOVED,
'removed': Status.REMOVED,
'renamed': Status.RENAMED
}
defrun_pkgdiff(path_lo, path_hi, dest=None):
"""Compare two .tar archives and generate a report of their difference. Args: path_lo (str): path_hi (str): dest (str): Returns: str: """ifnotcheck_tar(path_lo) andcheck_tar(path_hi):
logger.error('cannot compare non tar archives, %s or %s', path_lo, path_hi)
returnNoneifdestisNone:
dest=tempfile.gettempdir()
ifos.path.isdir(dest):
dest=os.path.join(dest, 'report.html')
dest=os.path.abspath(dest)
command='pkgdiff %s %s -hide-unchanged -list-added-removed -quick -report-path %s'% (
path_lo, path_hi, dest)
success=_run_process(command, track_output=True, success_statuses=(0, 1,))
returndestifsuccesselseNonedefgenerate_diff(report_path):
"""Generate a list of files to pick/choose for the new distribution."""ifnotreport_pathornotos.path.exists(report_path):
logger.error('cannot parse report, %s', report_path)
returnNonewithopen(report_path, 'r') asins_file:
soup=BeautifulSoup(ins_file, 'lxml')
logger.debug('created report %s', report_path)
try:
headers=list(soup.find_all('h2'))
# ignore: Test Info, Test Results, Changes in Files . . . Packagesheaders=headers[3:-1]
forsectioninheaders:
# each table represents all the file changes of a certain "type"table=section.find_next('table')
rows=iter(table.findChildren('tr'))
forrowinrows:
# each row is an individual file that changedcells=list(row.findChildren('td'))
ifnotcellsorlen(cells) ==0:
continue# extract the two columns we care aboutfilepath, status=cells[:2]
filepath=os.path.join(filepath.text)
status=status_cmp.get(status.string.lower(), Status.ERROR)
# path attribute changes come in pairs of two rowsifstatusin (Status.RENAMED, Status.MOVED):
row_b=next(rows)
dest=row_b.findChildren('td')[0].textelse:
dest=Noneyieldfilepath, dest, statusexceptExceptionase:
logger.exception(e, exc_info=True)
logger.error('cannot parse report, possibly invalid')
raisee
Activity
blakev commentedon Feb 1, 2018
I'm experimenting with pkgdiff for my workflow and needed this too. This is the python code I wrote to extract the information; you can use it if you want.