-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBalloonCfg.py
105 lines (93 loc) · 5.04 KB
/
BalloonCfg.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
#!/usr/bin/python
#==============================================================================================================#
# #
# getBalloonCfg -- function for reading INI file for Balloon variables #
# #
# Copyright (C) 2023 Mike Pate - K5MAP #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# Reference https://www.pythonforbeginners.com/basics/convert-ini-file-to-dictionary-in-python #
#==============================================================================================================#
#
# if not already installled, use pip to install the following
#
# pip install configupdater
#
#==============================================================================================================#
import sys
import logging
import argparse
from configupdater import ConfigUpdater
import configparser
from constants import CFG_FILE
def getBalloonCfg() -> dict:
"""
Retrieve parameters from a config file to track a balloon
: param (none)
: return: dict
"""
parser = argparse.ArgumentParser()
parser.add_argument("bCallSign", help="Enter Balloon Callsign with SSID")
args = parser.parse_args()
cfgUpdater = ConfigUpdater()
cfgUpdater.read(CFG_FILE)
cfg = cfgUpdater.to_dict()
return cfg[args.bCallSign.upper()]
#==============================================================================================================#
def checkCfg(bCallsign: str):
"""
Verify each parameter for a balloon has been defined in the config file
: param bCallsign: string
: return: (none)
"""
if 'tracker' not in bCallsign.keys():
logging.error(f" *** Item 'tracker' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'uploadcallsign' not in bCallsign.keys():
logging.error(f" *** Item 'uploadcallsign' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'wsprcallsign' not in bCallsign.keys():
logging.error(f" *** Item 'wsprcallsign' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'ballooncallsign' not in bCallsign.keys():
logging.error(f" *** Item 'ballooncallsign' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'timeslot' not in bCallsign.keys():
logging.error(f" *** Item 'timeslot' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'comment' not in bCallsign.keys():
logging.error(f" *** Item 'comment' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'uploadsite' not in bCallsign.keys():
logging.error(f" *** Item 'uploadsite' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'telemetryfile' not in bCallsign.keys():
logging.error(f" *** Item 'telemetryfile' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if 'ldatetime' not in bCallsign.keys():
logging.error(f" *** Item 'ldatetime' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if bCallsign['tracker'] == 'U' and 'channel' not in bCallsign.keys():
logging.error(f" *** Item 'channel' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
if bCallsign['tracker'] == 'U' and 'band' not in bCallsign.keys():
logging.error(f" *** Item 'band' was NOT found in CFG file" )
sys.exit( "\n*** Missing CFG item, check log file ***" )
return
#==============================================================================================================#
def putBalloonCfg(Balloon: str, lDateTime: str):
"""
Update balloon parameters in the config file
: param Balloon: string, lDateTime: string
: return: (none)
"""
# save last datetime to ini
cfgUpdater = ConfigUpdater()
cfgUpdater.read(CFG_FILE)
cfgUpdater[Balloon]['ldatetime'].value = lDateTime
cfgUpdater.update_file()
return