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.
9 # Copyright (C) 2006, Thomas Leonard
10 # See the README file for details, or visit http://0install.net.
13 from logging
import debug
, info
, warn
15 from zeroinstall
.support
import tasks
16 from zeroinstall
.injector
import model
, policy
, run
17 from zeroinstall
.injector
.handler
import Handler
18 from zeroinstall
import NeedDownload
20 class AutoPolicy(policy
.Policy
):
21 __slots__
= ['download_only']
23 def __init__(self
, interface_uri
, download_only
= False, dry_run
= False, src
= False, handler
= None):
24 """@param handler: (new in 0.30) handler to use, or None to create a L{Handler}"""
25 handler
= handler
or Handler()
27 info("Note: dry_run is deprecated. Pass it to the handler instead!")
28 handler
.dry_run
= True
29 policy
.Policy
.__init
__(self
, interface_uri
, handler
, src
= src
)
30 self
.download_only
= download_only
32 def execute(self
, prog_args
, main
= None, wrapper
= None):
33 downloaded
= self
.download_uncached_implementations()
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
)
39 info("Downloads done (download-only mode)")
41 def download_and_execute(self
, prog_args
, refresh
= False, main
= None):
42 refreshed
= self
.solve_with_downloads(refresh
)
44 errors
= self
.handler
.wait_for_blocker(refreshed
)
46 raise model
.SafeException("Errors during download: " + '\n'.join(errors
))
48 if not self
.solver
.ready
:
49 raise model
.SafeException("Can't find all required implementations:\n" +
50 '\n'.join(["- %s -> %s" % (iface
, self
.solver
.selections
[iface
])
51 for iface
in self
.solver
.selections
]))
52 self
.execute(prog_args
, main
= main
)