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.
- 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:
package_inst –
pkgcore.ebuild.ebuild_src.package
instance to regenerateeclass_cache –
pkgcore.ebuild.eclass_cache
instance to use for eclass access
- Returns:
string of the ebuild environment.
- get_keys(package_inst, eclass_cache)[source]¶
Request the metadata be regenerated from an ebuild.
- Parameters:
package_inst –
pkgcore.ebuild.ebuild_src.package
instance to regenerateeclass_cache –
pkgcore.ebuild.eclass_cache
instance to use for eclass access
- 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.
- 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
- 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.
- 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:
ebp –
EbuildProcessor
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:
- Parameters:
userpriv – should the processor be deprived to
pkgcore.os_data.portage_gid
andpkgcore.os_data.portage_uid
?sandbox – should the processor be sandboxed?