Minor changes
- use functions instead of lambda - dont use color for non-terminal tty's - add --temp argument for blendfile_pack
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
__version__ = "0.0.5.2"
|
__version__ = "0.0.5.4"
|
||||||
|
|
||||||
def main(argv=sys.argv):
|
def main(argv=sys.argv):
|
||||||
from .cli import main
|
from .cli import main
|
||||||
|
@@ -99,7 +99,10 @@ def pack(
|
|||||||
# os.path.dirname(blendfile_src)
|
# os.path.dirname(blendfile_src)
|
||||||
# but in some cases we wan't to use a path higher up.
|
# but in some cases we wan't to use a path higher up.
|
||||||
# base_dir_src,
|
# base_dir_src,
|
||||||
blendfile_src, blendfile_dst, mode='FILE',
|
blendfile_src, blendfile_dst,
|
||||||
|
mode='ZIP',
|
||||||
|
# optionally pass in the temp dir
|
||||||
|
base_dir_dst_temp=None,
|
||||||
paths_remap_relbase=None,
|
paths_remap_relbase=None,
|
||||||
deps_remap=None, paths_remap=None, paths_uuid=None,
|
deps_remap=None, paths_remap=None, paths_uuid=None,
|
||||||
# load every libs dep, not just used deps.
|
# load every libs dep, not just used deps.
|
||||||
@@ -121,7 +124,7 @@ def pack(
|
|||||||
blendfile_src_dir_fakeroot=None,
|
blendfile_src_dir_fakeroot=None,
|
||||||
|
|
||||||
# Read variations from json files.
|
# Read variations from json files.
|
||||||
use_variations=True,
|
use_variations=False,
|
||||||
|
|
||||||
# do _everything_ except to write the paths.
|
# do _everything_ except to write the paths.
|
||||||
# useful if we want to calculate deps to remap but postpone applying them.
|
# useful if we want to calculate deps to remap but postpone applying them.
|
||||||
@@ -153,8 +156,12 @@ def pack(
|
|||||||
# also prevents cyclic loops from crashing.
|
# also prevents cyclic loops from crashing.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from bam.utils.system import colorize
|
if sys.stdout.isatty():
|
||||||
|
from bam.utils.system import colorize
|
||||||
|
else:
|
||||||
|
from bam.utils.system import colorize_dummy as colorize
|
||||||
|
|
||||||
# in case this is directly from the command line or user-input
|
# in case this is directly from the command line or user-input
|
||||||
blendfile_src = os.path.normpath(os.path.abspath(blendfile_src))
|
blendfile_src = os.path.normpath(os.path.abspath(blendfile_src))
|
||||||
@@ -174,7 +181,8 @@ def pack(
|
|||||||
TEMP_SUFFIX = b'@'
|
TEMP_SUFFIX = b'@'
|
||||||
|
|
||||||
if report is None:
|
if report is None:
|
||||||
report = lambda msg: msg
|
def report(msg):
|
||||||
|
return msg
|
||||||
|
|
||||||
yield report("%s: %r...\n" % (colorize("\nscanning deps", color='bright_green'), blendfile_src))
|
yield report("%s: %r...\n" % (colorize("\nscanning deps", color='bright_green'), blendfile_src))
|
||||||
|
|
||||||
@@ -187,10 +195,11 @@ def pack(
|
|||||||
# _dbg(blendfile_src)
|
# _dbg(blendfile_src)
|
||||||
# _dbg(blendfile_dst)
|
# _dbg(blendfile_dst)
|
||||||
|
|
||||||
if mode == 'ZIP':
|
if base_dir_dst_temp is None:
|
||||||
base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_temp__')
|
if mode == 'ZIP':
|
||||||
else:
|
base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_temp__')
|
||||||
base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_pack__')
|
else:
|
||||||
|
base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_pack__')
|
||||||
|
|
||||||
def temp_remap_cb(filepath, rootdir):
|
def temp_remap_cb(filepath, rootdir):
|
||||||
"""
|
"""
|
||||||
@@ -335,7 +344,6 @@ def pack(
|
|||||||
yield report(" %s: %r\n" % (colorize("exclude", color='yellow'), path_src))
|
yield report(" %s: %r\n" % (colorize("exclude", color='yellow'), path_src))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# apply variation (if available)
|
# apply variation (if available)
|
||||||
if use_variations:
|
if use_variations:
|
||||||
if blendfile_levels_dict_curr:
|
if blendfile_levels_dict_curr:
|
||||||
@@ -381,8 +389,8 @@ def pack(
|
|||||||
_dst_dir = os.path.dirname(path_dst)
|
_dst_dir = os.path.dirname(path_dst)
|
||||||
path_copy_files.update(
|
path_copy_files.update(
|
||||||
{(os.path.join(_src_dir, f), os.path.join(_dst_dir, f))
|
{(os.path.join(_src_dir, f), os.path.join(_dst_dir, f))
|
||||||
for f in file_list
|
for f in file_list
|
||||||
})
|
})
|
||||||
del _src_dir, _dst_dir
|
del _src_dir, _dst_dir
|
||||||
|
|
||||||
if deps_remap is not None:
|
if deps_remap is not None:
|
||||||
@@ -414,9 +422,11 @@ def pack(
|
|||||||
if paths_remap is not None:
|
if paths_remap is not None:
|
||||||
|
|
||||||
if paths_remap_relbase is not None:
|
if paths_remap_relbase is not None:
|
||||||
relbase = lambda fn: os.path.relpath(fn, paths_remap_relbase)
|
def relbase(fn):
|
||||||
|
return os.path.relpath(fn, paths_remap_relbase)
|
||||||
else:
|
else:
|
||||||
relbase = lambda fn: fn
|
def relbase(fn):
|
||||||
|
return fn
|
||||||
|
|
||||||
for src, dst in path_copy_files:
|
for src, dst in path_copy_files:
|
||||||
# TODO. relative to project-basepath
|
# TODO. relative to project-basepath
|
||||||
@@ -493,7 +503,8 @@ def pack(
|
|||||||
zlib.Z_DEFAULT_COMPRESSION = compress_level
|
zlib.Z_DEFAULT_COMPRESSION = compress_level
|
||||||
_compress_mode = zipfile.ZIP_STORED if (compress_level == 0) else zipfile.ZIP_DEFLATED
|
_compress_mode = zipfile.ZIP_STORED if (compress_level == 0) else zipfile.ZIP_DEFLATED
|
||||||
if _compress_mode == zipfile.ZIP_STORED:
|
if _compress_mode == zipfile.ZIP_STORED:
|
||||||
is_compressed_filetype = lambda fn: False
|
def is_compressed_filetype(fn):
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
from bam.utils.system import is_compressed_filetype
|
from bam.utils.system import is_compressed_filetype
|
||||||
|
|
||||||
@@ -554,13 +565,17 @@ def create_argparse():
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-m", "--mode", dest="mode", metavar='MODE', required=False,
|
"-m", "--mode", dest="mode", metavar='MODE', required=False,
|
||||||
choices=('FILE', 'ZIP'), default='FILE',
|
choices=('FILE', 'ZIP'), default='ZIP',
|
||||||
help="Output file or a directory when multiple inputs are passed",
|
help="Output file or a directory when multiple inputs are passed",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-q", "--quiet", dest="use_quiet", action='store_true', required=False,
|
"-q", "--quiet", dest="use_quiet", action='store_true', required=False,
|
||||||
help="Suppress status output",
|
help="Suppress status output",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-t", "--temp", dest="temp_path", metavar='DIR', required=False,
|
||||||
|
help="Temporary directory to use",
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@@ -572,14 +587,20 @@ def main():
|
|||||||
args = parser.parse_args(sys.argv[1:])
|
args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
if args.use_quiet:
|
if args.use_quiet:
|
||||||
report = lambda msg: None
|
def report(msg):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
report = lambda msg: print(msg, end="")
|
def report(msg):
|
||||||
|
sys.stdout.write(msg)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
for msg in pack(
|
for msg in pack(
|
||||||
args.path_src.encode('utf-8'),
|
args.path_src.encode('utf-8'),
|
||||||
args.path_dst.encode('utf-8'),
|
args.path_dst.encode('utf-8'),
|
||||||
mode=args.mode,
|
mode=args.mode,
|
||||||
|
base_dir_dst_temp=(
|
||||||
|
args.temp_path.encode('utf-8')
|
||||||
|
if args.temp_path else None),
|
||||||
):
|
):
|
||||||
report(msg)
|
report(msg)
|
||||||
|
|
||||||
|
@@ -1382,6 +1382,7 @@ class bam_commands:
|
|||||||
all_deps=all_deps,
|
all_deps=all_deps,
|
||||||
compress_level=compress_level,
|
compress_level=compress_level,
|
||||||
report=report,
|
report=report,
|
||||||
|
use_variations=True,
|
||||||
filename_filter=filename_filter,
|
filename_filter=filename_filter,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
#
|
#
|
||||||
# ***** END GPL LICENCE BLOCK *****
|
# ***** END GPL LICENCE BLOCK *****
|
||||||
|
|
||||||
|
def colorize_dummy(msg, color=None):
|
||||||
|
return msg
|
||||||
|
|
||||||
_USE_COLOR = True
|
_USE_COLOR = True
|
||||||
if _USE_COLOR:
|
if _USE_COLOR:
|
||||||
color_codes = {
|
color_codes = {
|
||||||
@@ -41,8 +44,7 @@ if _USE_COLOR:
|
|||||||
def colorize(msg, color=None):
|
def colorize(msg, color=None):
|
||||||
return (color_codes[color] + msg + color_codes['normal'])
|
return (color_codes[color] + msg + color_codes['normal'])
|
||||||
else:
|
else:
|
||||||
def colorize(msg, color=None):
|
colorize = colorize_dummy
|
||||||
return msg
|
|
||||||
|
|
||||||
|
|
||||||
def uuid_from_file(fn, block_size=1 << 20):
|
def uuid_from_file(fn, block_size=1 << 20):
|
||||||
|
@@ -469,6 +469,7 @@ class FileAPI(Resource):
|
|||||||
all_deps=all_deps,
|
all_deps=all_deps,
|
||||||
report=report,
|
report=report,
|
||||||
blendfile_src_dir_fakeroot=blendfile_src_dir_fakeroot.encode('utf-8'),
|
blendfile_src_dir_fakeroot=blendfile_src_dir_fakeroot.encode('utf-8'),
|
||||||
|
use_variations=True,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
binary_edits=binary_edits,
|
binary_edits=binary_edits,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user