-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (67 loc) · 2.61 KB
/
main.py
File metadata and controls
80 lines (67 loc) · 2.61 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
from parser import parse_spl_file
from excel_export import export_to_excel
import os
import argparse
from utils import log, init_log
def parse_arguments():
parser = argparse.ArgumentParser(
description='Convert a spool file containing multiple query results into Excel file(s).'
)
parser.add_argument(
'input_file',
help='Path to the input spool file (e.g., cl_accounts.spl).'
)
parser.add_argument(
'-d', '--destination',
help=(
'Destination file name (for single Excel) or folder name (for multiple files).\n'
'If not provided, defaults to:\n'
' - <input_filename>.xlsx (if creating a single Excel file)\n'
' - <input_filename>/ folder (if creating multiple Excel files)'
)
)
parser.add_argument(
'-s', '--separate',
action='store_true',
help='Create a separate Excel file for each query result instead of separate sheets in one file.'
)
parser.add_argument(
'-v', '--verbose',
action='store_true',
help='Enable verbose mode. Shows detailed output of each processing step.'
)
parser.add_argument(
'-st', '--showstats',
action='store_true',
help='Include a summary sheet (or file) listing each query and its row count.'
)
return parser.parse_args()
def main(input_file, destination, separate, verbose, showstats):
# Input and output paths
# Parse the SPL file
log('Main', f"Parsing {input_file}...", verbose, mandatory=True)
results = parse_spl_file(input_file, verbose_flag=verbose, )
# Export to Excel
log('Main', f"Found and parsed {len(results)} queries in {input_file}.", verbose, mandatory=True)
log('Main', f"Initiating export to destination: {destination}...", verbose, mandatory=True)
export_to_excel(results, destination, separate, verbose, showstats)
log("Main", "Export completed.", verbose, mandatory=True)
if __name__ == "__main__":
args = parse_arguments()
# Derive default destination if not provided
if not args.destination:
base = os.path.splitext(os.path.basename(args.input_file))[0]
args.destination = base if args.separate else f"{base}.xlsx"
if args.verbose:
init_log(args.input_file)
try:
main(
input_file=args.input_file,
destination=args.destination,
separate=args.separate,
verbose=args.verbose,
showstats=args.showstats
)
except Exception as e:
log("Main", f"An error occurred: {e}", args.verbose, mandatory=True)
raise