Added --compress option for 'bat pack' command
This compresses all packed Blend files. Other files, as well as already- compressed Blend files, are left as-is.
This commit is contained in:
@@ -97,11 +97,14 @@ class Packer:
|
||||
bfile: pathlib.Path,
|
||||
project: pathlib.Path,
|
||||
target: pathlib.Path,
|
||||
noop=False) -> None:
|
||||
*,
|
||||
noop=False,
|
||||
compress=False) -> None:
|
||||
self.blendfile = bfile
|
||||
self.project = project
|
||||
self.target = target
|
||||
self.noop = noop
|
||||
self.compress = compress
|
||||
self._aborted = threading.Event()
|
||||
self._abort_lock = threading.RLock()
|
||||
|
||||
@@ -352,6 +355,9 @@ class Packer:
|
||||
|
||||
def _create_file_transferer(self) -> transfer.FileTransferer:
|
||||
"""Create a FileCopier(), can be overridden in a subclass."""
|
||||
|
||||
if self.compress:
|
||||
return filesystem.CompressedFileCopier()
|
||||
return filesystem.FileCopier()
|
||||
|
||||
def _start_file_transferrer(self):
|
||||
|
||||
@@ -22,6 +22,7 @@ import pathlib
|
||||
import shutil
|
||||
import typing
|
||||
|
||||
from .. import compressor
|
||||
from . import transfer
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -81,9 +82,17 @@ class FileCopier(transfer.FileTransferer):
|
||||
if self.files_skipped:
|
||||
log.info('Skipped %d files', self.files_skipped)
|
||||
|
||||
def _move(self, srcpath: pathlib.Path, dstpath: pathlib.Path):
|
||||
"""Low-level file move"""
|
||||
shutil.move(str(srcpath), str(dstpath))
|
||||
|
||||
def _copy(self, srcpath: pathlib.Path, dstpath: pathlib.Path):
|
||||
"""Low-level file copy"""
|
||||
shutil.copy2(str(srcpath), str(dstpath))
|
||||
|
||||
def move(self, srcpath: pathlib.Path, dstpath: pathlib.Path):
|
||||
s_stat = srcpath.stat()
|
||||
shutil.move(str(srcpath), str(dstpath))
|
||||
self._move(srcpath, dstpath)
|
||||
|
||||
self.files_transferred += 1
|
||||
self.report_transferred(s_stat.st_size)
|
||||
@@ -108,7 +117,7 @@ class FileCopier(transfer.FileTransferer):
|
||||
return
|
||||
|
||||
log.debug('Copying %s → %s', srcpath, dstpath)
|
||||
shutil.copy2(str(srcpath), str(dstpath))
|
||||
self._copy(srcpath, dstpath)
|
||||
|
||||
self.already_copied.add((srcpath, dstpath))
|
||||
self.files_transferred += 1
|
||||
@@ -176,3 +185,11 @@ class FileCopier(transfer.FileTransferer):
|
||||
self.already_copied.add((src, dst))
|
||||
|
||||
return dst
|
||||
|
||||
|
||||
class CompressedFileCopier(FileCopier):
|
||||
def _move(self, srcpath: pathlib.Path, dstpath: pathlib.Path):
|
||||
compressor.move(srcpath, dstpath)
|
||||
|
||||
def _copy(self, srcpath: pathlib.Path, dstpath: pathlib.Path):
|
||||
compressor.copy(srcpath, dstpath)
|
||||
|
||||
Reference in New Issue
Block a user