Permalink
Browse files

Add command to print a table with the patched modules

To print the table type: recipy pm

This command uses tabluate. If tabulate isn't installed, an error
message is printed.

Todo:
- add tests for this command
- show warning if the patched modules are empty; this means that
  recipy hasn't been run (the patched modules table is filled every
  time recipy is imported)
  • Loading branch information...
jvdzwaan committed Oct 17, 2018
1 parent 0f93a68 commit 2dca1d151b02e7a57947bac16a8e001eda01c2f7
Showing with 38 additions and 0 deletions.
  1. +38 −0 recipyCmd/recipycmd.py
@@ -6,6 +6,7 @@
recipy latest [options]
recipy gui [options]
recipy annotate [<idvalue>]
recipy pm [--format=<rst|plain>]
recipy (-h | --help)
recipy --version
@@ -141,6 +142,8 @@ def main():
gui(args)
elif args['annotate']:
annotate(args)
elif args['pm']:
patched_modules(args)
def annotate(args):
@@ -428,5 +431,40 @@ def _change_date(result):
result['date'] = str(result['date']).replace('{TinyDate}:', '')
return result
def patched_modules(args):
modules = db.table('patches').all()
db.close()
fmt = args.get('--format', 'plain')
print(fmt)
try:
from tabulate import tabulate
except ImportError:
print('Please install tabulate for printing the patched modules.')
return
table = []
for m in modules:
t = {}
for k, v in m.items():
if isinstance(v, list):
if len(v) > 0:
if fmt == 'rst':
t[k] = '``{}``'.format('``,\n``'.join(v))
else:
t[k] = '{}'.format('\n'.join(v))
else:
t[k] = ''
else:
if fmt == 'rst':
t[k] = '``{}``'.format(v)
else:
t[k] = v
table.append(t)
print(tabulate(table, headers='keys', tablefmt='rst'))
if __name__ == '__main__':
main()

0 comments on commit 2dca1d1

Please sign in to comment.