Skip to content

Commit

Permalink
Further work on modals that contain extracts from auxilliary input files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Oct 26, 2024
1 parent 507ca86 commit 131c668
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
16 changes: 9 additions & 7 deletions PlumedToHTML/PlumedFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, **options) :
self.hasload=options["hasload"]
self.broken=options["broken"]
self.auxinputs=options["auxinputs"]
self.auxinputlines=options["auxinputlines"]
self.valuedict=options["valuedict"]
self.actions=options["actions"]
self.valcolors = {
Expand Down Expand Up @@ -140,13 +141,13 @@ def format(self, tokensource, outfile):
iff = open( inp, 'r' )
fcontent = iff.read()
iff.close()
if len(fcontent.splitlines())>5 :
n, shortversion = 0, ""
for l in fcontent.splitlines() :
shortversion += l + "\n"
n = n + 1
if n==5 : break
shortversion += "...\n" + fcontent.splitlines()[-1]
if len(self.auxinputlines)>0 :
shortversion, allines = "", fcontent.splitlines()
for n, l in enumerate(self.auxinputlines) :
bounds = l.split("-")
start, end = int( bounds[0] ), int( bounds[1] )
if n>0 : shortversion += "...\n"
for kk in range(start,end+1) : shortversion += allines[kk-1] + "\n"
fcontent = shortversion
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>')
outfile.write('<div id="' + self.egname + inp + '" class="modal">')
Expand Down Expand Up @@ -223,6 +224,7 @@ def format(self, tokensource, outfile):
else : raise Exception("keyword " + value.strip().upper() + " is not in syntax for action " + action )
if desc=="" and self.broken : outfile.write( value )
else :
if action not in self.keyword_dict : raise Exception("action " + action + " not present in keyword dictionary")
if "actionlink" in self.keyword_dict[action]["syntax"][mykey].keys() and self.keyword_dict[action]["syntax"][mykey]["actionlink"]!="none" :
linkaction = self.keyword_dict[action]["syntax"][mykey]["actionlink"]
desc = desc + ". Options for this keyword are explained in the documentation for <a href=\"" + self.keyword_dict[linkaction]["hyperlink"] + "\">" + linkaction + "</a>.";
Expand Down
14 changes: 11 additions & 3 deletions PlumedToHTML/PlumedToHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,22 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
inpt, incomplete = manage_incomplete_inputs( inpt )

# Create a list of all the auxiliary input files that are needed by the plumed input
inputfiles = []
inputfiles, inputfilelines = [], []
for line in inpt.splitlines() :
if "#SETTINGS" in line :
for word in line.split() :
if "MOLFILE=" in word :
inputfiles.append( word.replace("MOLFILE=","") )
molfile = word.replace("MOLFILE=","")
iff = open( molfile, 'r' )
content = iff.read()
iff.close()
inputfiles.append(molfile)
inputfilelines.append("1-5")
inputfilelines.append( str(len(content.splitlines())-4) + "-" + str(len(content.splitlines())) )
elif "INPUTFILES=" in word :
for n in word.replace("INPUTFILES=","").split(",") : inputfiles.append( n )
elif "INPUTFILELINES=" in word :
inputfilelines = word.replace("INPUTFILELINES=","").split(",")

# Check for include files
foundincludedfiles, srcdir = True, str(pathlib.PurePosixPath(name).parent)
Expand Down Expand Up @@ -235,7 +243,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
plumed_info = subprocess.run(cmd, capture_output=True, text=True )
keyfile = plumed_info.stdout.strip() + "/json/syntax.json"
formatfile = os.path.join(os.path.dirname(__file__),"PlumedFormatter.py")
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 )
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 )

# Now generate html of input
html = '<div style="width: 100%; float:left">\n'
Expand Down
2 changes: 1 addition & 1 deletion PlumedToHTML/tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def testSimple(self) :
keyfile = plumed_info.stdout.strip() + "/json/syntax.json"

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

# Now run over all the inputs in the json
for item in tests["regtests"] :
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='PlumedToHTML',
version='0.87',
version='0.89',
author="Gareth Tribello",
author_email="[email protected]",
description="A package for creating pretified HTML for PLUMED files",
Expand Down

0 comments on commit 131c668

Please sign in to comment.