-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_sublib_difftable.py
60 lines (53 loc) · 2.15 KB
/
create_sublib_difftable.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
############################################################
#
# Author: Georg Schnabel
# Email: [email protected]
# Date: 2021/06/29
# Institution: IAEA
#
# Takes a directory that contains a changes.txt file and
# difference files with names <endf-file>.diff.html.
# The file changes.txt contains the output of
# 'git diff --name-status commit1 commit2', thus the first
# column contains the modification type ((A)dded, (M)odified, (D)eleted)
# and the second column the <endf-file> names relative to the root
# of the fendl-endf repository. This result of this script is an
# output file diff.html with an html-table with links to the
# <endf-file>.diff.html files.
#
# Usage:
# python create_sublib_difftable.py <dir>
#
# <dir>: directory with changes.txt and differences files
#
# Following environment variables must be set:
#
# FENDL_TEMPLATE_DIR - folder with html templates
# FENDL_VERSION - version of FENDL library
# FENDL_OLD_VERSION - previous version of FENDL library
#
############################################################
import pandas as pd
from jinja2 import Environment, FileSystemLoader
import sys
import os
# path to data directory of FENDL website
if len(sys.argv) != 2:
raise ValueError('Please provide path to diffdir')
fendl_version = os.environ['FENDL_VERSION']
fendl_old_version = os.environ['FENDL_OLD_VERSION']
diffdir = sys.argv[1]
# path to folder with jinja html templates
env = Environment(loader=FileSystemLoader(os.environ['FENDL_TEMPLATE_DIR']))
tmpl = env.get_template('diff_table.jinja')
diff_inpfile = os.path.join(diffdir, 'changes.txt')
html_outfile = os.path.join(diffdir, 'diff.html')
diff_table = pd.read_table(diff_inpfile, header=None)
diff_table.columns = ['status', 'filename']
diff_table['status'] = diff_table['status'].replace({'A': 'added', 'M': 'modified', 'D': 'deleted'})
diff_table['link'] = [os.path.basename(fname) + '.diff.html' for fname in diff_table['filename']]
print(diff_table)
html_output = tmpl.render(change_df=diff_table,
fendl_version=fendl_version, fendl_old_version=fendl_old_version)
with open(html_outfile, 'w+') as f:
f.write(html_output)