blob: 5384911ee07af14e68b699f02cebaecdbf1f02b4 [file] [log] [blame]
Kuang-che Wu41e8b592018-09-25 17:01:30 +08001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3# Copyright 2018 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6"""Helper script to prepare source trees for ChromeOS bisection.
7
8Typical usage:
9
10 Initial setup:
11 $ %(prog)s init --chromeos
12 $ %(prog)s init --chrome
13 $ %(prog)s init --android=pi-arc-dev
14
15 Sync code if necessary:
16 $ %(prog)s sync
17
18 Create source trees for bisection
19 $ %(prog)s new --session=12345
20
21 After bisection finished, delete trees
22 $ %(prog)s delete --session=12345
23"""
24from __future__ import print_function
25import argparse
26import csv
27import logging
28import os
Kuang-che Wu67be74b2018-10-15 14:17:26 +080029import time
Kuang-che Wu41e8b592018-09-25 17:01:30 +080030import urllib2
Kuang-che Wu67be74b2018-10-15 14:17:26 +080031import urlparse
Kuang-che Wu41e8b592018-09-25 17:01:30 +080032
33from bisect_kit import common
34from bisect_kit import configure
35from bisect_kit import gclient_util
36from bisect_kit import git_util
Kuang-che Wudc714412018-10-17 16:06:39 +080037from bisect_kit import locking
Kuang-che Wu41e8b592018-09-25 17:01:30 +080038from bisect_kit import repo_util
39from bisect_kit import util
40
41DEFAULT_MIRROR_BASE = os.path.expanduser('~/git-mirrors')
42DEFAULT_WORK_BASE = os.path.expanduser('~/bisect-workdir')
43CHECKOUT_TEMPLATE_NAME = 'template'
44
45logger = logging.getLogger(__name__)
46
47
48class DefaultProjectPathFactory(object):
49 """Factory for chromeos/chrome/android source tree paths."""
50
51 def __init__(self, mirror_base, work_base, session):
52 self.mirror_base = mirror_base
53 self.work_base = work_base
54 self.session = session
55
56 def get_chromeos_mirror(self):
57 return os.path.join(self.mirror_base, 'chromeos')
58
59 def get_chromeos_tree(self):
60 return os.path.join(self.work_base, self.session, 'chromeos')
61
62 def get_android_mirror(self, branch):
63 return os.path.join(self.mirror_base, 'android.%s' % branch)
64
65 def get_android_tree(self, branch):
66 return os.path.join(self.work_base, self.session, 'android.%s' % branch)
67
68 def get_chrome_cache(self):
69 return os.path.join(self.mirror_base, 'chrome')
70
71 def get_chrome_tree(self):
72 return os.path.join(self.work_base, self.session, 'chrome')
73
74
75def subvolume_or_makedirs(opts, path):
76 if os.path.exists(path):
77 return
78
79 path = os.path.abspath(path)
80 if opts.btrfs:
81 dirname, basename = os.path.split(path)
82 if not os.path.exists(dirname):
83 os.makedirs(dirname)
84 util.check_call('btrfs', 'subvolume', 'create', basename, cwd=dirname)
85 else:
86 os.makedirs(path)
87
88
89def is_btrfs_subvolume(path):
90 if util.check_output('stat', '-f', '--format=%T', path).strip() != 'btrfs':
91 return False
92 return util.check_output('stat', '--format=%i', path).strip() == '256'
93
94
95def snapshot_or_copytree(src, dst):
96 assert os.path.isdir(src), '%s does not exist' % src
97 assert os.path.isdir(os.path.dirname(dst))
98
99 # Make sure dst do not exist, otherwise it becomes "dst/name" (one extra
100 # depth) instead of "dst".
101 assert not os.path.exists(dst)
102
103 if is_btrfs_subvolume(src):
104 util.check_call('btrfs', 'subvolume', 'snapshot', src, dst)
105 else:
106 # -a for recursion and preserve all attributes.
107 util.check_call('cp', '-a', src, dst)
108
109
Kuang-che Wubfa64482018-10-16 11:49:49 +0800110def collect_removed_manifest_repos(repo_dir, last_sync_time, only_branch=None):
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800111 manifest_dir = os.path.join(repo_dir, '.repo', 'manifests')
Kuang-che Wu16cd6e22018-10-17 12:06:12 +0800112 util.check_call('git', 'fetch', cwd=manifest_dir)
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800113
114 manifest_path = 'default.xml'
115 manifest_full_path = os.path.join(manifest_dir, manifest_path)
116 # hack for chromeos symlink
117 if os.path.islink(manifest_full_path):
118 manifest_path = os.readlink(manifest_full_path)
119
120 parser = repo_util.ManifestParser(manifest_dir)
121 latest = None
122 removed = {}
123 for _, git_rev in reversed(
124 parser.enumerate_manifest_commits(last_sync_time, None, manifest_path)):
125 root = parser.parse_xml_recursive(git_rev, manifest_path)
Kuang-che Wubfa64482018-10-16 11:49:49 +0800126 if (only_branch and root.find('default') is not None and
127 root.find('default').get('revision') != only_branch):
128 break
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800129 entries = parser.process_parsed_result(root)
130 if latest is None:
131 assert entries is not None
132 latest = entries
133 continue
134
135 for path, path_spec in entries.items():
136 if path in latest:
137 continue
138 if path in removed:
139 continue
140 removed[path] = path_spec
141
142 return removed
143
144
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800145def setup_chromeos_repos(opts, path_factory):
146 chromeos_mirror = path_factory.get_chromeos_mirror()
147 chromeos_tree = path_factory.get_chromeos_tree()
148 subvolume_or_makedirs(opts, chromeos_mirror)
149 subvolume_or_makedirs(opts, chromeos_tree)
150
151 manifest_url = (
152 'https://chrome-internal.googlesource.com/chromeos/manifest-internal')
153 repo_url = 'https://chromium.googlesource.com/external/repo.git'
154
155 if os.path.exists(os.path.join(chromeos_mirror, '.repo', 'manifests')):
156 logger.warning(
157 '%s has already been initialized, assume it is setup properly',
158 chromeos_mirror)
159 else:
160 logger.info('repo init for chromeos mirror')
161 repo_util.init(
162 chromeos_mirror,
163 manifest_url=manifest_url,
164 repo_url=repo_url,
165 mirror=True)
166
167 local_manifest_dir = os.path.join(chromeos_mirror, '.repo',
168 'local_manifests')
169 os.mkdir(local_manifest_dir)
170 with open(os.path.join(local_manifest_dir, 'manifest-versions.xml'),
171 'w') as f:
172 f.write('''<?xml version="1.0" encoding="UTF-8"?>
173 <manifest>
174 <project name="chromeos/manifest-versions" remote="cros-internal" />
175 </manifest>
176 ''')
177
178 logger.info('repo init for chromeos tree')
179 repo_util.init(
180 chromeos_tree,
181 manifest_url=manifest_url,
182 repo_url=repo_url,
183 reference=chromeos_mirror)
184
Kuang-che Wudc714412018-10-17 16:06:39 +0800185 with locking.lock_file(
186 os.path.join(chromeos_mirror, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
187 logger.info('repo sync for chromeos mirror (this takes hours; be patient)')
188 repo_util.sync(chromeos_mirror)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800189
190 logger.info('repo sync for chromeos tree')
191 repo_util.sync(chromeos_tree)
192
193
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800194def read_last_sync_time(repo_dir):
195 timestamp_path = os.path.join(repo_dir, 'last_sync_time')
196 if os.path.exists(timestamp_path):
197 with open(timestamp_path) as f:
198 return int(f.read())
199 else:
200 # 4 months should be enough for most bisect cases.
201 return int(time.time()) - 86400 * 120
202
203
204def write_sync_time(repo_dir, sync_time):
205 timestamp_path = os.path.join(repo_dir, 'last_sync_time')
206 with open(timestamp_path, 'w') as f:
207 f.write('%d\n' % sync_time)
208
209
210def write_extra_manifest_to_mirror(repo_dir, removed):
211 local_manifest_dir = os.path.join(repo_dir, '.repo', 'local_manifests')
212 if not os.path.exists(local_manifest_dir):
213 os.mkdir(local_manifest_dir)
214 with open(os.path.join(local_manifest_dir, 'deleted-repos.xml'), 'w') as f:
215 f.write('''<?xml version="1.0" encoding="UTF-8"?>\n<manifest>\n''')
216 remotes = {}
217 for path_spec in removed.values():
218 scheme, netloc, remote_path = urlparse.urlsplit(path_spec.repo_url)[:3]
219 assert remote_path[0] == '/'
220 remote_path = remote_path[1:]
221 if (scheme, netloc) not in remotes:
222 remote_name = 'remote_for_deleted_repo_%s' % (scheme + netloc)
223 remotes[scheme, netloc] = remote_name
224 f.write(''' <remote name="%s" fetch="%s" />\n''' %
225 (remote_name, '%s://%s' % (scheme, netloc)))
Kuang-che Wubfa64482018-10-16 11:49:49 +0800226 f.write(
227 ''' <project name="%s" path="%s" remote="%s" revision="%s" />\n''' %
228 (remote_path, path_spec.path, remotes[scheme, netloc], path_spec.at))
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800229 f.write('''</manifest>\n''')
230
231
Kuang-che Wubfa64482018-10-16 11:49:49 +0800232def generate_extra_manifest_for_deleted_repo(repo_dir, only_branch=None):
233 last_sync_time = read_last_sync_time(repo_dir)
234 removed = collect_removed_manifest_repos(
235 repo_dir, last_sync_time, only_branch=only_branch)
236 write_extra_manifest_to_mirror(repo_dir, removed)
237 logger.info('since last sync, %d repo got removed', len(removed))
238
239
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800240def sync_chromeos_code(opts, path_factory):
241 del opts # unused
242
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800243 start_sync_time = int(time.time())
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800244 chromeos_mirror = path_factory.get_chromeos_mirror()
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800245
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800246 logger.info('repo sync for chromeos mirror')
Kuang-che Wubfa64482018-10-16 11:49:49 +0800247 generate_extra_manifest_for_deleted_repo(chromeos_mirror)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800248 repo_util.sync(chromeos_mirror)
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800249 write_sync_time(chromeos_mirror, start_sync_time)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800250
251 logger.info('repo sync for chromeos tree')
252 chromeos_tree = path_factory.get_chromeos_tree()
253 repo_util.sync(chromeos_tree)
254
255 # test_that may use this ssh key and ssh complains its permission is too open
256 util.check_call(
257 'chmod',
258 'o-r,g-r',
259 'src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa',
260 cwd=chromeos_tree)
261
262
263def query_chrome_latest_branch():
264 result = None
265 r = urllib2.urlopen('https://omahaproxy.appspot.com/all')
266 for row in csv.DictReader(r):
267 if row['true_branch'].isdigit():
268 result = max(result, int(row['true_branch']))
269 return result
270
271
272def setup_chrome_repos(opts, path_factory):
273 chrome_cache = path_factory.get_chrome_cache()
274 subvolume_or_makedirs(opts, chrome_cache)
275 chrome_tree = path_factory.get_chrome_tree()
276 subvolume_or_makedirs(opts, chrome_tree)
277
278 latest_branch = query_chrome_latest_branch()
279 logger.info('latest chrome branch is %d', latest_branch)
280 assert latest_branch
281 spec = '''
282solutions = [
283 { "name" : "buildspec",
284 "url" : "https://chrome-internal.googlesource.com/a/chrome/tools/buildspec.git",
285 "deps_file" : "branches/%d/DEPS",
286 "custom_deps" : {
287 },
288 "custom_vars": {'checkout_src_internal': True},
289 },
290]
291target_os = ['chromeos']
292cache_dir = %r
293''' % (latest_branch, chrome_cache)
294
Kuang-che Wudc714412018-10-17 16:06:39 +0800295 with locking.lock_file(
296 os.path.join(chrome_cache, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
297 logger.info('gclient config for chrome')
298 gclient_util.config(chrome_tree, spec=spec)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800299
Kuang-che Wudc714412018-10-17 16:06:39 +0800300 is_first_sync = not os.listdir(chrome_cache)
301 if is_first_sync:
302 logger.info('gclient sync for chrome (this takes hours; be patient)')
303 else:
304 logger.info('gclient sync for chrome')
305 gclient_util.sync(
306 chrome_tree, with_branch_heads=True, with_tags=True, ignore_locks=True)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800307
Kuang-che Wudc714412018-10-17 16:06:39 +0800308 # It's possible that some repos are removed from latest branch and thus
309 # their commit history is not fetched in recent gclient sync. So we call
310 # 'git fetch' for all existing git mirrors.
311 # TODO(kcwu): only sync repos not in DEPS files of latest branch
312 logger.info('additional sync for chrome mirror')
313 for git_repo_name in os.listdir(chrome_cache):
314 # another gclient is running or leftover of previous run; skip
315 if git_repo_name.startswith('_cache_tmp'):
316 continue
317 git_repo = os.path.join(chrome_cache, git_repo_name)
318 if not git_util.is_git_rev(git_repo):
319 continue
320 util.check_call('git', 'fetch', cwd=git_repo)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800321
Kuang-che Wu1e49f512018-12-06 15:27:42 +0800322 # Some repos were removed from the DEPS and won't be synced here. They will
323 # be synced during DEPS file processing because the necessary information
324 # requires full DEPS parsing. (crbug.com/902238)
325
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800326
327def sync_chrome_code(opts, path_factory):
328 # The sync step is identical to the initial gclient config step.
329 setup_chrome_repos(opts, path_factory)
330
331
332def setup_android_repos(opts, path_factory, branch):
333 android_mirror = path_factory.get_android_mirror(branch)
334 android_tree = path_factory.get_android_tree(branch)
335 subvolume_or_makedirs(opts, android_mirror)
336 subvolume_or_makedirs(opts, android_tree)
337
338 manifest_url = ('persistent-https://googleplex-android.git.corp.google.com'
339 '/platform/manifest')
340 repo_url = 'https://gerrit.googlesource.com/git-repo'
341
342 if os.path.exists(os.path.join(android_mirror, '.repo', 'manifests')):
343 logger.warning(
344 '%s has already been initialized, assume it is setup properly',
345 android_mirror)
346 else:
347 logger.info('repo init for android mirror branch=%s', branch)
348 repo_util.init(
349 android_mirror,
350 manifest_url=manifest_url,
351 repo_url=repo_url,
352 manifest_branch=branch,
353 mirror=True)
354
355 logger.info('repo init for android tree branch=%s', branch)
356 repo_util.init(
357 android_tree,
358 manifest_url=manifest_url,
359 repo_url=repo_url,
360 manifest_branch=branch,
361 reference=android_mirror)
362
363 logger.info('repo sync for android mirror (this takes hours; be patient)')
364 repo_util.sync(android_mirror, current_branch=True)
365
366 logger.info('repo sync for android tree branch=%s', branch)
367 repo_util.sync(android_tree, current_branch=True)
368
369
370def sync_android_code(opts, path_factory, branch):
371 del opts # unused
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800372 start_sync_time = int(time.time())
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800373 android_mirror = path_factory.get_android_mirror(branch)
374 android_tree = path_factory.get_android_tree(branch)
375
Kuang-che Wudc714412018-10-17 16:06:39 +0800376 with locking.lock_file(
377 os.path.join(android_mirror, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
378 logger.info('repo sync for android mirror branch=%s', branch)
379 # Android usually big jump between milestone releases and add/delete lots of
380 # repos when switch releases. Because it's infeasible to bisect between such
381 # big jump, the deleted repo is useless. In order to save disk, do not sync
382 # repos deleted in other branches.
383 generate_extra_manifest_for_deleted_repo(android_mirror, only_branch=branch)
384 repo_util.sync(android_mirror, current_branch=True)
385 write_sync_time(android_mirror, start_sync_time)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800386
387 logger.info('repo sync for android tree branch=%s', branch)
388 repo_util.sync(android_tree, current_branch=True)
389
390
391def cmd_init(opts):
392 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
393 CHECKOUT_TEMPLATE_NAME)
394
395 if opts.chromeos:
396 setup_chromeos_repos(opts, path_factory)
397 if opts.chrome:
398 setup_chrome_repos(opts, path_factory)
399 for branch in opts.android:
400 setup_android_repos(opts, path_factory, branch)
401
402
403def enumerate_android_branches_available(base):
404 branches = []
405 for name in os.listdir(base):
406 if name.startswith('android.'):
407 branches.append(name.partition('.')[2])
408 return branches
409
410
411def cmd_sync(opts):
412 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
413 CHECKOUT_TEMPLATE_NAME)
414
415 sync_all = False
416 if not opts.chromeos and not opts.chrome and not opts.android:
417 logger.info('sync trees for all')
418 sync_all = True
419
420 if sync_all or opts.chromeos:
421 sync_chromeos_code(opts, path_factory)
422 if sync_all or opts.chrome:
423 sync_chrome_code(opts, path_factory)
424
425 if sync_all:
426 android_branches = enumerate_android_branches_available(opts.mirror_base)
427 else:
428 android_branches = opts.android
429 for branch in android_branches:
430 sync_android_code(opts, path_factory, branch)
431
432
433def cmd_new(opts):
434 work_dir = os.path.join(opts.work_base, opts.session)
435 if not os.path.exists(work_dir):
436 os.makedirs(work_dir)
437
438 template_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
439 CHECKOUT_TEMPLATE_NAME)
440 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
441 opts.session)
442
443 prepare_all = False
444 if not opts.chromeos and not opts.chrome and not opts.android:
445 logger.info('prepare trees for all')
446 prepare_all = True
447
448 chromeos_template = template_factory.get_chromeos_tree()
449 if (prepare_all and os.path.exists(chromeos_template)) or opts.chromeos:
450 logger.info('prepare tree for chromeos, %s',
451 path_factory.get_chromeos_tree())
452 snapshot_or_copytree(chromeos_template, path_factory.get_chromeos_tree())
453
454 chrome_template = template_factory.get_chrome_tree()
455 if (prepare_all and os.path.exists(chrome_template)) or opts.chrome:
456 logger.info('prepare tree for chrome, %s', path_factory.get_chrome_tree())
457 snapshot_or_copytree(chrome_template, path_factory.get_chrome_tree())
458
459 if prepare_all:
460 android_branches = enumerate_android_branches_available(opts.mirror_base)
461 else:
462 android_branches = opts.android
463 for branch in android_branches:
464 logger.info('prepare tree for android branch=%s, %s', branch,
465 path_factory.get_android_tree(branch))
466 snapshot_or_copytree(
467 template_factory.get_android_tree(branch),
468 path_factory.get_android_tree(branch))
469
470
471def delete_tree(path):
472 if is_btrfs_subvolume(path):
473 util.check_call('btrfs', 'subvolume', 'delete', path)
474 else:
475 util.check_call('rm', '-rf', path)
476
477
478def cmd_list(opts):
479 print('%-20s %s' % ('Session', 'Path'))
480 for name in os.listdir(opts.work_base):
481 if name == CHECKOUT_TEMPLATE_NAME:
482 continue
483 path = os.path.join(opts.work_base, name)
484 print('%-20s %s' % (name, path))
485
486
487def cmd_delete(opts):
488 assert opts.session
489 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
490 opts.session)
491
492 chromeos_tree = path_factory.get_chromeos_tree()
493 if os.path.exists(chromeos_tree):
494 if os.path.exists(os.path.join(chromeos_tree, 'chromite')):
495 # ignore error
496 util.call('cros_sdk', '--unmount', cwd=chromeos_tree)
497 delete_tree(chromeos_tree)
498
499 chrome_tree = path_factory.get_chrome_tree()
500 if os.path.exists(chrome_tree):
501 delete_tree(chrome_tree)
502
503 android_branches = enumerate_android_branches_available(opts.mirror_base)
504 for branch in android_branches:
505 android_tree = path_factory.get_android_tree(branch)
506 if os.path.exists(android_tree):
507 delete_tree(android_tree)
508
509 os.rmdir(os.path.join(opts.work_base, opts.session))
510
511
512def create_parser():
513 parser = argparse.ArgumentParser(
514 formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__)
515 parser.add_argument(
516 '--mirror_base',
517 metavar='MIRROR_BASE',
518 default=configure.get('MIRROR_BASE', DEFAULT_MIRROR_BASE),
519 help='Directory for mirrors (default: %(default)s)')
520 parser.add_argument(
521 '--work_base',
522 metavar='WORK_BASE',
523 default=configure.get('WORK_BASE', DEFAULT_WORK_BASE),
524 help='Directory for bisection working directories (default: %(default)s)')
525 common.add_common_arguments(parser)
526 subparsers = parser.add_subparsers(
527 dest='command', title='commands', metavar='<command>')
528
529 parser_init = subparsers.add_parser(
530 'init', help='Mirror source trees and create template checkout')
531 parser_init.add_argument(
532 '--chrome', action='store_true', help='init chrome mirror and tree')
533 parser_init.add_argument(
534 '--chromeos', action='store_true', help='init chromeos mirror and tree')
535 parser_init.add_argument(
536 '--android',
537 metavar='BRANCH',
538 action='append',
539 default=[],
540 help='init android mirror and tree of BRANCH')
541 parser_init.add_argument(
542 '--btrfs',
543 action='store_true',
544 help='create btrfs subvolume for source tree')
545 parser_init.set_defaults(func=cmd_init)
546
547 parser_sync = subparsers.add_parser(
548 'sync',
549 help='Sync source trees',
550 description='Sync all if no projects are specified '
551 '(--chrome, --chromeos, or --android)')
552 parser_sync.add_argument(
553 '--chrome', action='store_true', help='sync chrome mirror and tree')
554 parser_sync.add_argument(
555 '--chromeos', action='store_true', help='sync chromeos mirror and tree')
556 parser_sync.add_argument(
557 '--android',
558 metavar='BRANCH',
559 action='append',
560 default=[],
561 help='sync android mirror and tree of BRANCH')
562 parser_sync.set_defaults(func=cmd_sync)
563
564 parser_new = subparsers.add_parser(
565 'new',
566 help='Create new source checkout for bisect',
567 description='Create for all if no projects are specified '
568 '(--chrome, --chromeos, or --android)')
569 parser_new.add_argument('--session', required=True)
570 parser_new.add_argument(
571 '--chrome', action='store_true', help='create chrome checkout')
572 parser_new.add_argument(
573 '--chromeos', action='store_true', help='create chromeos checkout')
574 parser_new.add_argument(
575 '--android',
576 metavar='BRANCH',
577 action='append',
578 default=[],
579 help='create android checkout of BRANCH')
580 parser_new.set_defaults(func=cmd_new)
581
582 parser_list = subparsers.add_parser(
583 'list', help='List existing sessions with source checkout')
584 parser_list.set_defaults(func=cmd_list)
585
586 parser_delete = subparsers.add_parser('delete', help='Delete source checkout')
587 parser_delete.add_argument('--session', required=True)
588 parser_delete.set_defaults(func=cmd_delete)
589
590 return parser
591
592
593def main():
594 common.init()
595 parser = create_parser()
596 opts = parser.parse_args()
597 common.config_logging(opts)
598
599 opts.func(opts)
600
601
602if __name__ == '__main__':
603 main()