pkgcore.util.commandline module

Utilities for writing commandline utilities.

pkgcore scripts should use the ArgumentParser subclass here for a consistent commandline “look and feel” (and it tries to make life a bit easier too). They will probably want to use main from an C{if __name__ == ‘__main__’} block too: it will take care of things like consistent exception handling.

See dev-notes/commandline.rst for more complete documentation.

class pkgcore.util.commandline.ArgumentParser(suppress=False, help=True, config=True, domain=True, global_config=(), **kwds)[source]

Bases: ArgumentParser

class pkgcore.util.commandline.BooleanQuery(attrs, klass_type=None, priority=100, converter=None)[source]

Bases: DelayedValue

invokable(namespace, attr)[source]
class pkgcore.util.commandline.DomainFromPath(*args, **kwargs)[source]

Bases: StoreConfigObject

exception pkgcore.util.commandline.NoDefaultConfigError(argument, message)[source]

Bases: ArgumentError

class pkgcore.util.commandline.StoreConfigObject(*args, **kwargs)[source]

Bases: _StoreAction

default_priority = 20
classmethod lazy_load_object(config_type, key, priority=None)[source]
static store_all_default(config_type, namespace, attr)[source]
static store_default(config_type, namespace, attr, option_string=None)[source]
class pkgcore.util.commandline.StoreRepoObject(*args, **kwargs)[source]

Bases: StoreConfigObject

Load a repo object from the config.

valid_repo_types = {'all': 'repos', 'all-raw': 'repos_raw', 'binary': 'binary_repos', 'binary-raw': 'binary_repos_raw', 'binary-unfiltered': 'binary_repos_unfiltered', 'config': 'repo_configs', 'ebuild': 'ebuild_repos', 'ebuild-raw': 'ebuild_repos_raw', 'ebuild-unfiltered': 'ebuild_repos_unfiltered', 'installed': 'installed_repos', 'installed-raw': 'installed_repos_raw', 'source': 'source_repos', 'source-raw': 'source_repos_raw', 'unfiltered': 'unfiltered_repos'}
class pkgcore.util.commandline.StoreTarget(*args, **kwargs)[source]

Bases: _AppendAction

Parse extended package atom syntax and optionally set arguments.

Various target arguments are supported including the following:

atom

An extended atom syntax is supported, see the related section in pkgcore(5).

package set

Used to define lists of packages, the syntax used for these is @pkgset. For example, the @system and @world package sets are supported.

extended globbing

Globbing package names or atoms allows for use cases such as 'far*' (merge every package starting with ‘far’), 'dev-python/*::gentoo' (merge every package in the dev-python category from the gentoo repo), or even ‘*’ (merge everything).

Also, the target ‘-’ allows targets to be read from standard input.

class pkgcore.util.commandline.Tool(parser, outfile=None, errfile=None)[source]

Bases: Tool

pkgcore-specific commandline utility functionality.

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

Pass down pkgcore-specific settings to the bash side.

pkgcore.util.commandline.convert_to_restrict(sequence, default=<AlwaysBool always True @0x7fe8ba72b800>)[source]

Convert an iterable to a list of atoms, or return the default

pkgcore.util.commandline.find_domains_from_path(sections, path)[source]
pkgcore.util.commandline.make_query(parser, *args, **kwargs)[source]
pkgcore.util.commandline.python_namespace_type(value, module=False, attribute=False)[source]

return the object from python namespace that value specifies

Parameters:
  • value – python namespace, snakeoil.modules for example

  • module – if true, the object must be a module

  • attribute – if true, the object must be a non-module

Raises:

ValueError – if the conditions aren’t met, or import fails

pkgcore.util.commandline.register_command(commands, real_type=<class 'type'>)[source]
pkgcore.util.commandline.store_config(namespace, attr, global_config=())[source]