pkgcore.ebuild.processor module

low level ebuild processor

This basically is a coprocessor that controls a bash daemon for actual ebuild execution. Via this, the bash side can reach into the python side (and vice versa), enabling remote trees (piping data from python side into bash side for example).

A couple of processors are left lingering while pkgcore is running for the purpose of avoiding spawning overhead, this (and the general design) reduces regen time by over 40% compared to portage-2.1

class pkgcore.ebuild.processor.EbuildProcessor(userpriv, sandbox, fd_pipes=None)[source]

Bases: object

Abstraction of a running ebd instance.

Contains the env, functions, etc that ebuilds expect.

allow_eclass_caching()[source]
clear_preloaded_eclasses()[source]
disable_eclass_caching()[source]
expect(want, async_req=False, flush=False, timeout=0)[source]

Read from the daemon, check if the returned string is expected.

Parameters:

want – string we’re expecting

Returns:

boolean, was what was read == want?

generic_handler(additional_commands=None)[source]

Internal event handler responding to the running processor’s requests.

Parameters:

additional_commands (mapping from string to callable.) – Extra command handlers. Command names cannot have spaces. The callable is called with the processor as first arg, and remaining string (None if no remaining fragment) as second arg. If you need to split the args to command, whitespace splitting falls to your func.

Raises:

UnhandledCommand – thrown when an unknown command is encountered.

get_ebuild_environment(package_inst, eclass_cache)[source]

Request a dump of the ebuild environ for a package.

This dump is created from doing metadata sourcing.

Parameters:
Returns:

string of the ebuild environment.

get_keys(package_inst, eclass_cache)[source]

Request the metadata be regenerated from an ebuild.

Parameters:
Returns:

dict when successful, None when failed

property is_alive

Return whether the processor is alive.

property is_locked

alias to processing_lock

property is_responsive

Return where the processor is in main control loop and responsive.

lock()[source]

Lock the processor.

Currently doesn’t block any access, but will.

preload_eclasses(cache, async_req=False, limited_to=None)[source]

Preload an eclass stack’s eclasses into bash functions.

Avoids the cost of going to disk on inherit. Preloading eutils (which is heavily inherited) speeds up regen times for example.

Parameters:

ec_file – filepath of eclass to preload

Returns:

boolean, True for success

read(lines=1)[source]

Read data from the daemon.

Shouldn’t be called except internally.

readlines(lines)[source]
run_phase(phase, env, tmpdir=None, logging=None, additional_commands=None, sandbox=True)[source]

Utility function, to initialize the processor for a phase.

Used to combine multiple calls into one, leaving the processor in a state where all that remains is a call start_processing call, then generic_handler event loop.

Parameters:
  • phase (str) – phase to prep for

  • env – mapping of the environment to prep the processor with

  • sandbox – should the sandbox be enabled?

  • logging – None, or a filepath to log the output from the processor to

Returns:

True for success, False for everything else

sandbox_summary(move_log=False)[source]

If the instance is sandboxed, print the sandbox access summary.

Parameters:

move_log – location to move the sandbox log to if a failure occurred

send_env(env_dict, async_req=False, tmpdir=None)[source]

Transfer the ebuild’s desired env (env_dict) to the running daemon.

Parameters:

env_dict (mapping with string keys and values.) – the bash env.

set_logfile(logfile='')[source]

Set the logfile (location to log to).

Relevant only when the daemon is sandboxed.

Parameters:

logfile – filepath to log to

shutdown_processor(force=False, ignore_keyboard_interrupt=False)[source]

Tell the daemon to shut itself down, and mark this instance as dead.

unlock()[source]

Unlock the processor.

write(string, flush=True, disable_runtime_exceptions=False, append_newline=True)[source]

Send something to the bash side.

Parameters:
  • string – string to write to the bash processor. All strings written are automatically n terminated.

  • flush – boolean controlling whether the data is flushed immediately. Disabling flush is useful when dumping large amounts of data.

exception pkgcore.ebuild.processor.UnhandledCommand(line=None)[source]

Bases: ProcessingInterruption

Bash processor sent an unknown command.

pkgcore.ebuild.processor.expected_ebuild_env(pkg, d=None, env_source_override=None, depends=False)[source]

Setup expected ebuild vars.

Parameters:

d – if None, generates a dict, else modifies a passed in mapping

Returns:

mapping

pkgcore.ebuild.processor.release_ebuild_processor(ebp)[source]

Release a given processor instance and shut it down if necessary.

Any processor requested via request_ebuild_processor() B{must} be released via this function once it’s no longer in use.

Parameters:

ebpEbuildProcessor instance

Returns:

boolean indicating release results- if the processor isn’t known as active, False is returned. If a processor isn’t known as active, this means either calling error or an internal error.

pkgcore.ebuild.processor.request_ebuild_processor(userpriv=False, sandbox=None, fd_pipes=None)[source]

Request a processor instance, creating a new one if needed.

Returns:

EbuildProcessor

Parameters:
  • userpriv – should the processor be deprived to pkgcore.os_data.portage_gid and pkgcore.os_data.portage_uid?

  • sandbox – should the processor be sandboxed?