2 The B{0install config} command-line interface.
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
12 from zeroinstall
import cmd
, SafeException
, _
13 from zeroinstall
.support
import basedir
14 from zeroinstall
.injector
import policy
, namespaces
, model
15 from zeroinstall
.cmd
import UsageError
17 syntax
= "[NAME [VALUE]]"
19 def add_options(parser
):
36 return str(value
) + "s"
39 return str(value
) + "m"
42 return str(value
) + "h"
44 return str(value
) + "d"
61 raise SafeException(_('Unknown unit "%s" - use e.g. 5d for 5 days') % unit
)
70 if value
.lower() == 'true':
72 elif value
.lower() == 'false':
75 raise SafeException(_('Must be True or False, not "%s"') % value
)
78 'network_use': String
,
79 'freshness': TimeInterval
,
80 'help_with_testing': Boolean
,
83 def handle(config
, options
, args
):
85 if options
.gui
is None and os
.environ
.get('DISPLAY', None):
88 from zeroinstall
import helpers
89 return helpers
.get_selections_gui(None, [])
91 for key
, setting_type
in settings
.iteritems():
92 value
= getattr(config
, key
)
93 print key
, "=", setting_type
.format(value
)
99 if option
not in settings
:
100 raise SafeException(_('Unknown option "%s"') % option
)
103 value
= getattr(config
, option
)
104 print settings
[option
].format(value
)
106 value
= settings
[option
].parse(args
[1])
107 if option
== 'network_use' and value
not in model
.network_levels
:
108 raise SafeException(_("Must be one of %s") % list(model
.network_levels
))
109 setattr(config
, option
, value
)
111 config
.save_globals()