forked from weewx/weewx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wee_config
executable file
·123 lines (105 loc) · 5.5 KB
/
wee_config
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
#!/usr/bin/env python
#
# Copyright (c) 2009-2020 Tom Keffer <[email protected]>
#
# See the file LICENSE.txt for your rights.
#
"""Configure the configuration file."""
from __future__ import absolute_import
import sys
import optparse
from weecfg.config import ConfigEngine, Logger
usage = """Usage: wee_config --help
wee_config --version
wee_config --list-drivers
wee_config --reconfigure CONFIG_FILE|--config=CONFIG_FILE
[--driver=DRIVER] [--units=(us|metric)]
[--latitude=yy.y] [--longitude=xx.x] [--altitude=zz.z,(foot|meter)]
[--location="Home Sweet Home"] [--register=(y,n)]
[--output=OUT_CONFIG] [--no-prompt] [--no-backup] [--verbosity=N]
wee_config --install --dist-config=DIST_CONFIG --output=OUT_CONFIG
[--driver=DRIVER] [--units=(us|metric)]
[--latitude=yy.y] [--longitude=xx.x] [--altitude=zz.z,(foot|meter)]
[--location="Home Sweet Home"] [--register=(y,n)]
[--no-prompt] [--no-backup] [--verbosity=N]
wee_config --upgrade CONFIG_FILE|--config=CONFIG_FILE
--dist-config=DIST_CONFIG
[--output=OUT_CONFIG] [--no-prompt] [--no-backup]
[--warn-on-error] [--verbosity=N]
User actions:
--version Show the WeeWX version, then exit.
--list-drivers List the available weewx device drivers, then exit.
--reconfigure Modify an existing configuration file CONFIG_FILE with any
specified station parameters. Use this command with the
--driver option to change the device driver.
System actions (not normally done by users):
--install Install a new configuration file starting with the contents of
DIST_CONFIG, prompting for station parameters.
--upgrade Update the contents of configuration file CONFIG_FILE to the
installed version, then merge the result with the contents of
configuration file DIST_CONFIG.
Station parameters:
--driver --units
--latitude --longitude
--altitude --location
--register
"""
def main():
# Create a command line parser:
parser = optparse.OptionParser(usage=usage)
# Add the various options:
parser.add_option("--version", action="store_true",
help="Show the weewx version then exit.")
parser.add_option("--list-drivers", action="store_true",
help="List the available device drivers.")
parser.add_option("--reconfigure", action="store_true",
help="Reconfigure an existing configuration file.")
parser.add_option("--install", action="store_true",
help="Install a new configuration file.")
parser.add_option("--upgrade", action="store_true",
help="Update an existing configuration file, then merge "
"with contents of DIST_CONFIG.")
parser.add_option("--config", dest="config_path", metavar="CONFIG_FILE",
help="Use configuration file CONFIG_FILE.")
parser.add_option("--dist-config",
help="Use template configuration file DIST_CONFIG.")
parser.add_option("--output", metavar="OUT_CONFIG",
help="Save to configuration file OUT_CONFIG. If not "
"specified then replace existing configuration file.")
parser.add_option("--driver", metavar="DRIVER",
help="Use the driver DRIVER. "
"For example, weewx.drivers.vantage")
parser.add_option("--latitude", metavar="yy.y",
help="The station latitude in decimal degrees.")
parser.add_option("--longitude", metavar="xx.x",
help="The station longitude in decimal degrees.")
parser.add_option("--altitude", metavar="zz,(foot|meter)",
help="The station altitude in either feet or meters."
" For example, '750,foot' or '320,meter'")
parser.add_option("--location",
help="""A text description of the station."""
""" For example, "Santa's workshop, North Pole" """)
parser.add_option("--units", choices=["us", "metric"], metavar="(metric|us)",
help="Set display units to 'metric' or 'us'.")
parser.add_option("--register", dest='register_this_station', choices=['y', 'n'],
metavar="(y/n)",
help="Register this station in the weewx registry?")
parser.add_option("--no-prompt", action="store_true",
help="Do not prompt. Use default or specified values.")
parser.add_option("--no-backup", action="store_true", default=False,
help="When replacing an existing configuration file, "
"do not create a backup copy.")
parser.add_option("--warn-on-error", action="store_true", default=False,
help="Only warn if an update is not possible. Default "
"behavior is to warn then exit.")
parser.add_option("--debug", action="store_true",
help="Show diagnostic information while running.")
parser.add_option('--verbosity', type=int, default=1,
metavar="N", help='How much status to display, 0-3')
# Now we are ready to parse the command line:
(options, args) = parser.parse_args()
config_mgr = ConfigEngine(logger=Logger(verbosity=options.verbosity))
config_mgr.run(args, options)
sys.exit(0)
if __name__ == "__main__" :
main()