-
Notifications
You must be signed in to change notification settings - Fork 2
/
format-reqs
executable file
·100 lines (90 loc) · 3.69 KB
/
format-reqs
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Print out PSM requirements in a specified format.
#
# Copyright (C) 2018 Open Tech Strategies, LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__doc__ = """\
Convert the PSM requirements spreadsheet to OUTPUT_FORMAT. The two
supported output formats so far are "human" (the default) and "elisp".
Note: This requires the psm_reqs.py module to be available in the
Python import path (typically it is in the same directory).
"""
import argparse
import sys
import psm_reqs
def parse_args():
"""Parse the arguments from the command line."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--output',
choices=['human', 'elisp'],
default='human',
dest='output_format'
)
parser.add_argument(
'reqs_file',
help="""A spreadsheet containing all the PSM requirements.
(Normally, requirements/RTM.xlsx on the PSM tree master branch.)""",
)
return parser.parse_args()
def main():
args = parse_args()
reqs = psm_reqs.get_reqs(args.reqs_file)
# Note that we'll print the requirements in whatever order we
# received them, because iteration over dicts in Python will now
# (or will soon) preserve insertion order. See this thread:
# https://mail.python.org/pipermail/python-dev/2017-December/151283.html
#
# We could also print them out sorted lexically by req ID, with:
#
# for req in [reqs[key] for key in sorted(reqs)]:
#
# However, that would not work quite the way we want, because,
# for example, "psm-FR-3.3" would sort after "psm-FR-3.25".
for req in reqs.values():
if args.output_format == "human":
print("%s" % req)
print("===================================")
elif args.output_format == "elisp":
# Every req has at least these fields.
print(" ((id \"%s\")\n"
" (category \"%s\")\n"
" (description \"%s\")"
% (req.req_id.replace('"', '\\"'),
req.category.replace('"', '\\"'),
req.description.replace('"', '\\"')))
# Each of these fields is optional
for elisp_symbol, req_field in (
("comment", req.comment,),
("priority", req.priority,),
("rank", req.rank,),
("source", req.source,),
("source-doc", req.source_doc,),
("release", req.release,),
("design-ref", req.design_ref,),
("acceptance-test-ref", req.acceptance_test_ref,),):
if (req_field is not None) and (req_field != ""):
print(" (%s \"%s\")" % (elisp_symbol, req_field))
# Close out this req's sublist.
print(" )")
else:
sys.stderr.write("ERROR: unknown output format '%s' "
"should have been caught earlier\n"
% args.output_format)
sys.exit(1)
if __name__ == '__main__':
main()