From a7706f21b6e59123b32f43edbfc73d296bf811a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 28 Feb 2018 17:02:34 +0100 Subject: [PATCH] Nicer CLI listing of dependencies --- blender_asset_tracer/cli/list_deps.py | 33 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/blender_asset_tracer/cli/list_deps.py b/blender_asset_tracer/cli/list_deps.py index e50e174..f6da0c5 100644 --- a/blender_asset_tracer/cli/list_deps.py +++ b/blender_asset_tracer/cli/list_deps.py @@ -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)