-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcritic
More file actions
executable file
·136 lines (117 loc) · 3.45 KB
/
critic
File metadata and controls
executable file
·136 lines (117 loc) · 3.45 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
#! /usr/bin/env python3
# -*-Python-*-
import os, subprocess, sys
HAVE_GITHUB = False
try:
import github
HAVE_GITHUB = True
except ImportError:
pass
COMPILER = 'clang++'
MEGABYTE = 1024 * 1024
MAX_SOURCE_FILE_SIZE = 1 * MEGABYTE
def print_divider():
print('-' * 79)
def is_source_file(path):
if not os.path.isfile(path):
return False
st = os.stat(path)
size = st.st_size
if size > MAX_SOURCE_FILE_SIZE:
return False
return True
# return True on success or False on failure
def command(arg_list):
print(' '.join(arg_list))
return_code = subprocess.call(arg_list)
return (return_code == 0)
# return a list of lines printed to stdout on success, or None on error
def command_lines(arg_list):
print(' '.join(arg_list))
p = subprocess.Popen(arg_list,
stdout=subprocess.PIPE,
universal_newlines=True,
close_fds=True)
stdout_str, stderr_str = p.communicate()
if p.returncode != 0:
return None
else:
return stdout_str.splitlines()
class Contributor:
def __init__(self, name, emails):
self.name = name
self.emails = emails
def find_contributors():
lines = command_lines(['git', 'shortlog', '-s', '-e'])
result = []
for line in lines:
name_and_email = line[7:]
name_part, email_part = name_and_email.split('<')
name = name_part.strip()
email = email_part.lstrip('<').rstrip('>')
result.append(Contributor(name, [email]))
return result
# return True on success or False on failure
def compile(source_path_list, library_name_list, output_path):
return command([COMPILER] +
['-g', '-std=c++11'] +
source_path_list +
['-l' + lib for lib in library_name_list] +
['-o'] + output_path)
def build():
return (compile(['catalog_test.cpp'],
[],
['catalog_test']) and
compile(['datafile_test.cpp'],
[],
['datafile_test']))
def test():
return (build() and
command(['./catalog_test']) and
command(['./datafile_test']))
def team():
contribs = find_contributors()
print('The following git users have contributed to this repository:')
print_divider()
for contrib in contribs:
print('"' + contrib.name + '"', end="")
for email in contrib.emails:
print(' <' + email + '>', end="")
print('')
print_divider()
print('')
def print_usage():
print('Usage:\n' +
'\n' +
' critic <COMMAND>\n' +
'\n' +
'Commands:\n' +
'\n' +
' build compile and link\n'
' help print this usage information\n'
' team print team members\n'
' test compile, then run unit tests\n')
def usage_error():
print_usage()
sys.exit(1)
def main():
if len(sys.argv) != 2:
usage_error()
command = sys.argv[1]
if command == 'build':
success = build()
elif command == 'help':
print_usage()
success = True
elif command == 'team':
team()
success = True
elif command == 'test':
success = test()
else:
usage_error()
success = False
if not success:
sys.exit(1)
if __name__ == '__main__':
main()