33
33
from systemimage.config import config
34
34
from systemimage.helpers import last_update_date, makedirs, version_detail
35
35
from systemimage.logging import initialize
36
from systemimage.reboot import factory_reset
37
from systemimage.settings import Settings
36
38
from systemimage.state import State
37
39
from textwrap import dedent
78
80
full updates or only delta updates. The
79
81
argument to this option must be either `full`
83
parser.add_argument('-g', '--no-reboot',
84
default=False, action='store_true',
85
help="""Download (i.e. "get") all the data files and
86
prepare for updating, but don't actually
87
reboot the device into recovery to apply the
81
89
parser.add_argument('-i', '--info',
82
90
default=False, action='store_true',
83
91
help="""Show some information about the current
90
98
parser.add_argument('-v', '--verbose',
91
99
default=0, action='count',
92
100
help='Increase verbosity')
101
parser.add_argument('--list-channels',
102
default=False, action='store_true',
103
help="""List all available channels, then exit""")
104
parser.add_argument('--factory-reset',
105
default=False, action='store_true',
106
help="""Perform a destructive factory reset and
107
reboot. WARNING: this will wipe all user data
109
parser.add_argument('--switch',
110
default=None, action='store', metavar='CHANNEL',
111
help="""Switch to the given channel. This is
112
equivalent to `-c CHANNEL -b 0`.""")
114
parser.add_argument('--show-settings',
115
default=False, action='store_true',
116
help="""Show all settings as key=value pairs,
118
parser.add_argument('--set',
119
default=[], action='append', metavar='KEY=VAL',
120
help="""Set a key and value in the settings, adding
121
the key if it doesn't yet exist, or overriding
122
its value if the key already exists. Multiple
123
--set arguments can be given.""")
124
parser.add_argument('--get',
125
default=[], action='append', metavar='KEY',
126
help="""Get the value for a key. If the key does not
127
exist, a default value is returned. Multiple
128
--get arguments can be given.""")
129
parser.add_argument('--del',
130
default=[], action='append',
131
metavar='KEY', dest='delete',
132
help="""Delete the key and its value. It is a no-op
133
if the key does not exist. Multiple
134
--del arguments can be given.""")
94
136
args = parser.parse_args(sys.argv[1:])
105
147
except FileNotFoundError:
150
# Perform a factory reset.
151
if args.factory_reset:
153
# We should never get here, except possibly during the testing
154
# process, so just return as normal.
157
# Handle all settings arguments. They are mutually exclusive.
158
if sum(bool(arg) for arg in
159
(args.set, args.get, args.delete, args.show_settings)) > 1:
160
parser.error('Cannot mix and match settings arguments')
161
assert 'parser.error() does not return'
163
if args.show_settings:
164
rows = sorted(Settings())
166
print('{}={}'.format(*row))
169
settings = Settings()
171
print(settings.get(key))
174
settings = Settings()
175
for keyval in args.set:
176
key, val = keyval.split('=', 1)
177
settings.set(key, val)
180
settings = Settings()
181
for key in args.delete:
108
185
# Sanity check -f/--filter.
109
186
if args.filter is None:
110
187
candidate_filter = None
124
201
# We assume the cache_partition already exists, as does the /etc directory
125
202
# (i.e. where the archive master key lives).
127
# Command line overrides.
204
# Command line overrides. Process --switch first since if both it and
205
# -c/-b are given, the latter take precedence.
206
if args.switch is not None:
207
config.build_number = 0
208
config.channel = args.switch
128
209
if args.build is not None:
130
211
config.build_number = int(args.build)
168
249
print('version {}: {}'.format(key, details[key]))
252
if args.list_channels:
255
state.run_thru('get_channel')
257
log.exception('system-image-cli exception')
259
print('Available channels:')
260
for key in sorted(state.channels):
261
alias = state.channels[key].get('alias')
263
print(' {}'.format(key))
265
print(' {} (alias for: {})'.format(key, alias))
171
268
# We can either run the API directly or through DBus.
173
270
client = DBusClient()