forked from lfd/PaStA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pasta
executable file
·180 lines (153 loc) · 5.43 KB
/
pasta
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
"""
PaStA - Patch Stack Analysis
A tool for tracking the evolution of patch stacks
Copyright (c) OTH Regensburg, 2016-2017
Author:
Ralf Ramsauer <[email protected]>
This work is licensed under the terms of the GNU GPL, version 2. See
the COPYING file in the top-level directory.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
"""
import errno
import logging
import sys
from copy import deepcopy
from pypasta import Config
from bin.pasta_analyse import analyse
from bin.pasta_check_connectivity import check_connectivity
from bin.pasta_check_mbox import check_mbox
from bin.pasta_compare import compare
from bin.pasta_compare_clusters import compare_clusters
from bin.pasta_prepare_evaluation import prepare_evaluation
from bin.pasta_optimise_cluster import optimise_cluster
from bin.pasta_rate import rate
from bin.pasta_ripup import ripup
from bin.pasta_show_cluster import show_cluster
from bin.pasta_statistics import statistics
from bin.pasta_sync import sync
from bin.pasta_compare_stacks import compare_stacks
from bin.pasta_patch_descriptions import patch_descriptions
from bin.pasta_upstream_duration import upstream_duration
from bin.pasta_upstream_history import pasta_upstream_history
from bin.pasta_web import web
__author__ = 'Ralf Ramsauer'
__copyright__ = 'Copyright (c) OTH Regensburg, 2016-2017'
__credits__ = ['Ralf Ramsauer']
__license__ = 'GPLv2'
__version__ = '0.3'
__maintainer__ = 'Ralf Ramsauer'
__email__ = '[email protected]'
__status__ = 'Development'
log = logging.getLogger('PaStA')
def usage(me, exit_code=errno.EINVAL):
file = sys.stdout
if exit_code != 0:
file = sys.stderr
print('PaStA - The Patch Stack Analysis (PaStA %s)\n'
'\n'
'usage: %s [-d] [-c project_name] sub [-h|--help]\n'
'where sub is one of:\n'
' analyse\n'
' check_connectivity\n'
' check_mbox\n'
' compare\n'
' optimise_cluster\n'
' prepare_evaluation\n'
' rate\n'
' sync\n'
' select\n'
' show_cluster\n'
' statistics\n'
' compare_stacks\n'
' compare_clusters\n'
' patch_descriptions\n'
' ripup\n'
' upstream_history\n'
' web\n'
'\n'
'If -c is not provided, PaStA will choose ./config as config file\n'
'\n'
'%s\n'
'Licensed under %s (See COPYING)\n'
'This is free software: you are free to change and redistribute it.\n'
'There is NO WARRANTY, to the extent permitted by law.\n'
'\n'
'Written by %s.' %
(__version__, me, __copyright__, __license__, __author__), file=file)
sys.exit(exit_code)
def main(argv):
me = argv.pop(0)
config = None
level = logging.INFO
debug = False
while len(argv) and argv[0].startswith('-'):
argument = argv.pop(0)
if argument == '-c':
if not argv:
usage(me)
config = argv.pop(0)
elif argument == '-d':
level = logging.DEBUG
debug = True
fmt = '%(asctime)-15s %(name)-15s %(levelname)-8s %(message)s'
logging.basicConfig(level=level, stream=sys.stdout, format=fmt)
filehandler = logging.FileHandler(filename='./log', mode='a')
filehandler.setFormatter(logging.Formatter(fmt))
logging.getLogger().addHandler(filehandler)
log.info('Cmdline: ' + ' '.join(sys.argv))
if not config:
with open('./config', 'r') as f:
config = f.read().strip()
if not argv:
usage(me)
sub = argv.pop(0)
if sub == 'compare_clusters':
return compare_clusters(sub, argv)
if sub == 'optimise_cluster':
return optimise_cluster(sub, argv)
if sub == 'select':
return Config.select_config(argv[0])
config = Config(config, debug)
if sub == '-h' or sub == '--help':
usage(me, 0)
elif sub == 'analyse':
return analyse(config, sub, argv)
elif sub == 'check_connectivity':
return check_connectivity(config, sub, argv)
elif sub == 'check_mbox':
return check_mbox(config, sub, argv)
elif sub == 'compare':
return compare(config, sub, argv)
elif sub == 'prepare_evaluation':
return prepare_evaluation(config, sub, argv)
elif sub == 'rate':
return rate(config, sub, argv)
elif sub == 'statistics':
return statistics(config, sub, argv)
elif sub == 'compare_stacks':
return compare_stacks(config, sub, argv)
elif sub == 'patch_descriptions':
return patch_descriptions(config, sub, argv)
elif sub == 'ripup':
return ripup(config, sub, argv)
elif sub == 'show_cluster':
return show_cluster(config, sub, argv)
elif sub == 'sync':
return sync(config, sub, argv)
elif sub == 'upstream_history':
return pasta_upstream_history(config, sub, argv)
elif sub == 'upstream_duration':
return upstream_duration(config, sub, argv)
elif sub == 'web':
return web(config, sub, argv)
else:
print('Unknown command: %s' % sub)
usage(me)
if __name__ == '__main__':
ret = main(deepcopy(sys.argv))
log.info('Shutting down')
sys.exit(ret if ret else 0)