-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGetRDMConfig.py
174 lines (117 loc) · 5.08 KB
/
GetRDMConfig.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
import os
import sys
from collections import OrderedDict
try:
# Python 2
import ConfigParser as configparser
except:
# Python 3
import configparser
class RDMConfig(object):
def __init__(self):
""" Config container. """
self.station_code = None
self.channel = None
self.latitude = None
self.longitude = None
self.elevation = None
self.instrument_string = None
self.raw = None
self.zipped = None
self.mode = None
self.gain = None
self.upload_enabled = None
self.hostname = None
self.rsa_private_key = None
self.upload_queue_file = None
self.remote_dir = None
self.read_from_server = False
self.mains_frequency = 60
def readConfig(config_file_path):
""" Generates two plots of the nights data.
Arguments:
config_file_path: [str] The path to the directory that stores the configuration file.
E.g.: /home/pi/RadiometerData/config.txt
Return:
rdm_config: [object] The configuration object.
"""
# Create the configuration object
rdm_config = RDMConfig()
# Create a config object
config = configparser.ConfigParser()
# Read the config file into the object
config.read(config_file_path)
# Gather configuration data for the station
rdm_config.station_code = config['Station']['StationCode']
rdm_config.channel = config['Station']['Channel']
rdm_config.latitude = float(config['Station']['Latitude'])
rdm_config.longitude = float(config['Station']['Longitude'])
rdm_config.elevation = float(config['Station']['Elevation'])
rdm_config.instrument_string = config['Station']['InstrumentString']
rdm_config.raw = config['Station']['RawData']
rdm_config.zipped = config['Station']['StoredData']
rdm_config.mode = int(config['Station']['DifferentialMode'])
rdm_config.gain = int(config['Station']['Gain'])
# Gather configuration data for the upload manager
rdm_config.upload_enabled = (config['Upload']['EnableUpload'].lower().strip() == "true")
rdm_config.hostname = config['Upload']['HostName']
rdm_config.rsa_private_key = config['Upload']['RSAPrivateKey']
rdm_config.upload_queue_file = config['Upload']['QueueFilename']
rdm_config.remote_dir = config['Upload']['RemoteDirectory']
# If True, it means that this instance of the code is running on the server
rdm_config.read_from_server = (config['Server']['ReadFromServer'].lower().strip() == "true")
# Filtering parameters
rdm_config.mains_frequency = float(config['Filtering']['MainsFrequency'])
# Return the configuration object
return rdm_config
def makeConfig(config_file_path):
""" Generates two plots of the nights data.
Input Arguments:
-config_file_path (string): The path to the directory that will store the configuration file. Ex: /home/pi/RadiometerData/config.txt
Outputs:
- One config.txt file saved in config_file_path
"""
# There was no detected config file so one will be created
# An error message explaining the issue
print("No config file detected in /home/pi/RadiometerData")
print("A default config file has been created and can be changed in RadiometerData")
# Create a config object
config = configparser.ConfigParser()
# optionxform prevents it from naming all config parameters with lower case letters
config.optionxform = str
# Creates the station data inside the config file using default values
config['Station'] = OrderedDict((
('StationCode', 'AA0000'),
('Channel', 'A'),
('Latitude', '0.0'),
('Longitude', '0.0'),
('Elevation', '0.0'),
('InstrumentString', 'Your description'),
('RawData','CapturedData'),
('StoredData','ArchivedData'),
('DifferentialMode','1'),
('Gain','1')
))
# Creates the upload manager configuration section using default settings
config['Upload'] = OrderedDict((
('EnableUpload', 'True'),
('HostName', ''),
('RSAPrivateKey', '~/.ssh/id_rsa'),
('QueueFilename','FILES_TO_UPLOAD.inf'),
('RemoteDirectory','.')
))
# Creates the upload manager configuration section using default settings
config['Server'] = OrderedDict((
('ReadFromServer', 'False'),
))
# Creates the upload manager configuration section using default settings
config['Filtering'] = OrderedDict((
('MainsFrequency', '60'),
))
# Generate the file in the desired directory and close it
with open(config_file_path, 'w') as configfile:config.write(configfile)
configfile.closed
# Allow the user to configure the config file
os.chmod(config_file_path, 0o777)
# Exit allowing the user to configure their settings
sys.exit()