62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
import argparse
|
|
from table_handler.serializer import Transformer, XslxReader
|
|
from logger import logger
|
|
|
|
import instructions.countings_formater as countings_formater
|
|
import instructions.ring_formater as ring_formater
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="Serialize Excel tables.")
|
|
|
|
parser.add_argument(
|
|
"-i", "--input",
|
|
required=True,
|
|
help="Input Excel file"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"-o", "--output",
|
|
required=True,
|
|
help="Output Excel file"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"-t", "--type",
|
|
required=True,
|
|
choices=["ring", "counting"],
|
|
help="Type of table to process"
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Select formatter based on type
|
|
if args.type == "ring":
|
|
formatter = ring_formater
|
|
row_instructions = ring_formater.ROW_INSTRUCTIONS
|
|
else:
|
|
formatter = countings_formater
|
|
row_instructions = countings_formater.ROW_INSTRUCTION
|
|
|
|
logger.info("Reading file, building serializer...")
|
|
data = XslxReader(args.input).serialize_table(formatter.EXPECTED_INPUT_TABLE_SCHEMA)
|
|
|
|
serializer = Transformer(
|
|
data,
|
|
formatter.EXPECTED_OUTPUT_TABLE_SCHEMA or formatter.EXPECTED_INPUT_TABLE_SCHEMA,
|
|
)
|
|
|
|
logger.info("Starting transformation")
|
|
serializer.run(
|
|
formatter.COL_INSTRUCTIONS,
|
|
row_instructions
|
|
)
|
|
|
|
logger.info("Writing transformations")
|
|
serializer.write_output(args.output)
|
|
|
|
logger.info("Done")
|
|
|
|
if __name__ == "__main__":
|
|
main() |