markovchain.cli package

Submodules

markovchain.cli.image module

class markovchain.cli.image.TraversalProgressWrapper(obj, channels, parent=None)[source]

Bases: markovchain.util.ObjectWrapper

Traversal object wrapper.

Shows image traversal progress.

pbar_parent

Parent progress bar.

Type

tqdm.tqdm

__call__(width, height, ends=True)[source]

Call self as a function.

__init__(obj, channels, parent=None)[source]
markovchain.cli.image.cmd_create(args)[source]

Create a generator.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.image.cmd_filter(args)[source]

Filter an image.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.image.cmd_generate(args)[source]

Generate images.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.image.cmd_update(args)[source]

Update a generator.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.image.create_arg_parser(parent)[source]

Create command subparsers.

Parameters

parent (argparse.ArgumentParser) – Command parser.

markovchain.cli.image.outfiles(markov, fmt, nfiles, progress, start=0)[source]

Get output file paths.

Parameters
  • markov (markovchain.base.MarkovBase) – Markov chain generator.

  • fmt (str) – File path format string.

  • nfiles (int) – Number of files.

  • progress (bool) – Show progress bars.

  • start (int, optional) – Initial image level (default: 0).

Returns

Output file paths.

Return type

generator of str

markovchain.cli.image.read(fnames, markov, progress, leave=True)[source]

Read data files and update a generator.

Parameters
  • fnames (list of str) – File paths.

  • markov (markovchain.base.MarkovBase) – Generator to update.

  • progress (bool) – Show progress bar.

  • leave (bool, optional) – Leave progress bars (default: True).

markovchain.cli.main module

markovchain.cli.main.main(args=None)[source]

CLI main function.

Parameters

args (list of str, optional) – CLI arguments (default: sys.argv).

markovchain.cli.text module

markovchain.cli.text.cmd_create(args)[source]

Create a generator.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.text.cmd_generate(args)[source]

Generate text.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.text.cmd_update(args)[source]

Update a generator.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.text.create_arg_parser(parent)[source]

Create command subparsers.

Parameters

parent (argparse.ArgumentParser) – Command parser.

markovchain.cli.text.read(fnames, markov, progress)[source]

Read data files and update a generator.

Parameters
  • fnames (list of str) – File paths.

  • markov (markovchain.base.MarkovBase) – Generator to update.

  • progress (bool) – Show progress bar.

markovchain.cli.util module

class markovchain.cli.util.NoProgressBar[source]

Bases: object

Missing progress bar class.

warning

True if a missing progress bar warning was printed.

Type

bool

close(*args, **kwargs)[source]

Do nothing.

classmethod print_warning()[source]

Print a missing progress bar warning if it was not printed.

update(*args, **kwargs)[source]

Do nothing.

warning = False
markovchain.cli.util.check_output_format(fmt, nfiles)[source]

Validate file format string.

Parameters
  • fmt (str) – File format string.

  • nfiles (int) – Number of files.

Raises

ValueError – If nfiles < 0 or format string is invalid.

markovchain.cli.util.cmd_settings(args)[source]

Print generator settings.

Parameters

args (argparse.Namespace) – Command arguments.

markovchain.cli.util.infiles(fnames, progress, leave=True)[source]

Get input file paths.

Parameters
  • fnames (list of str) – File paths.

  • progress (bool) – Show progress bar.

  • leave (bool, optional) – Leave progress bar (default: True).

Returns

Input file paths.

Return type

generator of str

markovchain.cli.util.load(cls, fname, args)[source]

Load a generator.

Parameters
  • cls (type) – Generator class.

  • fname (str) – Input file path.

  • args (argparse.Namespace) – Command arguments.

Return type

cls

markovchain.cli.util.no_tqdm(iterable=None, *args, **kwargs)[source]

Print a missing progress bar warning if it was not printed.

Parameters

iterable (iterable or None, optional) – Iterable to decorate with a progress bar (default: None).

Return type

iterable or markovchain.cli.util.NoProgressBar

markovchain.cli.util.outfiles(fmt, nfiles, progress, leave=True)[source]

Get output file paths.

Parameters
  • fmt (str) – File path format string.

  • nfiles (int) – Number of files.

  • progress (bool) – Show progress bars.

  • leave (bool, optional) – Leave progress bar (default: True).

Raises

ValueError – If nfiles <= 0.

Returns

Output file paths.

Return type

generator of str

markovchain.cli.util.pprint(data, indent=0, end='\n')[source]

Pretty print JSON data.

Parameters
  • data – JSON data.

  • indent (int, optional) – Indent level in characters (default: 0).

  • end (str, optional) – String to print after the data (default: ‘\n’).

markovchain.cli.util.save(markov, fname, args)[source]

Save a generator.

Parameters
  • markov (markovchain.Markov) – Generator to save.

  • fname (str) – Output file path.

  • args (argparse.Namespace) – Command arguments.

markovchain.cli.util.save_image(img, fname)[source]

Save an image.

Parameters
  • img (PIL.Image) – Image to save.

  • fname (str) – File path.

markovchain.cli.util.set_args(args)[source]

Set computed command arguments.

Parameters
  • args (argparse.Namespace) – Command arguments.

  • base (iterable of type) – Generator mixins.

Raises

ValueError – If output file is stdout and progress bars are enabled.

Module contents