-
Notifications
You must be signed in to change notification settings - Fork 3
/
radio_sync_cli.py
195 lines (159 loc) · 4.68 KB
/
radio_sync_cli.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import argparse
import logging
import sys
import src.ham.util.radio_types
import src.radio_sync_version_check
from src import radio_sync_version
from src.ham.migration.migration_manager import MigrationManager
from src.ham.radio_generator import RadioGenerator
from src.ham.util.path_manager import PathManager
from src.ham.wizard import Wizard
def main():
logger = logging.getLogger()
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d %(levelname)7s %(filename).6s:%(lineno)3s: %(message)s', datefmt="%Y-%m-%d %H:%M:%S")
handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(formatter)
logger.setLevel(logging.INFO)
logger.addHandler(handler)
logging.warning("COMMAND LINE IS DEPRECATED. NEWER FEATURES MAY NOT BE SUPPORTED.")
parser = argparse.ArgumentParser(
prog='Ham Radio channel wizard',
description='''Convert a ham channel list to various radio formats. All of these options can be chained
to run multiple steps in order.''')
parser.add_argument(
'--clean', '-c',
action='store_true',
default=False,
required=False,
help='Destroys input and output directories along with all their contents.',
)
parser.add_argument(
'--migrate-check',
action='store_true',
default=False,
required=False,
help='Checks for outdated columns.',
)
parser.add_argument(
'--migrate', '-m',
action='store_true',
default=False,
required=False,
help='Safely updates your input files to the latest version.',
)
parser.add_argument(
'--migrate-cleanup',
action='store_true',
default=False,
required=False,
help='Removes .bak files created during migration process.',
)
parser.add_argument(
'--wizard', '-w',
action='store_true',
default=False,
required=False,
help='Runs the setup wizard and creates minimum needed files',
)
parser.add_argument(
'--input', '-i',
default=False,
required=False,
help='Sets the input folder',
)
parser.add_argument(
'--output', '-o',
default=False,
required=False,
help='Sets the output folder',
)
parser.add_argument(
'--force', '-f',
action='store_true',
default=False,
required=False,
help="Defaults to 'yes' for all prompts (DANGEROUS)",
)
parser.add_argument(
'--radios', '-r',
choices=src.ham.util.radio_types.radio_choices(),
default=[],
nargs='+',
help=f"""Target radios to create."""
)
parser.add_argument(
'--version',
action='store_true',
default=False,
required=False,
help='Display app version.',
)
parser.add_argument(
'--debug',
action='store_true',
default=False,
required=False,
help='Enable debug logging.',
)
arg_values = parser.parse_args()
op_performed = False
if arg_values.debug:
logger.setLevel(logging.DEBUG)
logging.debug("Logging level set to debug.")
PathManager.set_input_path('in')
if arg_values.input:
PathManager.set_input_path(arg_values.input)
logging.info(f"Input directory set to {PathManager.get_input_path()}")
PathManager.set_output_path('out')
if arg_values.output:
PathManager.set_output_path(arg_values.output)
logging.info(f"Input directory set to {PathManager.get_output_path()}")
if arg_values.force:
logging.warning("FORCE HAS BEEN SET. ALL PROMPTS WILL DEFAULT YES. Files may be destroyed.")
if arg_values.clean:
logging.info("Running cleanup.")
wizard = Wizard()
wizard.cleanup()
op_performed = True
if arg_values.wizard:
logging.info("Running wizard.")
wizard = Wizard()
if PathManager.input_path_exists(''):
logging.info(f"Your input directory is located at: `{PathManager.get_input_path()}`")
logging.warning("INPUT DIRECTORY ALREADY EXISTS!! Input files will be overwritten. Continue? (y/n)[n]")
prompt = input()
if prompt != 'y':
logging.info("Wizard cancelled")
return
else:
logging.warning('Input directory will be overwritten')
wizard.bootstrap(arg_values.force)
op_performed = True
if arg_values.migrate_check:
logging.info("Running migration check")
migrations = MigrationManager()
migrations.log_check_migrations()
op_performed = True
if arg_values.migrate:
logging.info("Running migration")
migrations = MigrationManager()
migrations.migrate()
op_performed = True
if arg_values.migrate_cleanup:
logging.info("Running migration")
migrations = MigrationManager()
migrations.remove_backups()
op_performed = True
if arg_values.version:
logging.info(f"App version {src.radio_sync_version.version}")
src.radio_sync_version_check.check_version()
op_performed = True
if len(arg_values.radios) > 0:
logging.info("Running radio generator.")
radio_generator = RadioGenerator(arg_values.radios)
radio_generator.generate_all_declared()
op_performed = True
if not op_performed:
parser.print_usage()
return
main()