def testBackground(self, verbose=False): p = Policy('http://example.com:8000/Hello.xml', config=self.config) self.import_feed(p.root, 'Hello.xml') p.freshness = 0 p.network_use = model.network_minimal p.solver.solve(p.root, arch.get_host_architecture()) assert p.ready, p.solver.get_failure_reason() @tasks. async def choose_download(registed_cb, nid, actions): try: assert actions == ['download', 'Download'], actions registed_cb(nid, 'download') except: import traceback traceback.print_exc() yield None global ran_gui ran_gui = False old_out = sys.stdout try: sys.stdout = StringIO() self.child = server.handle_requests('Hello.xml', '6FCF121BE2390E0B.gpg') my_dbus.system_services = { "org.freedesktop.NetworkManager": { "/org/freedesktop/NetworkManager": NetworkManager() } } my_dbus.user_callback = choose_download pid = os.getpid() old_exit = os._exit def my_exit(code): # The background handler runs in the same process # as the tests, so don't let it abort. if os.getpid() == pid: raise SystemExit(code) # But, child download processes are OK old_exit(code) from zeroinstall.injector import config key_info = config.DEFAULT_KEY_LOOKUP_SERVER config.DEFAULT_KEY_LOOKUP_SERVER = None try: try: os._exit = my_exit background.spawn_background_update(p, verbose) assert False except SystemExit as ex: self.assertEquals(1, ex.code) finally: os._exit = old_exit config.DEFAULT_KEY_LOOKUP_SERVER = key_info finally: sys.stdout = old_out assert ran_gui
def testBackground(self, verbose=False): p = Policy("http://example.com:8000/Hello.xml", config=self.config) self.import_feed(p.root, "Hello.xml") p.freshness = 0 p.network_use = model.network_minimal p.solver.solve(p.root, arch.get_host_architecture()) assert p.ready, p.solver.get_failure_reason() @tasks.async def choose_download(registed_cb, nid, actions): try: assert actions == ["download", "Download"], actions registed_cb(nid, "download") except: import traceback traceback.print_exc() yield None global ran_gui ran_gui = False old_out = sys.stdout try: sys.stdout = StringIO() self.child = server.handle_requests("Hello.xml", "6FCF121BE2390E0B.gpg") my_dbus.system_services = { "org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()} } my_dbus.user_callback = choose_download pid = os.getpid() old_exit = os._exit def my_exit(code): # The background handler runs in the same process # as the tests, so don't let it abort. if os.getpid() == pid: raise SystemExit(code) # But, child download processes are OK old_exit(code) key_info = fetch.DEFAULT_KEY_LOOKUP_SERVER fetch.DEFAULT_KEY_LOOKUP_SERVER = None try: try: os._exit = my_exit background.spawn_background_update(p, verbose) assert False except SystemExit, ex: self.assertEquals(1, ex.code) finally: os._exit = old_exit fetch.DEFAULT_KEY_LOOKUP_SERVER = key_info finally: sys.stdout = old_out assert ran_gui
def testBackground(self, verbose = False): r = Requirements('http://example.com:8000/Hello.xml') d = Driver(requirements = r, config = self.config) self.import_feed(r.interface_uri, 'Hello.xml') self.config.freshness = 0 self.config.network_use = model.network_minimal d.solver.solve(r.interface_uri, arch.get_host_architecture()) assert d.solver.ready, d.solver.get_failure_reason() @tasks.async def choose_download(registed_cb, nid, actions): try: assert actions == ['download', 'Download'], actions registed_cb(nid, 'download') except: import traceback traceback.print_exc() yield None global ran_gui ran_gui = False old_out = sys.stdout try: sys.stdout = StringIO() run_server('Hello.xml', '6FCF121BE2390E0B.gpg') my_dbus.system_services = {"org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}} my_dbus.user_callback = choose_download pid = os.getpid() old_exit = os._exit def my_exit(code): # The background handler runs in the same process # as the tests, so don't let it abort. if os.getpid() == pid: raise SystemExit(code) # But, child download processes are OK old_exit(code) from zeroinstall.injector import config key_info = config.DEFAULT_KEY_LOOKUP_SERVER config.DEFAULT_KEY_LOOKUP_SERVER = None try: try: os._exit = my_exit background.spawn_background_update(d, verbose) assert False except SystemExit as ex: self.assertEqual(1, ex.code) finally: os._exit = old_exit config.DEFAULT_KEY_LOOKUP_SERVER = key_info finally: sys.stdout = old_out assert ran_gui
def testArch(self): host_arch = arch.get_host_architecture() host_arch2 = arch.get_architecture(None, None) self.assertEquals(host_arch.os_ranks, host_arch2.os_ranks) self.assertEquals(host_arch.machine_ranks, host_arch2.machine_ranks) other = arch.get_architecture('FooBar', 'i486') self.assertEquals(2, len(other.os_ranks)) assert 'FooBar' in other.os_ranks assert None in other.os_ranks assert 'i486' in other.machine_ranks assert 'ppc' not in other.machine_ranks
def __init__(self, root = None, handler = None, src = None, command = -1, config = None, requirements = None): """ @param requirements: Details about the program we want to run @type requirements: L{requirements.Requirements} @param config: The configuration settings to use, or None to load from disk. @type config: L{ConfigParser.ConfigParser} Note: all other arguments are deprecated (since 0launch 0.52) """ self.watchers = [] if requirements is None: from zeroinstall.injector.requirements import Requirements requirements = Requirements(root) requirements.source = bool(src) # Root impl must be a "src" machine type if command == -1: if src: command = 'compile' else: command = 'run' requirements.command = command self.target_arch = arch.get_host_architecture() else: assert root == src == None assert command == -1 self.target_arch = arch.get_architecture(requirements.os, requirements.cpu) self.requirements = requirements self.stale_feeds = set() if config is None: self.config = load_config(handler or Handler()) else: assert handler is None, "can't pass a handler and a config" self.config = config from zeroinstall.injector.solver import DefaultSolver self.solver = DefaultSolver(self.config) # If we need to download something but can't because we are offline, # warn the user. But only the first time. self._warned_offline = False debug(_("Supported systems: '%s'"), arch.os_ranks) debug(_("Supported processors: '%s'"), arch.machine_ranks) if requirements.before or requirements.not_before: self.solver.extra_restrictions[config.iface_cache.get_interface(requirements.interface_uri)] = [ model.VersionRangeRestriction(model.parse_version(requirements.before), model.parse_version(requirements.not_before))]
def testBackground(self, verbose=False): r = Requirements('http://example.com:8000/Hello.xml') d = Driver(requirements=r, config=self.config) self.import_feed(r.interface_uri, 'Hello.xml') self.config.freshness = 0 self.config.network_use = model.network_minimal d.solver.solve(r.interface_uri, arch.get_host_architecture()) assert d.solver.ready, d.solver.get_failure_reason() @tasks. async def choose_download(registed_cb, nid, actions): try: assert actions == ['download', 'Download'], actions registed_cb(nid, 'download') except: import traceback traceback.print_exc() yield None global ran_gui ran_gui = False os.environ['DISPLAY'] = 'dummy' old_out = sys.stdout try: sys.stdout = StringIO() run_server('Hello.xml', '6FCF121BE2390E0B.gpg') my_dbus.system_services = { "org.freedesktop.NetworkManager": { "/org/freedesktop/NetworkManager": NetworkManager() } } my_dbus.user_callback = choose_download with trapped_exit(1): from zeroinstall.injector import config key_info = config.DEFAULT_KEY_LOOKUP_SERVER config.DEFAULT_KEY_LOOKUP_SERVER = None try: background.spawn_background_update(d, verbose) finally: config.DEFAULT_KEY_LOOKUP_SERVER = key_info finally: sys.stdout = old_out assert ran_gui
def testBackground(self, verbose = False): r = Requirements('http://example.com:8000/Hello.xml') d = Driver(requirements = r, config = self.config) self.import_feed(r.interface_uri, 'Hello.xml') self.config.freshness = 0 self.config.network_use = model.network_minimal d.solver.solve(r.interface_uri, arch.get_host_architecture()) assert d.solver.ready, d.solver.get_failure_reason() @tasks.async def choose_download(registed_cb, nid, actions): try: assert actions == ['download', 'Download'], actions registed_cb(nid, 'download') except: import traceback traceback.print_exc() yield None global ran_gui ran_gui = False os.environ['DISPLAY'] = 'dummy' old_out = sys.stdout try: sys.stdout = StringIO() run_server('Hello.xml', '6FCF121BE2390E0B.gpg') my_dbus.system_services = {"org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}} my_dbus.user_callback = choose_download with trapped_exit(1): from zeroinstall.injector import config key_info = config.DEFAULT_KEY_LOOKUP_SERVER config.DEFAULT_KEY_LOOKUP_SERVER = None try: background.spawn_background_update(d, verbose) finally: config.DEFAULT_KEY_LOOKUP_SERVER = key_info finally: sys.stdout = old_out assert ran_gui
class Policy(object): """Chooses a set of implementations based on a policy. Typical use: 1. Create a Policy object, giving it the URI of the program to be run and a handler. 2. Call L{solve_with_downloads}. If more information is needed, a L{fetch.Fetcher} will be used to download it. 3. When all downloads are complete, the L{solver} contains the chosen versions. 4. Use L{get_uncached_implementations} to find where to get these versions and download them using L{download_uncached_implementations}. @ivar target_arch: target architecture for binaries @type target_arch: L{arch.Architecture} @ivar root: URI of the root interface @ivar solver: solver used to choose a set of implementations @type solver: L{solve.Solver} @ivar watchers: callbacks to invoke after recalculating @ivar help_with_testing: default stability policy @type help_with_testing: bool @ivar network_use: one of the model.network_* values @ivar freshness: seconds allowed since last update @type freshness: int @ivar handler: handler for main-loop integration @type handler: L{handler.Handler} @ivar src: whether we are looking for source code @type src: bool @ivar stale_feeds: set of feeds which are present but haven't been checked for a long time @type stale_feeds: set """ __slots__ = ['root', 'watchers', 'freshness', 'handler', '_warned_offline', 'target_arch', 'src', 'stale_feeds', 'solver', '_fetcher'] help_with_testing = property(lambda self: self.solver.help_with_testing, lambda self, value: setattr(self.solver, 'help_with_testing', value)) network_use = property(lambda self: self.solver.network_use, lambda self, value: setattr(self.solver, 'network_use', value)) implementation = property(lambda self: self.solver.selections) ready = property(lambda self: self.solver.ready) def __init__(self, root, handler = None, src = False): """ @param root: The URI of the root interface (the program we want to run). @param handler: A handler for main-loop integration. @type handler: L{zeroinstall.injector.handler.Handler} @param src: Whether we are looking for source code. @type src: bool """ self.watchers = [] self.freshness = 60 * 60 * 24 * 30 self.src = src # Root impl must be a "src" machine type self.stale_feeds = set() from zeroinstall.injector.solver import DefaultSolver self.solver = DefaultSolver(network_full, iface_cache, iface_cache.stores) # If we need to download something but can't because we are offline, # warn the user. But only the first time. self._warned_offline = False self._fetcher = None # (allow self for backwards compat) self.handler = handler or self debug(_("Supported systems: '%s'"), arch.os_ranks) debug(_("Supported processors: '%s'"), arch.machine_ranks) path = basedir.load_first_config(config_site, config_prog, 'global') if path: try: config = ConfigParser.ConfigParser() config.read(path) self.solver.help_with_testing = config.getboolean('global', 'help_with_testing') self.solver.network_use = config.get('global', 'network_use') self.freshness = int(config.get('global', 'freshness')) assert self.solver.network_use in network_levels, self.solver.network_use except Exception, ex: warn(_("Error loading config: %s"), str(ex) or repr(ex)) self.set_root(root) self.target_arch = arch.get_host_architecture()