Package ubiquerg Documentation

Class TmpEnv

Temporary environment variable setting.

def __init__(self, overwrite=False, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Class VersionInHelpParser

Object for parsing command line strings into Python objects.

Keyword Arguments: - prog -- The name of the program (default: sys.argv[0]) - usage -- A usage message (default: auto-generated from arguments) - description -- A description of what the program does - epilog -- Text following the argument descriptions - parents -- Parsers whose arguments should be copied into this one - formatter_class -- HelpFormatter class for printing help messages - prefix_chars -- Characters that prefix optional arguments - fromfile_prefix_chars -- Characters that prefix files containing additional arguments - argument_default -- The default value for all arguments - conflict_handler -- String indicating how to handle conflicts - add_help -- Add a -h/-help option - allow_abbrev -- Allow long options to be abbreviated unambiguously

def __init__(self, version=None, **kwargs)

Overwrites the inherited init. Saves the version as an object attribute for further use.

def arg_defaults(self, subcommand=None, unique=False, top_level=False)

Get argument defaults by subcommand from a parser.

Parameters:

  • subcommand (str): subcommand to get defaults for
  • unique (bool): whether only unique flat dict of dests anddefaults mapping should be returned

Returns:

  • dict: defaults by subcommand
def dests_by_subparser(self, subcommand=None, top_level=False)

Get argument dests by subcommand from a parser.

Parameters:

  • subcommand (str): subcommand to get dests for

Returns:

  • dict: dests by subcommand
def format_help(self)

Add version information to help text.

def subcommands(self)

Get subcommands defined by a parser.

Returns:

  • list[str]: subcommands defined within this parser
def subparsers(self)

Get the subparser associated with a parser.

Returns:

  • argparse._SubparsersAction: action defining the subparsers
def suppress_defaults(self)

Remove parser change defaults to argparse.SUPPRESS so that they do not show up in the argparse.Namespace object after argument parsing.

def top_level_args(self)

Get actions not assiated with any subparser.

Help and version are also excluded

Returns:

  • list[argparse.<action_type>]: list of argument actions
def asciify_dict(data)

https://gist.github.com/chris-hailstorm/4989643

def build_cli_extra(optargs)

Render CLI options/args as text to add to base command.

To specify a flag, map an option to None. Otherwise, map option short or long name to value(s). Values that are collection types will be rendered with single space between each. All non-string values are converted to string.

Parameters:

  • optargs (Mapping | Iterable[(str, object)]): values used asoptions/arguments

Returns:

  • str: text to add to base command, based on given opts/args

Raises:

  • TypeError: if an option name isn't a string
def checksum(path, blocksize=2000000000)

Generate a md5 checksum for the file contents in the provided path.

Parameters:

  • path (str): path to file for which to generate checksum
  • blocksize (int): 2GB

Returns:

  • str: checksum hash
def convert_value(val)

Convert string to the most appropriate type, one of: bool, str, int, None or float

Parameters:

  • val (str): the string to convert

Returns:

  • bool | str | int | float | None: converted string to themost appropriate type
def create_file_racefree(file)

Creates a file, but fails if the file already exists.

This function will thus only succeed if this process actually creates the file; if the file already exists, it will cause an OSError, solving race conditions.

Parameters:

  • file (str): File to create.

Raises:

  • OSError: if the file to be created already exists
def create_lock(filepath, wait_max=10)

Securely create a lock file

Parameters:

  • filepath (str): path to a file to lock
  • wait_max (int): max wait time if the file in question is already locked
def expandpath(path)

Expand a filesystem path that may or may not contain user/env vars.

Parameters:

  • path (str): path to expand

Returns:

  • str: expanded version of input path
def filesize_to_str(size)

Converts the numeric bytes to the size string

Parameters:

  • size (int|float): file size to convert

Returns:

  • str: file size string
def is_collection_like(c)

Determine whether an object is collection-like.

Parameters:

  • c (object): Object to test as collection

Returns:

  • bool: Whether the argument is a (non-string) collection
def is_command_callable(cmd)

Check if command can be called.

Parameters:

  • cmd (str): actual command to check for callability

Returns:

  • bool: whether given command's call succeeded

Raises:

  • TypeError: if the alleged command isn't a string
  • ValueError: if the alleged command is empty
def is_url(maybe_url)

Determine whether a path is a URL.

Parameters:

  • maybe_url (str): path to investigate as URL

Returns:

  • bool: whether path appears to be a URL
def is_writable(folder, check_exist=False, create=False)

Make sure a folder is writable.

Given a folder, check that it exists and is writable. Errors if requested on a non-existent folder. Otherwise, make sure the first existing parent folder is writable such that this folder could be created.

Parameters:

  • folder (str): Folder to check for writeability.
  • check_exist (bool): Throw an error if it doesn't exist?
  • create (bool): Create the folder if it doesn't exist?
def make_lock_path(lock_name_base)

Create a collection of path to locks file with given name as bases.

Parameters:

  • lock_name_base (str | list[str]): Lock file names

Returns:

  • str | list[str]: Path to the lock files.
def merge_dicts(x, y)

Merge dictionaries

Parameters:

  • x (Mapping): dict to merge
  • y (Mapping): dict to merge

Returns:

  • Mapping: merged dict
def mkabs(path, reldir=None)

Makes sure a path is absolute; if not already absolute, it's made absolute relative to a given directory. Also expands ~ and environment variables for kicks.

Parameters:

  • path (str): Path to make absolute
  • reldir (str): Relative directory to make path absolute from if it'snot already absolute
def parse_registry_path(rpstring, defaults=[('protocol', None), ('namespace', None), ('item', None), ('subitem', None), ('tag', None)])

Parse a 'registry path' string into components.

A registry path is a string that is kind of like a URL, providing a unique identifier for a particular asset, like protocol::namespace/item.subitem:tag. You can use the defaults argument to change the names of the entries in the return dict, and to provide defaults in case of missing values.

Parameters:

  • rpstring (str): string to parse
  • defaults (list): A list of 5 tuples with name of the 5 entries, and adefault value in case it is missing (can be 'None')

Returns:

  • dict: dict with one element for each parsed entry in the path
def powerset(items, min_items=None, include_full_pop=True, nonempty=False)

Build the powerset of a collection of items.

Parameters:

  • items (Iterable[object]): "Pool" of all items, the population forwhich to build the power set.
  • min_items (int): Minimum number of individuals from the populationto allow in any given subset.
  • include_full_pop (bool): Whether to include the full population inthe powerset (default True to accord with genuine definition)
  • nonempty (bool): force each subset returned to be nonempty

Returns:

  • list[object]: Sequence of subsets of the population, innondecreasing size order

Raises:

  • TypeError: if minimum item count is specified but is not an integer
  • ValueError: if minimum item count is insufficient to guaranteenonempty subsets
def query_yes_no(question, default='no')

Ask a yes/no question via raw_input() and return their answer.

Parameters:

  • question (str): a string that is presented to the user.
  • default (str): the presumed answer if the user just hits .

Returns:

  • bool: True for "yes" or False for "no"
def remove_lock(filepath)

Remove lock

Parameters:

  • filepath (str): path to the file to remove the lock for.Not the path to the lock!

Returns:

  • bool: whether the lock was found and removed
def size(path, size_str=True)

Gets the size of a file or directory or list of them in the provided path

Parameters:

  • path (str|list): path or list of paths to the file or directoriesto check size of
  • size_str (bool): whether the size should be converted to ahuman-readable string, e.g. convert B to MB

Returns:

  • int|str: file size or file size string
def untar(src, dst)

Unpack a path to a target folder. All the required directories will be created

Parameters:

  • src (str): path to unpack
  • dst (str): path to output folder
def wait_for_lock(lock_file, wait_max=30)

Just sleep until the lock_file does not exist

Parameters:

  • lock_file (str): Lock file to wait upon.
  • wait_max (int): max wait time if the file in question is already locked

Version Information: ubiquerg v0.6.1, generated by lucidoc v0.4.2