Nicer CLI listing of dependencies

This commit is contained in:
Sybren A. Stüvel 2018-02-28 17:02:34 +01:00
parent 2af8d94cb9
commit a7706f21b6

View File

@ -13,7 +13,8 @@ def add_parser(subparsers):
parser = subparsers.add_parser('list', help=__doc__) parser = subparsers.add_parser('list', help=__doc__)
parser.set_defaults(func=cli_list) parser.set_defaults(func=cli_list)
parser.add_argument('blendfile', type=pathlib.Path) parser.add_argument('blendfile', type=pathlib.Path)
common.add_flag(parser, 'recursive', help='Also report dependencies of dependencies') common.add_flag(parser, 'nonrecursive',
help='Limit to direct dependencies of the named blend file')
common.add_flag(parser, 'json', help='Output as JSON instead of human-readable text') common.add_flag(parser, 'json', help='Output as JSON instead of human-readable text')
@ -25,12 +26,26 @@ def cli_list(args):
log.fatal('File %s does not exist', args.blendfile) log.fatal('File %s does not exist', args.blendfile)
return 3 return 3
reported_files = set() cwd = pathlib.Path.cwd()
for usage in tracer.deps(bpath, recursive=args.recursive):
for path in usage.files(): reported_assets = set()
path = path.resolve() last_reported_bfile = None
if path in reported_files:
log.debug('Already reported %s', path) recursive = not args.nonrecursive
for usage in tracer.deps(bpath, recursive=recursive):
filepath = usage.block.bfile.filepath.absolute()
if filepath != last_reported_bfile:
print(filepath.relative_to(cwd))
last_reported_bfile = filepath
for assetpath in usage.files():
assetpath = assetpath.resolve()
if assetpath in reported_assets:
log.debug('Already reported %s', assetpath)
continue continue
print(path)
reported_files.add(path) try:
print(' ', assetpath.relative_to(cwd))
except ValueError:
print(' ', assetpath)
reported_assets.add(assetpath)