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.
10 from zeroinstall
import SafeException
, _
11 from zeroinstall
.injector
import model
12 from zeroinstall
.cmd
import UsageError
14 syntax
= "[NAME [VALUE]]"
16 def add_options(parser
):
63 raise SafeException(_('Unknown unit "%s" - use e.g. 5d for 5 days') % unit
)
72 if value
.lower() == 'true':
74 elif value
.lower() == 'false':
77 raise SafeException(_('Must be True or False, not "%s"') % value
)
80 'network_use': String
,
81 'freshness': TimeInterval
,
82 'help_with_testing': Boolean
,
85 def handle(config
, options
, args
):
87 if options
.gui
is None and os
.environ
.get('DISPLAY', None):
90 from zeroinstall
import helpers
91 return helpers
.get_selections_gui(None, [])
93 for key
, setting_type
in settings
.iteritems():
94 value
= getattr(config
, key
)
95 print key
, "=", setting_type
.format(value
)
101 if option
not in settings
:
102 raise SafeException(_('Unknown option "%s"') % option
)
105 value
= getattr(config
, option
)
106 print settings
[option
].format(value
)
108 value
= settings
[option
].parse(args
[1])
109 if option
== 'network_use' and value
not in model
.network_levels
:
110 raise SafeException(_("Must be one of %s") % list(model
.network_levels
))
111 setattr(config
, option
, value
)
113 config
.save_globals()