--get-selections with --console didn't work if we needed to download anything
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / injector / autopolicy.py
blobbd779fbe41e55976bbc685dcb0c73bcd3dfa9a05
1 """
2 A simple non-interactive policy.
4 This module provides a simple policy that will select, download and run a suitable set of
5 implementations. It is not interactive. This is the policy used when you run B{0launch -c}, and
6 is also the policy used to run the injector's GUI.
8 @deprecated: The interesting functionality has moved into the L{policy.Policy} base-class.
9 """
11 # Copyright (C) 2009, Thomas Leonard
12 # See the README file for details, or visit http://0install.net.
14 from logging import info
16 from zeroinstall.injector import model, policy, run
17 from zeroinstall.injector.handler import Handler
19 class AutoPolicy(policy.Policy):
20 __slots__ = ['download_only']
22 def __init__(self, interface_uri, download_only = False, dry_run = False, src = False, handler = None):
23 """@param handler: (new in 0.30) handler to use, or None to create a L{Handler}"""
24 handler = handler or Handler()
25 if dry_run:
26 info("Note: dry_run is deprecated. Pass it to the handler instead!")
27 handler.dry_run = True
28 policy.Policy.__init__(self, interface_uri, handler, src = src)
29 self.download_only = download_only
31 def execute(self, prog_args, main = None, wrapper = None):
32 """@deprecated"""
33 downloaded = self.download_uncached_implementations()
34 if downloaded:
35 self.handler.wait_for_blocker(downloaded)
36 if not self.download_only:
37 run.execute(self, prog_args, dry_run = self.handler.dry_run, main = main, wrapper = wrapper)
38 else:
39 info("Downloads done (download-only mode)")
41 def download_and_execute(self, prog_args, refresh = False, main = None):
42 """@deprecated: use L{solve_and_download_impls} instead"""
43 downloaded = self.solve_and_download_impls(refresh)
44 if downloaded:
45 self.handler.wait_for_blocker(downloaded)
46 self.execute(prog_args, main = main)