-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus-repos.py
executable file
·124 lines (111 loc) · 3.92 KB
/
status-repos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
import argparse
import os
import sys
import build_tools
def parse_args(args):
parser = argparse.ArgumentParser(
description='Gets various info about each source in the toolchain.',
parents=[build_tools.get_parent_parser()])
parser.add_argument(
'-k',
'--keep-going',
action='store_true',
help='Keep going even if errors are encountered.')
parser.add_argument(
'-i',
'--ignored',
action='store_true',
help='Show ignored files.')
parser.add_argument(
'--long',
action='store_true',
help='Print the long form status.')
parser.add_argument(
'--no-fetch',
action='store_true',
help="don't fetch before checking status")
parser.add_argument(
'-l',
'--list',
action='store_true',
help=(
'Just print the name of every source. '
'Ignores -k, -i, --no-fetch, and --long.'))
parser.add_argument(
'-b',
'--branch-only',
action='store_true',
help=(
'Just print the checked-out branch for each source. '
'Ignores -k, -i, --no-fetch, and --long.'))
parser.add_argument(
'--export',
action='store_true',
help=(
'export a json blob of branches'))
parser.add_argument(
'--export-for-windows',
action='store_true',
help=(
'export a json blob of branches for windows fancy builder'))
return parser.parse_args(args)
def status_repos(args):
"""
Prints out the status of each repo in the toolchain.
TODO(ted): Not sure how I feel about the fact that the behavior of this is
so tied to Source type, but I'd rather have it do something useful than
keeping everything 'pure'.
Actually, I think I hate everything about this.
"""
toolchain = build_tools.get_toolchain(args)
if args.export or args.export_for_windows:
if args.export_for_windows:
sep = '\\\"'
else:
sep = '\"'
jsonblob = '['
for source in toolchain:
if jsonblob.endswith('}'):
jsonblob += ','
jsonblob += '{' + sep + 'source' + sep + ':' + sep + source.name
jsonblob += sep + ',' + sep + 'version' + sep + ':'
jsonblob += sep + source.version + sep + '}'
jsonblob += ']'
print(jsonblob)
else:
if args.list:
def status(source):
print(source.name)
elif args.branch_only:
def status(source):
if isinstance(source, build_tools.source.Repo):
print(source.name + ': ' + source.current_branch())
else:
print(source.name + ': ' + source.version)
else:
def status(source):
if source.use_artifacts:
source.artifact_status()
elif isinstance(source, build_tools.source.Repo):
if not args.no_fetch:
rv = source.cmd(['git', 'fetch', '--all'], quiet=True)
if rv != 0:
print('could not fetch ' + source.name)
if not args.keep_going:
return rv
cmd = ['git', 'status']
if not args.long:
cmd.append('-sb')
if args.ignored:
cmd.append('--ignored')
rv = source.cmd(cmd)
if rv != 0:
print('could not get status of ' + source.name)
if not args.keep_going:
return rv
return toolchain.for_each_source(status, args.keep_going)
if '__main__' == __name__:
parsed_args = parse_args(sys.argv[1:])
rv = status_repos(parsed_args)
sys.exit(rv)