Unverified Commit 656757e7 authored by Robin Mueller's avatar Robin Mueller
Browse files

added generic files

parent e6db6bb1
import re
from modgen.parserbase.parser import FileParser
from modgen.utility.sql_writer import SqlWriter
class ObjectDefinitionParser(FileParser):
def __init__(self, file_list: list):
super().__init__(file_list)
def _handle_file_parsing(self, file_name: str, *args, **kwargs):
file = open(file_name, "r", encoding="utf-8")
for line in file.readlines():
match = re.search(r'([\w]*)[\s]*=[\s]*(0[xX][0-9a-fA-F]+)', line)
if match:
self.mib_table.update({match.group(2): [match.group(1)]})
def _handle_file_parsing_moving_window(self, file_name: str, current_line: int, moving_window_size: int,
moving_window: list, *args, **kwargs):
pass
def _post_parsing_operation(self):
pass
def export_object_file(filename, object_list, file_separator: str = ","):
file = open(filename, "w")
for entry in object_list:
file.write(str(entry[0]) + file_separator + entry[1][0] + '\n')
file.close()
def write_translation_file(filename, list_of_entries, date_string_full: str):
outputfile = open(filename, "w")
print('ObjectParser: Writing translation file ' + filename)
definitions = ""
function = "const char* translateObject(object_id_t object){\n\tswitch((object&0xFFFFFFFF)){\n"
for entry in list_of_entries:
# first part of translate file
definitions += "const char *" + entry[1][0] + "_STRING = \"" + entry[1][0] + "\";\n"
# second part of translate file. entry[i] contains 32 bit hexadecimal numbers
function += "\t\tcase " + str(entry[0]) + ":\n\t\t\treturn " + entry[1][0] + "_STRING;\n"
function += '\t\tdefault:\n\t\t\treturn "UNKNOWN_OBJECT";\n'
outputfile.write("/** \n * @brief\tAuto-generated object translation file. Contains "
+ str(len(list_of_entries)) + " translations. \n"
" * Generated on: " + date_string_full + "\n **/ \n")
outputfile.write("#include \"translateObjects.h\"\n\n")
outputfile.write(definitions + "\n" + function + "\t}\n\treturn 0;\n}\n")
outputfile.close()
def sql_object_exporter(object_table: list, delete_cmd: str, create_cmd: str, insert_cmd: str, sql_table: str):
sql_writer = SqlWriter(sql_table)
sql_writer.delete(delete_cmd)
sql_writer.open(create_cmd)
for entry in object_table:
sql_writer.write_entries(
insert_cmd, (entry[0], entry[1][0])
)
sql_writer.commit()
sql_writer.close()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment