OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """Display active git branches and code changes in a chromiumos workspace.""" | 6 """Display active git branches and code changes in a chromiumos workspace.""" |
7 | 7 |
| 8 import gclient_utils |
8 import os | 9 import os |
9 import re | 10 import re |
10 import subprocess | 11 import subprocess |
11 import sys | 12 import sys |
12 | 13 |
13 | 14 |
14 def show_dir(full_name, relative_name, color): | 15 def show_dir(full_name, relative_name, color): |
15 """Display active work in a single git repo.""" | 16 """Display active work in a single git repo.""" |
16 | 17 |
17 def show_name(): | 18 def show_name(): |
(...skipping 26 matching lines...) Expand all Loading... |
44 stdout=subprocess.PIPE).communicate()[0].rstrip() | 45 stdout=subprocess.PIPE).communicate()[0].rstrip() |
45 | 46 |
46 if len(status.splitlines()) > 2: | 47 if len(status.splitlines()) > 2: |
47 if lines_printed == 0: | 48 if lines_printed == 0: |
48 show_name() | 49 show_name() |
49 if lines_printed == 1: | 50 if lines_printed == 1: |
50 print '---------------' | 51 print '---------------' |
51 print status | 52 print status |
52 | 53 |
53 | 54 |
54 def find_file(filename): | |
55 """Search upwards from the current directory to find a file.""" | |
56 path = filename | |
57 while os.getcwd().split('/'): | |
58 if os.path.isfile(path): | |
59 return path | |
60 path = os.path.join('../', path) | |
61 | |
62 | |
63 def main(): | 55 def main(): |
64 """Take no arguments.""" | 56 """Take no arguments.""" |
65 | 57 |
66 color = False | 58 color = False |
67 | 59 |
68 if os.isatty(1): | 60 if os.isatty(1): |
69 color = True | 61 color = True |
70 | 62 |
71 base = os.path.basename(os.getcwd()) | 63 base = os.path.basename(os.getcwd()) |
72 config_file = '.gclient_entries' | 64 root, entries = gclient_utils.GetGClientRootAndEntries() |
73 config_path = find_file(config_file) | |
74 | 65 |
75 if not config_path: | 66 # which entries map to a git repos? |
76 print "Can't find", config_file | 67 raw = [k for k, v in entries.items() if not re.search('svn', v)] |
77 sys.exit(1) | |
78 | |
79 env = {} | |
80 execfile(config_path, env) | |
81 | |
82 # which are the git repos? | |
83 raw = [k for k, v in env['entries'].items() if not re.search('svn', v)] | |
84 raw.sort() | 68 raw.sort() |
85 | 69 |
86 # We want to use the full path for testing, but we want to use the relative | 70 # We want to use the full path for testing, but we want to use the relative |
87 # path for display. | 71 # path for display. |
88 root = os.path.dirname(config_path) | |
89 fulldirs = map(lambda(p): os.path.normpath(os.path.join(root, p)), raw) | 72 fulldirs = map(lambda(p): os.path.normpath(os.path.join(root, p)), raw) |
90 reldirs = map(lambda(p): re.sub('^' + base, '.', p), raw) | 73 reldirs = map(lambda(p): re.sub('^' + base, '.', p), raw) |
91 | 74 |
92 for full_path, relative_path in zip(fulldirs, reldirs): | 75 for full_path, relative_path in zip(fulldirs, reldirs): |
93 show_dir(full_path, relative_path, color) | 76 show_dir(full_path, relative_path, color) |
94 | 77 |
95 if __name__ == '__main__': | 78 if __name__ == '__main__': |
96 main() | 79 main() |
OLD | NEW |