drawer#

Example#

Here is an example CLI for extracting archives:

from libjam import captain, writer, drawer
import os
import sys

@captain()
def cli(archive, out_directory, **opts):
  # Validating input
  if not os.path.exists(archive):
    cli.usage_error(f'{archive}: no such file or directory.')
  if not os.path.isfile(archive):
    cli.usage_error(f'{archive}: not a file.')
  if not drawer.can_unpack(archive):
    cli.usage_error(f'{archive}: unsupported filetype.')
  # Extracting
  name = os.path.basename(archive)
  with writer.ProgressBar(f"Extracting '{name}'") as bar:
    drawer.unpack_with_progress(archive, out_directory, bar.update)

if __name__ == '__main__':
  sys.exit(cli())

API#

Provides a few missing pieces for file management.

libjam.drawer.copy_with_progress(src, dst, progress_callback: callable)#

Copies the given file while providing current progress.

libjam.drawer.copy_tree_with_progress(src, dst, progress_callback: callable)#

Copies the given directory while providing current progress.

Deletes the given directory while providing current progress.

libjam.drawer.get_tree_size(directory) int#

Returns the size of the given directory in bytes.

libjam.drawer.to_readable_size(size: int, ndigits: int = 1) tuple[float, str, str]#

Given a number of bytes, returns a human readable filesize, as a tuple.

Tuple format: (value, short unit name, long unit name) Example output: (6.9, ‘MB’, ‘MegaBytes’)

libjam.drawer.start(*args) int#

Like xdg-open, but platform-aware.

libjam.drawer.pack_zip(src, dst)#

Packs the given directory to a zip file.

libjam.drawer.pack_zip_with_progress(src, dst, progress_callback: callable)#

Packs the given directory to a zip file while providing the current progress.

libjam.drawer.unpack_zip(src, dst)#

Unpacks the given zip archive to the specified directory.

libjam.drawer.unpack_zip_with_progress(src, dst, progress_callback: callable)#

Unpacks the given zip archive to the specified directory while providing current progress.

libjam.drawer.pack_7z(src, dst)#

Packs the given directory to a 7zip file.

libjam.drawer.unpack_7z(src, dst)#

Unpacks the given 7zip archive to the specified directory.

libjam.drawer.unpack_7z_with_progress(src, dst, progress_callback: callable)#

Unpacks the given tar archive to the specified directory while providing current progress.

libjam.drawer.unpack_rar(src, dst)#

Unpacks the given rar archive to the specified directory.

libjam.drawer.unpack_rar_with_progress(src, dst, progress_callback: callable)#

Unpacks the given tar archive to the specified directory while providing current progress.

libjam.drawer.can_unpack(archive) bool#

Checks if the given archive can be unpacked.

libjam.drawer.unpack(src, dst)#

Unpacks the given archive to the specified directory.

If the archive type is not supported NotImplementedError is raised.

libjam.drawer.unpack_with_progress(src, dst, progress_callback: callable)#

Unpacks the given archive to the specified directory while providing current progress.

If the archive type is not supported NotImplementedError is raised.