Made a proper Config object
[zeroinstall/zeroinstall-afb.git] / zeroinstall / cmd / run.py
blob20fc3ecb2ab79154048241c4531745cf55ed3ca9
1 """
2 The B{0install run} command-line interface.
3 """
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 from optparse import OptionParser
9 import os, sys
10 import logging
12 from zeroinstall import cmd, SafeException, _
13 from zeroinstall.cmd import UsageError, select
14 from zeroinstall.injector import model, autopolicy, selections, handler
16 syntax = "URI [ARGS]"
18 def add_options(parser):
19 select.add_generic_select_options(parser)
20 parser.add_option("-m", "--main", help=_("name of the file to execute"))
21 parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND')
22 parser.disable_interspersed_args()
24 def handle(config, options, args):
25 if len(args) < 1:
26 raise UsageError()
27 iface_uri = model.canonical_iface_uri(args[0])
28 prog_args = args[1:]
30 def test_callback(sels):
31 from zeroinstall.injector import run
32 return run.test_selections(sels, prog_args,
33 False, # dry-run
34 options.main)
36 sels = select.get_selections(config, options, iface_uri,
37 select_only = False, download_only = False,
38 test_callback = test_callback)
39 if not sels:
40 sys.exit(1) # Aborted by user
42 from zeroinstall.injector import run
43 run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)