Package ubiquerg Documentation

Class TmpEnv

Temporary environment variable setting.

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 format_help(self)

Add version information to help text.

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 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 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 size(path, size_str=True)

Gets the size of the file or directory in the provided path

Parameters:

  • path (str): path to the file to check size of
  • size_str (bool): whether the size should be converted to a human-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

Version Information: ubiquerg v0.5.0, generated by lucidoc v0.4.1