Nicer CLI listing of dependencies
This commit is contained in:
parent
2af8d94cb9
commit
a7706f21b6
@ -13,7 +13,8 @@ def add_parser(subparsers):
|
||||
parser = subparsers.add_parser('list', help=__doc__)
|
||||
parser.set_defaults(func=cli_list)
|
||||
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')
|
||||
|
||||
|
||||
@ -25,12 +26,26 @@ def cli_list(args):
|
||||
log.fatal('File %s does not exist', args.blendfile)
|
||||
return 3
|
||||
|
||||
reported_files = set()
|
||||
for usage in tracer.deps(bpath, recursive=args.recursive):
|
||||
for path in usage.files():
|
||||
path = path.resolve()
|
||||
if path in reported_files:
|
||||
log.debug('Already reported %s', path)
|
||||
cwd = pathlib.Path.cwd()
|
||||
|
||||
reported_assets = set()
|
||||
last_reported_bfile = None
|
||||
|
||||
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
|
||||
print(path)
|
||||
reported_files.add(path)
|
||||
|
||||
try:
|
||||
print(' ', assetpath.relative_to(cwd))
|
||||
except ValueError:
|
||||
print(' ', assetpath)
|
||||
reported_assets.add(assetpath)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user