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.
8 from __future__
import print_function
12 from zeroinstall
import SafeException
, _
13 from zeroinstall
.injector
import model
14 from zeroinstall
.cmd
import UsageError
16 syntax
= "[NAME [VALUE]]"
18 def add_options(parser
):
65 raise SafeException(_('Unknown unit "%s" - use e.g. 5d for 5 days') % unit
)
74 if value
.lower() == 'true':
76 elif value
.lower() == 'false':
79 raise SafeException(_('Must be True or False, not "%s"') % value
)
82 'network_use': String
,
83 'freshness': TimeInterval
,
84 'help_with_testing': Boolean
,
85 'auto_approve_keys': Boolean
,
88 def handle(config
, options
, args
):
90 from zeroinstall
import helpers
91 if helpers
.get_selections_gui(None, [], use_gui
= options
.gui
) == helpers
.DontUseGUI
:
92 for key
, setting_type
in settings
.items():
93 value
= getattr(config
, key
)
94 print(key
, "=", setting_type
.format(value
))
95 # (else we displayed the preferences dialog in the GUI)
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()