def ZeroFindPath(url): """ find the path on the file system from the url from https://github.com/gfxmonk/0find/blob/master/zerofind.py """ try: del os.environ['DISPLAY'] except KeyError: pass selections = helpers.ensure_cached(url, command=None) if not selections: return None selection = selections.selections[url] if selection.id.startswith("package:"): print >> sys.stderr, "Package implementation: %s" % (selection.id, ) return None if os.path.exists(selection.id): return selection.id return zerostore.Stores().lookup_any(selection.digests)
def stores(self): if not self._stores: self._stores = zerostore.Stores() return self._stores
def __init__(self): self._interfaces = {} self.stores = zerostore.Stores()
def init_stores(): global stores assert stores is None if stores is None: stores = zerostore.Stores()
def execute_selections(selections, prog_args, dry_run=False, main=None, wrapper=None, stores=None): """Execute program. On success, doesn't return. On failure, raises an Exception. Returns normally only for a successful dry run. @param selections: the selected versions @type selections: L{selections.Selections} @param prog_args: arguments to pass to the program @type prog_args: [str] @param dry_run: if True, just print a message about what would have happened @type dry_run: bool @param main: the name of the binary to run, or None to use the default @type main: str @param wrapper: a command to use to actually run the binary, or None to run the binary directly @type wrapper: str @since: 0.27 @precondition: All implementations are in the cache. """ #assert stores is not None if stores is None: from zeroinstall import zerostore stores = zerostore.Stores() setup = Setup(stores, selections) commands = selections.commands if main is not None: # Replace first command with user's input if main.startswith('/'): main = main[ 1:] # User specified a path relative to the package root else: old_path = commands[0].path if commands else None if not old_path: raise SafeException( _("Can't use a relative replacement main when there is no original one!" )) main = os.path.join( os.path.dirname(old_path), main) # User main is relative to command's name # Copy all child nodes (e.g. <runner>) except for the arguments user_command_element = qdom.Element(namespaces.XMLNS_IFACE, 'command', {'path': main}) if commands: for child in commands[0].qdom.childNodes: if child.uri == namespaces.XMLNS_IFACE and child.name == 'arg': continue user_command_element.childNodes.append(child) user_command = Command(user_command_element, None) else: user_command = None setup.prepare_env() prog_args = setup.build_command(selections.interface, selections.command, user_command) + prog_args if wrapper: prog_args = ['/bin/sh', '-c', wrapper + ' "$@"', '-'] + list(prog_args) if dry_run: print(_("Would execute: %s") % ' '.join(prog_args)) else: logger.info(_("Executing: %s"), prog_args) sys.stdout.flush() sys.stderr.flush() try: env = os.environ.copy() for x in ['0install-runenv-ZEROINSTALL_GPG', 'ZEROINSTALL_GPG']: if x in env: del env[x] os.execve(prog_args[0], prog_args, env) except OSError as ex: raise SafeException( _("Failed to run '%(program_path)s': %(exception)s") % { 'program_path': prog_args[0], 'exception': str(ex) })
from zeroinstall import helpers from zeroinstall import zerostore from zeroinstall.injector.model import network_minimal from zeroinstall.injector import handler from zeroinstall.injector import trust trust_db = trust.TrustDB() config = load_config() config.network_use = network_minimal config.feed_mirror = None # Reads from ~/.config/0install.net/implementation-dirs - default empty # Just take default and manually append stores = zerostore.Stores() pluginStore = zerostore.Store('/results/plugins/implementations') stores.stores.append(pluginStore) class AntiTrustMgr(trust.TrustMgr): """ subclass trust.TrustMgr so we can replace the confim_keys method to accept our keys without input """ def confirm_keys(self, pending): assert pending.sigs from zeroinstall.injector import gpg valid_sigs = [s for s in pending.sigs if isinstance(s, gpg.ValidSig)] if not valid_sigs: