From 03195f9999c2024d2ed020681b81b9244cac5de0 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 3 Feb 2005 21:07:21 +0000 Subject: [PATCH] Added non-interactive injector-auto. Use it to run the graphical injector. git-svn-id: file:///home/talex/Backups/sf.net/Subversion/zero-install/injector/head@39 9f8c893c-44ee-0310-b757-c8ca8341c71e --- Makefile | 2 +- injector-gui.xml | 16 ++++++++++++++++ injector-gui/properties.py | 1 - injector.xml | 22 ++++++++++++++++++++++ injector/injector-auto | 35 +++++++++++++++++++++++++++++++++++ injector/policy.py | 10 ++++++++++ injector/reader.py | 5 ++++- injector/run.py | 1 + 8 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 injector-gui.xml create mode 100644 injector.xml create mode 100755 injector/injector-auto diff --git a/Makefile b/Makefile index d959322..e2779e5 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,4 @@ all: pychecker *.py test: - PYTHONPATH=injector ./injector-gui/injector-gui Tests/edit.xml AppRun + ./injector/injector-auto injector-gui.xml injector-gui Tests/edit.xml AppRun diff --git a/injector-gui.xml b/injector-gui.xml new file mode 100644 index 0000000..86ecacd --- /dev/null +++ b/injector-gui.xml @@ -0,0 +1,16 @@ + + + Injector-GUI + Graphical interface for the injector + + The injector GUI displays a window showing which versions of various components will be used when running a program, and allows you to alter various policy settings to affect the selection process. You can use this to mark particular versions of libraries as preferred, bugggy, etc. + + + + + + + + + + diff --git a/injector-gui/properties.py b/injector-gui/properties.py index 93ae3d2..0ccce0f 100644 --- a/injector-gui/properties.py +++ b/injector-gui/properties.py @@ -46,7 +46,6 @@ class Properties(Dialog): if resp == gtk.RESPONSE_CANCEL: self.destroy() elif resp == 1: - print "Refresh", interface import reader reader.update_from_network(interface) policy.recalculate() diff --git a/injector.xml b/injector.xml new file mode 100644 index 0000000..01932a3 --- /dev/null +++ b/injector.xml @@ -0,0 +1,22 @@ + + + Injector + Chooses software components to run programs + +A program is made up of many different components, typically written by +different groups of people. Each component is available in multiple versions. +The injector is used when starting a program. Its job is to decide which +implementation of each required component to use. + +An interface describes what a component does. The injector starts with the +interface for the program you want to run (like 'The Gimp') and chooses an +implementation (like 'The Gimp 2.2.0'). However, this implementation will in +turn depend on other interfaces, such as 'GTK' (which draws the menus and +buttons). Thus, the injector must choose implementations of each dependancy +(each of which may require further interfaces, and so on). + + + + + + diff --git a/injector/injector-auto b/injector/injector-auto new file mode 100755 index 0000000..395087d --- /dev/null +++ b/injector/injector-auto @@ -0,0 +1,35 @@ +#!/usr/bin/env python +import os, sys + +__builtins__._ = lambda x: x + +if len(sys.argv) < 3: + print "Usage: injector INTERFACE PROG [ARGS]" + print "PROG is a relative path inside an implementation of INTERFACE. Eg:" + print "injector /uri/0install/site/myprog.xml bin/myprog --help" + sys.exit(1) +interface_uri = sys.argv[1] +prog = sys.argv[2] +prog_args = sys.argv[3:] + +import model +from policy import policy + +interface = model.get_interface(interface_uri) +policy.set_root_iterface(interface) +policy.recalculate() + +import run + +try: + run.execute(interface, prog, prog_args) +except model.SafeException, ex: + print >>sys.stderr, ex + + import reader + for i in policy.walk_interfaces(): + print "Updating", i + reader.update_from_network(i) + policy.recalculate() + + run.execute(interface, prog, prog_args) diff --git a/injector/policy.py b/injector/policy.py index ff9e43c..dc600b3 100644 --- a/injector/policy.py +++ b/injector/policy.py @@ -116,6 +116,16 @@ class Policy(object): if self.network_use == network_offline and not impl.get_cached(): return True return False + + def walk_interfaces(self): + def walk(iface): + yield iface + impl = self.get_best_implementation(iface) + if impl: + for d in impl.dependencies.values(): + for id in walk(d.get_interface()): + yield id + return walk(self.root) # Singleton instance used everywhere... policy = Policy() diff --git a/injector/reader.py b/injector/reader.py index ed76066..73b803a 100644 --- a/injector/reader.py +++ b/injector/reader.py @@ -28,7 +28,10 @@ class Attrs(object): new = Attrs(self.stability, self.version, self.arch, self.path) if item.hasAttribute('path'): - new.path = os.path.join(self.path, item.getAttribute('path')) + if self.path: + new.path = os.path.join(self.path, item.getAttribute('path')) + else: + new.path = item.getAttribute('path') for x in ('arch', 'stability', 'version'): if item.hasAttribute(x): setattr(new, x, item.getAttribute(x)) diff --git a/injector/run.py b/injector/run.py index 606f7a9..5cbabca 100644 --- a/injector/run.py +++ b/injector/run.py @@ -10,6 +10,7 @@ def do_env_binding(binding, iface): os.environ[binding.name] = extra + ':' + os.environ[binding.name] else: os.environ[binding.name] = extra + #print "%s=%s" % (binding.name, os.environ[binding.name]) def execute(iface, prog, prog_args): def setup_bindings(i): -- 2.11.4.GIT