Added block expansion

The expansion process follows pointers and library links to construct
the full set of actually-used data blocks. This set consists of all data
blocks in the initial blend file, and all *actually linked-to* data
blocks in linked blend files.

I've also removed non-recursive dependency listing.
This commit is contained in:
Sybren A. Stüvel
2018-03-02 15:44:07 +01:00
parent 677d388a15
commit 8009ff1e47
10 changed files with 471 additions and 117 deletions
+7 -10
View File
@@ -4,8 +4,8 @@ import logging
import pathlib
import sys
from . import common
from blender_asset_tracer import tracer
from . import common
log = logging.getLogger(__name__)
@@ -16,8 +16,6 @@ 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, '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')
@@ -27,14 +25,13 @@ def cli_list(args):
log.fatal('File %s does not exist', args.blendfile)
return 3
recursive = not args.nonrecursive
if args.json:
report_json(bpath, recursive)
report_json(bpath)
else:
report_text(bpath, recursive)
report_text(bpath)
def report_text(bpath, recursive):
def report_text(bpath):
reported_assets = set()
last_reported_bfile = None
cwd = pathlib.Path.cwd()
@@ -46,7 +43,7 @@ def report_text(bpath, recursive):
except ValueError:
return somepath
for usage in tracer.deps(bpath, recursive=recursive):
for usage in tracer.deps(bpath):
filepath = usage.block.bfile.filepath.absolute()
if filepath != last_reported_bfile:
print(shorten(filepath))
@@ -71,13 +68,13 @@ class JSONSerialiser(json.JSONEncoder):
return super().default(o)
def report_json(bpath, recursive):
def report_json(bpath):
import collections
# Mapping from blend file to its dependencies.
report = collections.defaultdict(set)
for usage in tracer.deps(bpath, recursive=recursive):
for usage in tracer.deps(bpath):
filepath = usage.block.bfile.filepath.absolute()
for assetpath in usage.files():
assetpath = assetpath.resolve()