OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 # | |
6 # Usage: | |
7 # gclient-new-workdir.py <repository> <new_workdir> [<branch>] | |
8 # | |
9 | |
10 import os | |
11 import shutil | |
12 import sys | |
13 | |
14 def main(argv): | |
15 if len(argv) < 3: | |
iannucci
2013/11/04 21:40:29
also check if not enough parameters? Shouldn't it
| |
16 usage() | |
17 return 1 | |
18 | |
19 if not os.path.exists(argv[1]): | |
20 print("Repository does not exist: " + argv[1]) | |
21 return 1 | |
22 | |
23 if os.path.exists(argv[2]): | |
24 print("New workdir already exists: " + argv[2]) | |
25 return 1 | |
26 | |
27 repository = argv[1] | |
28 new_workdir = argv[2] | |
iannucci
2013/11/04 21:40:29
Let's move these above the checks, so we don't hav
| |
29 | |
30 gclient = repository + os.sep + ".gclient" | |
iannucci
2013/11/04 21:40:29
os.path.join(repository, '.gclient')
| |
31 if not os.path.exists(gclient): | |
32 print("No .gclient file: " + gclient) | |
33 | |
34 gclient_entries = repository + os.sep + ".gclient_entries" | |
35 if not os.path.exists(gclient_entries): | |
36 print("No .gclient_entries file: " + gclient_entries) | |
37 | |
38 os.mkdir(new_workdir) | |
39 os.symlink(gclient, new_workdir + os.sep + ".gclient") | |
40 os.symlink(gclient_entries, new_workdir + os.sep + ".gclient_entries") | |
41 | |
42 for root, dirs, files in os.walk(repository): | |
43 for name in dirs: | |
44 if name == ".git": | |
45 workdir = root.replace(repository, new_workdir, 1) | |
46 make_workdir(os.path.join(root, name), os.path.join(workdir, name)) | |
47 | |
48 return 0 | |
49 | |
50 def make_workdir(repository, new_workdir): | |
51 print("Creating: " + new_workdir) | |
52 os.makedirs(new_workdir) | |
53 make_symlink(repository, new_workdir, "config") | |
54 make_symlink(repository, new_workdir, "refs") | |
55 if os.path.exists(repository + os.sep + "logs"): | |
56 os.makedirs(new_workdir + os.sep + "logs") | |
57 make_symlink(repository, new_workdir, "logs" + os.sep + "refs") | |
58 make_symlink(repository, new_workdir, "objects") | |
59 make_symlink(repository, new_workdir, "info") | |
60 make_symlink(repository, new_workdir, "hooks") | |
61 make_symlink(repository, new_workdir, "packed-refs") | |
62 make_symlink(repository, new_workdir, "remotes") | |
63 make_symlink(repository, new_workdir, "rr-cache") | |
64 make_symlink(repository, new_workdir, "svn") | |
65 shutil.copy2(repository + os.sep + "HEAD", new_workdir + os.sep + "HEAD") | |
66 before = os.getcwd() | |
67 os.chdir(new_workdir.rstrip(".git")) | |
68 os.system("git checkout -f") | |
iannucci
2013/11/04 21:40:29
let's just use subprocess.check_call with the cwd
| |
69 os.chdir(before) | |
70 | |
71 def make_symlink(repository, new_workdir, link): | |
72 if not os.path.exists(repository + os.sep + link): | |
73 return | |
74 os.symlink(repository + os.sep + link, new_workdir + os.sep + link) | |
75 | |
76 def usage(): | |
77 print("gclient-new-workdir.py <repository> <new_workdir>") | |
78 | |
79 if __name__ == '__main__': | |
80 sys.exit(main(sys.argv)) | |
OLD | NEW |