bam cli: updates
- deps now supports --json - paths are now committed relative to their session dir (TODO, remapping)
This commit is contained in:
@@ -181,6 +181,8 @@ class bam_session:
|
||||
import os
|
||||
from bam_utils.system import sha1_from_file
|
||||
|
||||
session_rootdir = os.path.abspath(session_rootdir)
|
||||
|
||||
# don't commit metadata
|
||||
paths_used = {
|
||||
os.path.join(session_rootdir, ".bam_paths_uuid.json"),
|
||||
@@ -229,7 +231,9 @@ class bam_session:
|
||||
if fn_abs not in paths_used:
|
||||
# we should be clever - add the file to a useful location based on some rules
|
||||
# (category, filetype & tags?)
|
||||
fn_rel = os.path.basename(fn_abs)
|
||||
|
||||
# XXX, remap!
|
||||
fn_rel = os.path.relpath(fn_abs, session_rootdir)
|
||||
|
||||
# TODO(cam)
|
||||
# remap paths of added files
|
||||
@@ -616,19 +620,28 @@ class bam_commands:
|
||||
print(" %s" % name_short)
|
||||
|
||||
@staticmethod
|
||||
def deps(paths, recursive=False):
|
||||
import blendfile_path_walker
|
||||
def deps(paths, recursive=False, use_json=False):
|
||||
import os
|
||||
# TODO(cam) multiple paths
|
||||
|
||||
def deps_path_walker():
|
||||
import blendfile_path_walker
|
||||
for blendfile_src in paths:
|
||||
blendfile_src = blendfile_src.encode('utf-8')
|
||||
for fp, (rootdir, fp_blend_basename) in blendfile_path_walker.FilePath.visit_from_blend(
|
||||
yield from blendfile_path_walker.FilePath.visit_from_blend(
|
||||
blendfile_src,
|
||||
readonly=True,
|
||||
recursive=recursive,
|
||||
):
|
||||
print(" %r -> %r" % (os.path.join(fp.basedir, fp_blend_basename), fp.filepath))
|
||||
)
|
||||
|
||||
if use_json:
|
||||
ret = []
|
||||
import json
|
||||
for fp, (rootdir, fp_blend_basename) in deps_path_walker():
|
||||
ret.append((os.path.join(fp.basedir, fp_blend_basename).decode('utf-8'), fp.filepath.decode('utf-8')))
|
||||
print(json.dumps(ret))
|
||||
else:
|
||||
for fp, (rootdir, fp_blend_basename) in deps_path_walker():
|
||||
print(" %r -> %r" % (os.path.join(fp.basedir, fp_blend_basename), fp.filepath))
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Argument Parser
|
||||
@@ -771,7 +784,9 @@ def create_argparse_list(subparsers):
|
||||
|
||||
subparse.set_defaults(
|
||||
func=lambda args:
|
||||
bam_commands.list_dir(args.paths or ["."], use_json=args.json),
|
||||
bam_commands.list_dir(
|
||||
args.paths or ["."],
|
||||
use_json=args.json),
|
||||
)
|
||||
|
||||
|
||||
@@ -788,9 +803,14 @@ def create_argparse_deps(subparsers):
|
||||
"-r", "--recursive", dest="recursive", action='store_true',
|
||||
help="Scan dependencies recursively",
|
||||
)
|
||||
|
||||
generic_argument_json(subparse)
|
||||
|
||||
subparse.set_defaults(
|
||||
func=lambda args:
|
||||
bam_commands.deps(args.paths or ["."], args.recursive)
|
||||
bam_commands.deps(
|
||||
args.paths or ["."], args.recursive,
|
||||
use_json=args.json),
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user