Skip to content

Commit 131c668

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
Gareth Aneurin Tribello
authored and
Gareth Aneurin Tribello
committed
Further work on modals that contain extracts from auxilliary input files
1 parent 507ca86 commit 131c668

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

PlumedToHTML/PlumedFormatter.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, **options) :
1818
self.hasload=options["hasload"]
1919
self.broken=options["broken"]
2020
self.auxinputs=options["auxinputs"]
21+
self.auxinputlines=options["auxinputlines"]
2122
self.valuedict=options["valuedict"]
2223
self.actions=options["actions"]
2324
self.valcolors = {
@@ -140,13 +141,13 @@ def format(self, tokensource, outfile):
140141
iff = open( inp, 'r' )
141142
fcontent = iff.read()
142143
iff.close()
143-
if len(fcontent.splitlines())>5 :
144-
n, shortversion = 0, ""
145-
for l in fcontent.splitlines() :
146-
shortversion += l + "\n"
147-
n = n + 1
148-
if n==5 : break
149-
shortversion += "...\n" + fcontent.splitlines()[-1]
144+
if len(self.auxinputlines)>0 :
145+
shortversion, allines = "", fcontent.splitlines()
146+
for n, l in enumerate(self.auxinputlines) :
147+
bounds = l.split("-")
148+
start, end = int( bounds[0] ), int( bounds[1] )
149+
if n>0 : shortversion += "...\n"
150+
for kk in range(start,end+1) : shortversion += allines[kk-1] + "\n"
150151
fcontent = shortversion
151152
outfile.write('<div class="tooltip">' + inp + '<div class="right"> Click <a onclick=\'openModal("' + self.egname + inp + '")\'>here</a> to see an extract from this file.<i></i></div></div>')
152153
outfile.write('<div id="' + self.egname + inp + '" class="modal">')
@@ -223,6 +224,7 @@ def format(self, tokensource, outfile):
223224
else : raise Exception("keyword " + value.strip().upper() + " is not in syntax for action " + action )
224225
if desc=="" and self.broken : outfile.write( value )
225226
else :
227+
if action not in self.keyword_dict : raise Exception("action " + action + " not present in keyword dictionary")
226228
if "actionlink" in self.keyword_dict[action]["syntax"][mykey].keys() and self.keyword_dict[action]["syntax"][mykey]["actionlink"]!="none" :
227229
linkaction = self.keyword_dict[action]["syntax"][mykey]["actionlink"]
228230
desc = desc + ". Options for this keyword are explained in the documentation for <a href=\"" + self.keyword_dict[linkaction]["hyperlink"] + "\">" + linkaction + "</a>.";

PlumedToHTML/PlumedToHTML.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,22 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
186186
inpt, incomplete = manage_incomplete_inputs( inpt )
187187

188188
# Create a list of all the auxiliary input files that are needed by the plumed input
189-
inputfiles = []
189+
inputfiles, inputfilelines = [], []
190190
for line in inpt.splitlines() :
191191
if "#SETTINGS" in line :
192192
for word in line.split() :
193193
if "MOLFILE=" in word :
194-
inputfiles.append( word.replace("MOLFILE=","") )
194+
molfile = word.replace("MOLFILE=","")
195+
iff = open( molfile, 'r' )
196+
content = iff.read()
197+
iff.close()
198+
inputfiles.append(molfile)
199+
inputfilelines.append("1-5")
200+
inputfilelines.append( str(len(content.splitlines())-4) + "-" + str(len(content.splitlines())) )
195201
elif "INPUTFILES=" in word :
196202
for n in word.replace("INPUTFILES=","").split(",") : inputfiles.append( n )
203+
elif "INPUTFILELINES=" in word :
204+
inputfilelines = word.replace("INPUTFILELINES=","").split(",")
197205

198206
# Check for include files
199207
foundincludedfiles, srcdir = True, str(pathlib.PurePosixPath(name).parent)
@@ -235,7 +243,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
235243
plumed_info = subprocess.run(cmd, capture_output=True, text=True )
236244
keyfile = plumed_info.stdout.strip() + "/json/syntax.json"
237245
formatfile = os.path.join(os.path.dirname(__file__),"PlumedFormatter.py")
238-
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_file=keyfile, input_name=name, hasload=found_load, broken=any(broken), auxinputs=inputfiles, valuedict=valuedict, actions=actions )
246+
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_file=keyfile, input_name=name, hasload=found_load, broken=any(broken), auxinputs=inputfiles, auxinputlines=inputfilelines, valuedict=valuedict, actions=actions )
239247

240248
# Now generate html of input
241249
html = '<div style="width: 100%; float:left">\n'

PlumedToHTML/tests/test_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def testSimple(self) :
2222
keyfile = plumed_info.stdout.strip() + "/json/syntax.json"
2323

2424
# Setup a plumed formatter
25-
f = PlumedFormatter( keyword_file=keyfile, input_name="testout", hasload=False, broken=False, actions=set({}), valuedict=dict({}), auxinputs=[] )
25+
f = PlumedFormatter( keyword_file=keyfile, input_name="testout", hasload=False, broken=False, actions=set({}), valuedict=dict({}), auxinputs=[], auxinputlines=[] )
2626

2727
# Now run over all the inputs in the json
2828
for item in tests["regtests"] :

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name='PlumedToHTML',
9-
version='0.87',
9+
version='0.89',
1010
author="Gareth Tribello",
1111
author_email="gareth.tribello@gmail.com",
1212
description="A package for creating pretified HTML for PLUMED files",

0 commit comments

Comments
 (0)