You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
1 year ago
|
import re # libary to search and replace strings in the postscript file
|
||
|
import os
|
||
|
|
||
|
def generate_postscript(previous_module, current_module, script):
|
||
|
|
||
|
|
||
|
if previous_module == "" or previous_module == "dynamic_glyph":
|
||
|
print("use empty.ps and write to current_module.ps")
|
||
|
#input file
|
||
|
fileInput = open("empty.ps", "rt") # rt = read text mode
|
||
|
#output file to write the result to
|
||
|
fileOutput = open(current_module + ".ps", "wt") # wt = write text mode
|
||
|
|
||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||
|
# uses regular expressions library (re)
|
||
|
content = fileInput.read()
|
||
|
content = re.sub(r"% empty file\n\nshowpage\n% print all on a page", (script), content)
|
||
|
|
||
|
# write the new text to the output file
|
||
|
fileOutput.write(content)
|
||
|
#close input and output files
|
||
|
fileInput.close()
|
||
|
fileOutput.close()
|
||
|
# time.sleep(5)
|
||
|
|
||
|
else:
|
||
|
print("use previous_module.ps and write to current_module.ps")
|
||
|
#input file
|
||
|
fileInput = open(previous_module + ".ps", "rt") # a+ = read text mode and write (append) to end of file
|
||
|
fileOutput = open(current_module + ".ps", "wt") # wt = write text mode
|
||
|
|
||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||
|
# uses regular expressions library (re)
|
||
|
content = fileInput.read()
|
||
|
content = re.sub(r"showpage\n% print all on a page", (script), content)
|
||
|
|
||
|
# write the new text to the output file
|
||
|
fileOutput.write(content)
|
||
|
#close input and output files
|
||
|
fileInput.close()
|
||
|
fileOutput.close()
|
||
|
# time.sleep(5)
|