-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
90 lines (76 loc) · 2.94 KB
/
main.py
File metadata and controls
90 lines (76 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
Main script for Bidirectional Word-CSV Converter
This script allows:
1. Converting Word documents to CSV (parsing product specifications)
2. Converting CSV files back to Word documents
3. Choosing between GUI and command-line interfaces
Usage:
python main.py [--mode {word2csv,csv2word}] [--gui] [--cli]
"""
import os
import sys
import argparse
def run_word_to_csv_gui():
"""Run the Word to CSV GUI converter application."""
try:
from converter_app import main as converter_main
converter_main()
except ImportError:
print("Error: converter_app.py not found or has errors.")
print("Make sure converter_app.py is in the same directory.")
sys.exit(1)
def run_word_to_csv_cli():
"""Run the Word to CSV command-line parser."""
try:
from word_parser import main as parser_main
parser_main()
except ImportError:
print("Error: word_parser.py not found or has errors.")
print("Make sure word_parser.py is in the same directory.")
sys.exit(1)
def run_csv_to_word_gui():
"""Run the CSV to Word GUI converter application."""
try:
from csv_to_word_gui import main as csv_to_word_gui_main
csv_to_word_gui_main()
except ImportError:
print("Error: csv_to_word_gui.py not found or has errors.")
print("Make sure csv_to_word_gui.py is in the same directory.")
sys.exit(1)
def run_csv_to_word_cli():
"""Run the CSV to Word command-line converter."""
try:
from csv_to_word import main as csv_to_word_main
csv_to_word_main()
except ImportError:
print("Error: csv_to_word.py not found or has errors.")
print("Make sure csv_to_word.py is in the same directory.")
sys.exit(1)
def main():
"""Main function to parse arguments and run the appropriate module."""
parser = argparse.ArgumentParser(description="Bidirectional Word-CSV Converter")
# Mode selection
mode_group = parser.add_argument_group("Conversion Mode")
mode_group.add_argument("--mode", choices=["word2csv", "csv2word"], default="word2csv",
help="Select conversion direction (default: word2csv)")
# Interface selection
interface_group = parser.add_mutually_exclusive_group()
interface_group.add_argument("--gui", action="store_true", help="Launch the GUI application (default)")
interface_group.add_argument("--cli", action="store_true", help="Run the command-line interface")
args = parser.parse_args()
# Default to GUI if no interface specified
use_gui = not args.cli
# Run the appropriate application based on mode and interface
if args.mode == "word2csv":
if use_gui:
run_word_to_csv_gui()
else:
run_word_to_csv_cli()
else: # csv2word
if use_gui:
run_csv_to_word_gui()
else:
run_csv_to_word_cli()
if __name__ == "__main__":
main()