comparison toolfactory/rgToolFactory2.py @ 110:ab2474035f81 draft

Uploaded
author fubar
date Sun, 29 Nov 2020 06:16:34 +0000
parents 0116bfe0fa5e
children 223b78754735
comparison
equal deleted inserted replaced
109:0116bfe0fa5e 110:ab2474035f81
118 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$","#":"&#35;", "$":"&#36;"} 118 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$","#":"&#35;", "$":"&#36;"}
119 cheetah_escape_table = {"$": "\$","#":"\#"} 119 cheetah_escape_table = {"$": "\$","#":"\#"}
120 120
121 def html_escape(text): 121 def html_escape(text):
122 """Produce entities within text.""" 122 """Produce entities within text."""
123 return "".join(html_escape_table.get(c, c) for c in text) 123 return "".join([html_escape_table.get(c, c) for c in text])
124 124
125 def cheetah_escape(text): 125 def cheetah_escape(text):
126 """Produce entities within text.""" 126 """Produce entities within text."""
127 return "".join(cheetah_escape_table.get(c, c) for c in text) 127 return "".join([cheetah_escape_table.get(c, c) for c in text])
128 128
129 129
130 def html_unescape(text): 130 def html_unescape(text):
131 """Revert entities within text. Multiple character targets so use replace""" 131 """Revert entities within text. Multiple character targets so use replace"""
132 t = text.replace("&amp;", "&") 132 t = text.replace("&amp;", "&")
294 ) 294 )
295 tscript = open(self.sfile, "w") 295 tscript = open(self.sfile, "w")
296 tscript.write(self.script) 296 tscript.write(self.script)
297 tscript.close() 297 tscript.close()
298 self.escapedScript = [cheetah_escape(x) for x in rx] 298 self.escapedScript = [cheetah_escape(x) for x in rx]
299 self.spacedScript = [f" {x}" for x in self.escapedScript]
299 art = "%s.%s" % (self.tool_name, self.executeme) 300 art = "%s.%s" % (self.tool_name, self.executeme)
300 artifact = open(art, "wb") 301 artifact = open(art, "wb")
301 artifact.write(bytes(self.escapedScript, "utf8")) 302 artifact.write(bytes('\n'.join(self.escapedScript),'utf8'))
302 artifact.close() 303 artifact.close()
303 304
304 def cleanuppar(self): 305 def cleanuppar(self):
305 """ positional parameters are complicated by their numeric ordinal""" 306 """ positional parameters are complicated by their numeric ordinal"""
306 for i, p in enumerate(self.infiles): 307 for i, p in enumerate(self.infiles):
571 self.newtool.command_override = self.xmlcl 572 self.newtool.command_override = self.xmlcl
572 if self.args.help_text: 573 if self.args.help_text:
573 helptext = open(self.args.help_text, "r").readlines() 574 helptext = open(self.args.help_text, "r").readlines()
574 safertext = "\n".join([cheetah_escape(x) for x in helptext]) 575 safertext = "\n".join([cheetah_escape(x) for x in helptext])
575 if self.args.script_path: 576 if self.args.script_path:
576 scr = self.escapedScript 577 scr = [x for x in self.spacedScript if x.strip() > ""]
577 scrpt = [' %s' % x for x in scrpt if x.strip() > ''] # indent 578 scr.insert(0,'\n------\n\nScript::\n')
578 scrpt.insert(0,'------\n\nScript::\n') 579 if len(scr) > 300:
579 if len(scrpt) > 300: 580 scr = (
580 safertext = ( 581 scr[:100]
581 safertext 582 + [">300 lines - stuff deleted", "......"]
582 + scrpt[:100] 583 + scr[-100:]
583 + [">500 lines - stuff deleted", "......"]
584 + scrpt[-100:]
585 ) 584 )
586 else: 585 scr.append('\n------\n')
587 safertext = safertext + "\n".join(scrpt) 586 safertext = safertext + "\n".join(scr)
588 self.newtool.help = safertext 587 self.newtool.help = safertext
589 else: 588 else:
590 self.newtool.help = ( 589 self.newtool.help = (
591 "Please ask the tool author (%s) for help \ 590 "Please ask the tool author (%s) for help \
592 as none was supplied at tool generation\n" 591 as none was supplied at tool generation\n"