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