Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / scripts / sync_sonic.py
1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Sync the Chrome source code used by Sonic to the specified directory."""
6
7 from chromite.lib import commandline
8 from chromite.lib import cros_build_lib, git
9 from chromite.buildbot import repository
10 from chromite.lib import osutils
11
12
13 def GetParser():
14   """Creates the argparse parser."""
15   parser = commandline.ArgumentParser(description=__doc__)
16
17   parser.add_argument('--reset', help='Revert local changes',
18                       action='store_true', default=False)
19   parser.add_argument('chrome_root', help='Directory to sync chrome in')
20
21   return parser
22
23
24 def main(argv):
25   parser = GetParser()
26   options = parser.parse_args(argv)
27
28   mc = git.ManifestCheckout.Cached(__file__)
29
30   # TODO(cmasone): http://crbug.com/241805 support "internal"
31   # checkouts of sonic chrome, once source access and codename issues
32   # are sorted out.
33   repo_url = (mc.remotes['sonic-partner']['fetch'] +
34               mc.FindProjectCheckout('partner/manifest')['name'])
35
36   repo = repository.RepoRepository(repo_url=repo_url,
37                                    directory=options.chrome_root)
38
39   # Revert any lingering local changes.
40   if not osutils.SafeMakedirs(options.chrome_root) and options.reset:
41     try:
42       repo.Detach()
43     except cros_build_lib.RunCommandError:
44       osutils.RmDir(options.chrome_root)
45       osutils.SafeMakedirs(options.chrome_root)
46
47   repo.Sync()
48
49   return 0