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
):
33 return str(value
) + "s"
36 return str(value
) + "m"
39 return str(value
) + "h"
41 return str(value
) + "d"
58 raise SafeException(_('Unknown unit "%s" - use e.g. 5d for 5 days') % unit
)
67 if value
.lower() == 'true':
69 elif value
.lower() == 'false':
72 raise SafeException(_('Must be True or False, not "%s"') % value
)
75 'network_use': String
,
76 'freshness': TimeInterval
,
77 'help_with_testing': Boolean
,
80 def handle(config
, options
, args
):
82 if options
.gui
is None and os
.environ
.get('DISPLAY', None):
85 from zeroinstall
import helpers
86 return helpers
.get_selections_gui(None, [])
88 for key
, setting_type
in settings
.iteritems():
89 value
= getattr(config
, key
)
90 print key
, "=", setting_type
.format(value
)
96 if option
not in settings
:
97 raise SafeException(_('Unknown option "%s"') % option
)
100 value
= getattr(config
, option
)
101 print settings
[option
].format(value
)
103 value
= settings
[option
].parse(args
[1])
104 if option
== 'network_use' and value
not in model
.network_levels
:
105 raise SafeException(_("Must be one of %s") % list(model
.network_levels
))
106 setattr(config
, option
, value
)
108 config
.save_globals()