pack, support --exclude argument
See: bam pack --help
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
__version__ = "0.0.4.6"
|
__version__ = "0.0.4.7"
|
||||||
|
|
||||||
def main(argv=sys.argv):
|
def main(argv=sys.argv):
|
||||||
from .cli import main
|
from .cli import main
|
||||||
|
@@ -130,6 +130,10 @@ def pack(
|
|||||||
# {file: [(ofs, bytes), ...], ...}
|
# {file: [(ofs, bytes), ...], ...}
|
||||||
# ... where the file is the relative 'packed' location.
|
# ... where the file is the relative 'packed' location.
|
||||||
binary_edits=None,
|
binary_edits=None,
|
||||||
|
|
||||||
|
# Filename filter, allow to exclude files from the pack,
|
||||||
|
# function takes a string returns True if the files should be included.
|
||||||
|
filename_filter=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
:param deps_remap: Store path deps_remap info as follows.
|
:param deps_remap: Store path deps_remap info as follows.
|
||||||
@@ -467,6 +471,8 @@ def pack(
|
|||||||
# in rare cases a filepath could point to a directory
|
# in rare cases a filepath could point to a directory
|
||||||
if (not os.path.exists(src)) or os.path.isdir(src):
|
if (not os.path.exists(src)) or os.path.isdir(src):
|
||||||
yield report(" %s: %r\n" % (colorize("source missing", color='red'), src))
|
yield report(" %s: %r\n" % (colorize("source missing", color='red'), src))
|
||||||
|
elif filename_filter and not filename_filter(src):
|
||||||
|
yield report(" %s: %r\n" % (colorize("exclude", color='yellow'), src))
|
||||||
else:
|
else:
|
||||||
yield report(" %s: %r -> %r\n" % (colorize("copying", color='blue'), src, dst))
|
yield report(" %s: %r -> %r\n" % (colorize("copying", color='blue'), src, dst))
|
||||||
shutil.copy(src, dst)
|
shutil.copy(src, dst)
|
||||||
@@ -505,6 +511,8 @@ def pack(
|
|||||||
# in rare cases a filepath could point to a directory
|
# in rare cases a filepath could point to a directory
|
||||||
if (not os.path.exists(src)) or os.path.isdir(src):
|
if (not os.path.exists(src)) or os.path.isdir(src):
|
||||||
yield report(" %s: %r\n" % (colorize("source missing", color='red'), src))
|
yield report(" %s: %r\n" % (colorize("source missing", color='red'), src))
|
||||||
|
elif filename_filter and not filename_filter(src):
|
||||||
|
yield report(" %s: %r\n" % (colorize("exclude", color='yellow'), src))
|
||||||
else:
|
else:
|
||||||
yield report(" %s: %r -> <archive>\n" % (colorize("copying", color='blue'), src))
|
yield report(" %s: %r -> <archive>\n" % (colorize("copying", color='blue'), src))
|
||||||
zip_handle.write(
|
zip_handle.write(
|
||||||
|
39
bam/cli.py
39
bam/cli.py
@@ -1321,6 +1321,7 @@ class bam_commands:
|
|||||||
all_deps=False,
|
all_deps=False,
|
||||||
use_quiet=False,
|
use_quiet=False,
|
||||||
compress_level=-1,
|
compress_level=-1,
|
||||||
|
filename_filter=None,
|
||||||
):
|
):
|
||||||
# Local packing (don't use any project/session stuff)
|
# Local packing (don't use any project/session stuff)
|
||||||
from .blend import blendfile_pack
|
from .blend import blendfile_pack
|
||||||
@@ -1343,6 +1344,26 @@ class bam_commands:
|
|||||||
else:
|
else:
|
||||||
report = lambda msg: print(msg, end="")
|
report = lambda msg: print(msg, end="")
|
||||||
|
|
||||||
|
# replace var with a pattern matching callback
|
||||||
|
if filename_filter:
|
||||||
|
# convert string into regex callback
|
||||||
|
# "*.txt;*.png;*.rst" --> r".*\.txt$|.*\.png$|.*\.rst$"
|
||||||
|
import re
|
||||||
|
import fnmatch
|
||||||
|
|
||||||
|
compiled_pattern = re.compile(
|
||||||
|
b'|'.join(fnmatch.translate(f).encode('utf-8')
|
||||||
|
for f in filename_filter.split(";") if f),
|
||||||
|
re.IGNORECASE,
|
||||||
|
)
|
||||||
|
|
||||||
|
def filename_filter(f):
|
||||||
|
return (not filename_filter.compiled_pattern.match(f))
|
||||||
|
filename_filter.compiled_pattern = compiled_pattern
|
||||||
|
|
||||||
|
del compiled_pattern
|
||||||
|
del re, fnmatch
|
||||||
|
|
||||||
for msg in blendfile_pack.pack(
|
for msg in blendfile_pack.pack(
|
||||||
path.encode('utf-8'),
|
path.encode('utf-8'),
|
||||||
output.encode('utf-8'),
|
output.encode('utf-8'),
|
||||||
@@ -1350,6 +1371,7 @@ class bam_commands:
|
|||||||
all_deps=all_deps,
|
all_deps=all_deps,
|
||||||
compress_level=compress_level,
|
compress_level=compress_level,
|
||||||
report=report,
|
report=report,
|
||||||
|
filename_filter=filename_filter,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -1674,6 +1696,19 @@ def create_argparse_pack(subparsers):
|
|||||||
choices=('ZIP', 'FILE'),
|
choices=('ZIP', 'FILE'),
|
||||||
help="Output file or a directory when multiple inputs are passed",
|
help="Output file or a directory when multiple inputs are passed",
|
||||||
)
|
)
|
||||||
|
subparse.add_argument(
|
||||||
|
"-e", "--exclude", dest="exclude", metavar='PATTERN(S)', required=False,
|
||||||
|
default="",
|
||||||
|
help="""
|
||||||
|
Optionally exclude files from the pack.
|
||||||
|
|
||||||
|
Using Unix shell-style wildcards *(case insensitive)*.
|
||||||
|
``--exclude="*.png"``
|
||||||
|
|
||||||
|
Multiple patterns can be passed using the ``;`` separator.
|
||||||
|
``--exclude="*.txt;*.avi;*.wav"``
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
init_argparse_common(subparse, use_all_deps=True, use_quiet=True, use_compress_level=True)
|
init_argparse_common(subparse, use_all_deps=True, use_quiet=True, use_compress_level=True)
|
||||||
|
|
||||||
@@ -1687,7 +1722,9 @@ def create_argparse_pack(subparsers):
|
|||||||
args.mode,
|
args.mode,
|
||||||
all_deps=args.all_deps,
|
all_deps=args.all_deps,
|
||||||
use_quiet=args.use_quiet,
|
use_quiet=args.use_quiet,
|
||||||
compress_level=args.compress_level),
|
compress_level=args.compress_level,
|
||||||
|
filename_filter=args.exclude,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user