-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_documents_info.py
183 lines (142 loc) · 5.75 KB
/
make_documents_info.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
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
181
182
183
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
make_documents_info.py
Makes the document entries for the documents section.
See the README.md file for more information.
http://www.gridpp.ac.uk
"""
#...for the Operating System stuff.
import os
#...for parsing the arguments.
import argparse
#...for the logging.
import logging as lg
#...for the JSOB.
import json
#...for the time (being).
import time
# For the Document wrapper class.
from wrappers.document import Document
if __name__ == "__main__":
print("*")
print("*=========================*")
print("* make_documents_info.py *")
print("*=========================*")
print("*")
# Parse the command line arguments.
parser = argparse.ArgumentParser()
parser.add_argument("inputFilePath", help="Path to the input file.")
parser.add_argument("outputPath", help="Path to the output folder.")
parser.add_argument("subject", help="The subject.")
parser.add_argument("subjectCode", help="The subject code (for labels etc.).")
parser.add_argument("-v", "--verbose", help="Increase output verbosity", action="store_true")
args = parser.parse_args()
## The output path.
output_path = args.outputPath
#
# Check if the output directory exists. If it doesn't, raise an error.
if not os.path.isdir(output_path):
raise IOError("* ERROR: '%s' output directory does not exist!" % (output_path))
# Set the logging level.
if args.verbose:
level=lg.DEBUG
else:
level=lg.INFO
## Log file path.
log_file_path = os.path.join(output_path, 'log_make_documents_info.log')
# Configure the logging.
lg.basicConfig(filename=log_file_path, filemode='w', level=level)
## The path to the input file.
input_file_path = args.inputFilePath
#
if not os.path.exists(input_file_path):
raise IOError("* ERROR: Unable to find input file at '%s'." % (input_file_path))
## The subject of the presentations.
subject = str(args.subject)
## The subject code (used for labels etc.)
subject_code = str(args.subjectCode)
lg.info(" *=========================*")
lg.info(" * make_documents_info.py *")
lg.info(" *=========================*")
lg.info(" *")
lg.info(" * Input file path : %s" % (input_file_path))
lg.info(" * Output path : %s" % (output_path))
lg.info(" * Subject : %s" % (subject))
lg.info(" * Subject code : %s" % (subject_code))
lg.info(" *")
print("* Input file path : %s" % (input_file_path))
print("* Output path : %s" % (output_path))
print("* Subject : %s" % (subject))
print("* Subject code : %s" % (subject_code))
print("*")
# Get the events from the JSON file.
with open(input_file_path, "r") as jf:
js = json.load(jf)
#print js
t = """
%______________________________________________________________________________
\\begin{table}[htbp]
\\caption{\\label{tab:SUBJECT_CODEdocuments}Documents relating to
SUBJECT_NAME research and activities.}
\\lineup
\\begin{indented}
\item[]\\begin{tabular}{@{}lll}
\\br
\\centre{1}{$\\quad$DRN $\\quad$} &
\\centre{1}{$\\quad$Brief Title $\\quad$} &
\\centre{1}{$\\quad$DOI or URL $\\quad$} \\\\
\\mr
"""
t = t.replace("SUBJECT_CODE", subject_code)
t = t.replace("SUBJECT_NAME", subject)
s = ""
ms = []
for mj in js:
ms.append(Document(mj))
for m in sorted(ms):
lg.info(" * Title : %s" % (m.get_title()))
lg.info(" * Short title : %s" % (m.get_short_title()))
lg.info(" *")
s += "%=============================================================================\n"
s += "\\subsubsection{%s}\n" % (m.get_short_title())
s += "\\label{meeting:%s}\n" % (m.get_label())
s += "%=============================================================================\n"
s += "\\begin{itemize}\n"
s += "\\tightlist\n"
s += "\\item \\bullettext{Full title}: %s\n" % (m.get_title())
s += "\\item \\bullettext{DRN}: %s\n" % (m.get_drn())
if m.has_doi():
s += "\\item \\bullettext{DOI}: \\href{http://doi.org/%s}{%s}\n" % (m.get_doi(), m.get_doi())
elif m.has_url():
s += "\\item \\bullettext{URL}: \\href{%s}{%s}\n" % (m.get_url_latex(), m.get_url_latex())
elif m.has_lfn():
s += "\\item \\bullettext{LFN}: %s\n" % (m.get_lfn())
s += "\\end{itemize}\n"
s += "%s\n" % (m.get_summary_latex())
s += "%\n"
s += "\n"
# Add the document entry to the table.
if m.has_doi():
t += "\\texttt{%s} & %s & \\href{http://doi.org/%s}{\\texttt{%s}} \\\\\n" % (m.get_drn(), m.get_short_title(), m.get_doi(), m.get_doi())
elif m.has_url() and "twiki" in m.get_url_latex().lower():
t += "\\texttt{%s} & %s & \\href{%s}{MoEDAL Twiki page} \\\\\n" % (m.get_drn(), m.get_short_title(), m.get_url_latex())
elif m.has_url():
t += "\\texttt{%s} & %s & See \\url{%s} \\\\\n" % (m.get_drn(), m.get_short_title(), m.get_url_latex())
elif m.has_lfn():
t += "\\texttt{%s} & %s & \\texttt{%s} \\\\\n" % (m.get_drn(), m.get_short_title(), m.get_lfn())
# Complete the presentations table.
t += """\\br
\\end{tabular}
\\end{indented}
\\end{table}
%______________________________________________________________________________
"""
## The path of the TeX output file containing the document information.
output_tex_path = os.path.join(output_path, "documents.tex")
with open(output_tex_path, "w") as sf:
sf.write(s)
## The path of the table TeX file.
output_tex_table_path = os.path.join(output_path, "documentstable.tex")
with open(output_tex_table_path, "w") as tf:
tf.write(t)