Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 # | 5 # |
| 6 # Usage: | 6 # Usage: |
| 7 # gclient-new-workdir.py <repository> <new_workdir> [<branch>] | 7 # gclient-new-workdir.py <repository> <new_workdir> [<branch>] |
| 8 # | 8 # |
| 9 | 9 |
| 10 import os | 10 import os |
| 11 import shutil | 11 import shutil |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 | 15 |
| 16 def parse_options(argv): | 16 def parse_options(argv): |
| 17 assert not sys.platform.startswith("win") | 17 if sys.platform == "win32": |
| 18 print >> sys.stderr, ("This script cannot run on Windows because it uses" | |
| 19 "symlinks.") | |
|
iannucci
2013/11/13 17:57:30
As M-A pointed out, could convert all "" quoted st
| |
| 20 sys.exit(1) | |
| 18 | 21 |
| 19 if len(argv) != 3: | 22 if len(argv) != 3: |
| 20 print("usage: gclient-new-workdir.py <repository> <new_workdir>") | 23 print("""usage: gclient-new-workdir.py <repository> <new_workdir> |
| 24 | |
| 25 Clone an existing gclient directory, taking care of all sub-repositories | |
|
M-A Ruel
2013/11/13 17:17:33
You want the text to be +4 at output?
iannucci
2013/11/13 17:57:30
I think you want to pass this string through http:
| |
| 26 Works similarly to 'git new-workdir'. | |
| 27 | |
| 28 <repository> must be a absolute path | |
| 29 <new_workdir> must not exist | |
| 30 """) | |
| 21 sys.exit(1) | 31 sys.exit(1) |
| 22 | 32 |
| 23 repository = argv[1] | 33 repository = os.path.abspath(argv[1]) |
| 24 new_workdir = argv[2] | 34 new_workdir = argv[2] |
| 25 | 35 |
| 26 if not os.path.exists(repository): | 36 if not os.path.exists(repository): |
| 27 print("Repository does not exist: " + repository) | 37 print >> sys.stderr, ("Repository does not exist: " + repository) |
| 28 sys.exit(1) | 38 sys.exit(1) |
| 29 | 39 |
| 30 if os.path.exists(new_workdir): | 40 if os.path.exists(new_workdir): |
| 31 print("New workdir already exists: " + new_workdir) | 41 print >> sys.stderr, ("New workdir already exists: " + new_workdir) |
|
iannucci
2013/11/13 17:57:30
What do you think about a print_err function do th
| |
| 32 sys.exit(1) | 42 sys.exit(1) |
| 33 | 43 |
| 34 return repository, new_workdir | 44 return repository, new_workdir |
| 35 | 45 |
| 36 | 46 |
| 37 def main(argv): | 47 def main(argv): |
| 38 repository, new_workdir = parse_options(argv) | 48 repository, new_workdir = parse_options(argv) |
| 39 | 49 |
| 40 gclient = os.path.join(repository, ".gclient") | 50 gclient = os.path.join(repository, ".gclient") |
| 41 if not os.path.exists(gclient): | 51 if not os.path.exists(gclient): |
| 42 print("No .gclient file: " + gclient) | 52 print >> sys.stderr, ("No .gclient file: " + gclient) |
| 43 | 53 |
| 44 gclient_entries = os.path.join(repository, ".gclient_entries") | 54 gclient_entries = os.path.join(repository, ".gclient_entries") |
| 45 if not os.path.exists(gclient_entries): | 55 if not os.path.exists(gclient_entries): |
| 46 print("No .gclient_entries file: " + gclient_entries) | 56 print >> sys.stderr, ("No .gclient_entries file: " + gclient_entries) |
| 47 | 57 |
| 48 os.mkdir(new_workdir) | 58 os.mkdir(new_workdir) |
| 49 os.symlink(gclient, os.path.join(new_workdir, ".gclient")) | 59 os.symlink(gclient, os.path.join(new_workdir, ".gclient")) |
| 50 os.symlink(gclient_entries, os.path.join(new_workdir, ".gclient_entries")) | 60 os.symlink(gclient_entries, os.path.join(new_workdir, ".gclient_entries")) |
| 51 | 61 |
| 52 for root, dirs, _ in os.walk(repository): | 62 for root, dirs, _ in os.walk(repository): |
| 53 if ".git" in dirs: | 63 if ".git" in dirs: |
| 54 workdir = root.replace(repository, new_workdir, 1) | 64 workdir = root.replace(repository, new_workdir, 1) |
| 55 make_workdir(os.path.join(root, ".git"), | 65 make_workdir(os.path.join(root, ".git"), |
| 56 os.path.join(workdir, ".git")) | 66 os.path.join(workdir, ".git")) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 86 if not os.path.exists(os.path.join(repository, link)): | 96 if not os.path.exists(os.path.join(repository, link)): |
| 87 return | 97 return |
| 88 link_dir = os.path.dirname(os.path.join(new_workdir, link)) | 98 link_dir = os.path.dirname(os.path.join(new_workdir, link)) |
| 89 if not os.path.exists(link_dir): | 99 if not os.path.exists(link_dir): |
| 90 os.makedirs(link_dir) | 100 os.makedirs(link_dir) |
| 91 os.symlink(os.path.join(repository, link), os.path.join(new_workdir, link)) | 101 os.symlink(os.path.join(repository, link), os.path.join(new_workdir, link)) |
| 92 | 102 |
| 93 | 103 |
| 94 if __name__ == '__main__': | 104 if __name__ == '__main__': |
| 95 sys.exit(main(sys.argv)) | 105 sys.exit(main(sys.argv)) |
| OLD | NEW |