-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-xlsx
executable file
·110 lines (97 loc) · 3.72 KB
/
build-xlsx
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
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# build-xlsx - Generate a spread sheet from files
#
# USAGE
#
# (1) Output an empty sheet
#
# $ build-xlsx -o config.xlsx
#
# (2) Generate a filled sheet
#
# $ build-xlsx esr91.txt esr102.txt ... verify-targets-to-chapters.csv
# $ build-xlsx -p esr91.txt -c esr102.txt
# $ build-xlsx -d ESR91:esr91.txt -d ESR102:esr102.txt -d "ESR102 variation:esr102-variation.txt"
#
# DEFINITION OF TERMS IN THIS MODULE
#
# For example, about "Security-9-3 about:configの利用の可否:禁止する" on Firefox ESR102:
#
# * category: "Security", this is same to the name of the file under "esr102/"
# * item: "Security-9"
# * items: "Security-1", "Security-2", "Security-3", and others defined in the file "esr102/Security"
# * option: "Security-9-1", "Security-9-2", "Security-9-3", and others
# * config: `"BlockAboutConfig": true,` or others, defined in the given "conf" file like "esr102.txt"
# * template: `"BlockAboutConfig": true,` or others, defined in the file "esr102/Security"
#
# * conf: A file listing chosen options. Please note this is not an abbr of "config".
# * curr/prev: curr=ESR102, prev=ESR91 (versions)
import re
import sys
import glob
import getopt
import csv
import os
BASEDIR = os.path.dirname(os.path.realpath(__file__))
sys.path.append(BASEDIR)
import adlib
import xlsxlib
try:
import xlsxwriter
except ImportError:
print('ERROR: Please install xlswriter to run this script\n')
print(' $ sudo apt install python3-xlsxwriter\n')
sys.exit(1)
CHAPTERS_CSV = 'verify-targets-to-chapters.csv'
#
# main
def load_verification_chapters(path):
try:
with open(path) as file:
return dict(csv.reader(file))
except FileNotFoundError:
return {}
def main(args):
global check_template_mode
confs = {}
outfile = 'config.xlsx'
exclude_worksheets = []
opts, args = getopt.getopt(args, 'o:x:p:c:d:t')
for key, value in opts:
if key == '-o':
outfile = value
elif key == '-x':
exclude_worksheets = value.split(',')
elif key == '-p':
confs[xlsxlib.ESR_PREVIOUS.upper()] = value
elif key == '-c':
confs[xlsxlib.ESR_CURRENT.upper()] = value
elif key == '-d':
parts = value.split(':', 1)
confs[parts[0]] = parts[1]
elif key == '-t':
# Compare template configuration and finally applied configuration.
# Do not use this option for sheet in production. This option is intended to be used with checking.
check_template_mode = True
verification_chapters = {}
for arg in args:
if xlsxlib.ESR_PREVIOUS in arg and not xlsxlib.ESR_PREVIOUS.upper() in confs:
print('%s -> %s' % (xlsxlib.ESR_PREVIOUS, arg))
confs[xlsxlib.ESR_PREVIOUS.upper()] = arg
elif xlsxlib.ESR_CURRENT in arg and not xlsxlib.ESR_CURRENT.upper() in confs:
print('%s -> %s' % (xlsxlib.ESR_CURRENT, arg))
confs[xlsxlib.ESR_CURRENT.upper()] = arg
elif CHAPTERS_CSV in arg:
print('Loading', os.path.basename(arg))
verification_chapters = load_verification_chapters(arg)
for version, path in confs.items():
confs[version] = adlib.load_as_dict(path)
with xlsxwriter.Workbook(outfile) as workbook:
xlsxlib.generate_xlsx(workbook, confs, verification_chapters, exclude_worksheets)
print('Generated:', workbook.filename)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))