From 131c668d51011adea68832310a0c15f875399fdf Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Sat, 26 Oct 2024 16:21:37 +0100 Subject: [PATCH] Further work on modals that contain extracts from auxilliary input files --- PlumedToHTML/PlumedFormatter.py | 16 +++++++++------- PlumedToHTML/PlumedToHTML.py | 14 +++++++++++--- PlumedToHTML/tests/test_formatter.py | 2 +- setup.py | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/PlumedToHTML/PlumedFormatter.py b/PlumedToHTML/PlumedFormatter.py index 504a359..7d5035a 100644 --- a/PlumedToHTML/PlumedFormatter.py +++ b/PlumedToHTML/PlumedFormatter.py @@ -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 = { @@ -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('
' + inp + '
Click here to see an extract from this file.
') outfile.write('