diff options
Diffstat (limited to 'archive/BlockAdderGenerator/biovatgen.py')
-rw-r--r-- | archive/BlockAdderGenerator/biovatgen.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/archive/BlockAdderGenerator/biovatgen.py b/archive/BlockAdderGenerator/biovatgen.py new file mode 100644 index 0000000000..650cc52de7 --- /dev/null +++ b/archive/BlockAdderGenerator/biovatgen.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 2 19:11:07 2019 + +Copyright (c) 2019 boubou_19, bartimaeusnek +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +@author: boubou_19, bartimaeusnek +""" + +import os +import datetime +import time +name="GTNHBlocks" #change the name of the output file here +ending=".java" +csv_path = os.getcwd()+os.sep+"csv.csv" # change the name of the csv here +output_file_path = os.getcwd()+os.sep+name+ending +code_list = [] #will store all the lines of code +max_meta = [] +with open(csv_path, "r") as file:#open the file and automatically close it when it leaves the scope + code_list.append("import com.github.bartimaeusnek.bartworks.API.BioVatLogicAdder;\n") + code_list.append("\n") + code_list.append("//Autogenerated run file, script Created on Wed Jan 2 19:11:07 2019 by boubou_19 and bartimaeusnek\n") + code_list.append("//Executed on "+datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')+"\n") + code_list.append("public class "+name+" implements Runnable {\n") + code_list.append("\n") + code_list.append(" @Override\n") + code_list.append(" public void run(){\n") + file.readline() #skip the first line of the file + + for line in file: + line = line.split(";") #turns the string into a list of strings using the ";" separator + line[4] = line[4].strip("\n") #it remove the \n at the end of a csv line otherwise it will do shit in the string later + if line[3] == "-1" or line[3] == "0": + code_list.append(" BioVatLogicAdder.BioVatGlass.addCustomGlass(\"{0}\",\"{1}\",{2},{3});\n".format(line[0],line[1],line[2],line[4])) + else: + if line[3] == "15" and line[2] == "0": + max_meta.append(" BioVatLogicAdder.BioVatGlass.addCustomGlass(\"{0}\",\"{1}\",i,{3});\n".format(line[0],line[1],line[2],line[4])) + else: + code_list.append("\n for (int i = {0}; i <= {1};++i)\n".format(line[2],line[3])) + code_list.append(" BioVatLogicAdder.BioVatGlass.addCustomGlass(\"{0}\",\"{1}\",i,{3});\n\n".format(line[0],line[1],line[2],line[4])) + + # for i in range(int(line[2]),int(line[3])+1): #the +1 is here because range instruction always exclude the last number + code_list.append("\n for (int i = 0; i <= 15;++i;){\n") + for line in max_meta: + code_list.append(line) + code_list.append(" }\n") + code_list.append(" }\n") + code_list.append("}\n") +with open(output_file_path,"w") as out: + out.writelines(code_list) + |