diff --git a/bin/config_util.py b/bin/config_util.py index 83d90248..7ac9eff9 100644 --- a/bin/config_util.py +++ b/bin/config_util.py @@ -851,3 +851,25 @@ def prompt_with_limits(prompt, default=None, low_limit=None, high_limit=None): value = default return value + +def extract_roots(config_path, config_dict): + """Get the location of the various root directories used by weewx.""" + + root_dict = {'WEEWX_ROOT' : config_dict['WEEWX_ROOT'], + 'CONFIG_ROOT' : os.path.dirname(config_path), + 'BIN_ROOT' : config_dict.get('BIN_ROOT')} + # If there is no BIN_ROOT in the configuration dictionary, then set it + # to the location of this file: + if root_dict['BIN_ROOT'] is None: + root_dict['BIN_ROOT'] = os.path.dirname(__file__) + # The extensions directory can be found off of BIN_ROOT: + root_dict['EXT_ROOT'] = os.path.join(root_dict['BIN_ROOT'], 'user', 'installer') + # Add SKIN_ROOT if it can be found: + try: + root_dict['SKIN_ROOT'] = os.path.abspath(os.path.join(root_dict['WEEWX_ROOT'], + config_dict['StdReport']['SKIN_ROOT'])) + except KeyError: + pass + + return root_dict + diff --git a/bin/wee_config b/bin/wee_config index 4b7adfa8..09c8fbfc 100755 --- a/bin/wee_config +++ b/bin/wee_config @@ -16,14 +16,6 @@ import configobj import weewx import config_util -stn_info_defaults = {'location' : '', - 'latitude' : '0', - 'longitude' : '0', - 'altitude' : ['0', 'meter'], - 'units' : 'metric', - 'station_type' : 'Vantage', - 'driver' : 'weewx.drivers.Vantage'} - usage="""wee_config --help wee_config --version wee_config --list-drivers @@ -63,6 +55,10 @@ weewx.conf). Its location can be given as a command-line argument, or it can be specified with option --config. """ +# The default station information: +stn_info_defaults = {'station_type' : 'Simulator', + 'driver' : 'weewx.drivers.simulator'} + def main(): # Set defaults for the system logger: @@ -95,7 +91,7 @@ def main(): help="Where the results should be written.") parser.add_option("--no-prompt", action="store_true", help="Do not issue prompts. Use default values or specified options.") - parser.add_option("--driver", metavar="DRIVER", dest="driver", + parser.add_option("--driver", metavar="DRIVER", help="Use the driver DRIVER, e.g., weewx.driver.vantage. ") parser.add_option("--latitude", metavar="yy.y", help="The station latitude") diff --git a/bin/wee_extension b/bin/wee_extension new file mode 100755 index 00000000..f4043a36 --- /dev/null +++ b/bin/wee_extension @@ -0,0 +1,112 @@ +#!/usr/bin/env python +# +# Copyright (c) 2009-2015 Tom Keffer and +# Matthew Wall +# +# See the file LICENSE.txt for your full rights. +# +"""Install and remove extensions.""" +from __future__ import with_statement + +import os.path +import optparse +import sys +import shutil +from subprocess import Popen, PIPE + +import configobj + +import config_util + +usage = """wee_extension --help + wee_extension --list + [CONFIG_FILE|--config=CONFIG_FILE] + wee_extension --install=(filename|directory) + [CONFIG_FILE|--config=CONFIG_FILE] + [--tmpdir==DIR] [--dry-run] [--verbosity=N] + wee_extension --uninstall=EXTENSION + [CONFIG_FILE|--config=CONFIG_FILE] + [--verbosity=N] + +COMMANDS: + +--list: List all installed extensions +--install: Install the extension that can be found in the + named file or directory. +--uninstall: Uninstall the given extension.""" + +description = "This utility can install/remove/list extensions to weewx" + +def main(): + parser = optparse.OptionParser(description=description, usage=usage) + parser.add_option('--list', action="store_true", dest="list_extensions", + help="List all installed extensions") + parser.add_option('--install', metavar="filename|directory", + help="Install the driver found in filename or directory") + parser.add_option('--uninstall', metavar="EXTENSION", + help="Uninstall the extension with name EXTENSION") + parser.add_option("--config", metavar="CONFIG_FILE", + help="Use configuration file CONFIG_FILE.") + parser.add_option('--tmpdir', default='/var/tmp', + metavar="DIR", help='Use DIR as the temporary directory') + parser.add_option('--bin-root', metavar="BIN_ROOT", + help="Look in BIN_ROOT for Python executables (useful for debugging)") + parser.add_option('--dry-run', action='store_true', + help='Print what would happen but do not do it') + parser.add_option('--verbosity', type=int, default=1, + metavar="N", help='How much status to spew, 0-3') + + # Now we are ready to parse the command line: + (options, _args) = parser.parse_args() + + ext = Extension(_args, **vars(options)) + ext.run() + return 0 + + +class Logger(object): + def __init__(self, verbosity=0): + self.verbosity = verbosity + def log(self, msg, level=0): + if self.verbosity >= level: + print "%s%s" % (' ' * (level - 1), msg) + def set_verbosity(self, verbosity): + self.verbosity = verbosity + +class Extension(object): + + def __init__(self, args=None, list_extensions=None, install=None, uninstall=None, config=None, + tmpdir=None, bin_root=None, dry_run=None, verbosity=None): + self.logger = Logger(verbosity) + self.list_extensions = list_extensions + self.install = install + self.uninstall = uninstall + self.tmpdir = tmpdir + self.dry_run = dry_run + self.config_path, self.config_dict = config_util.read_config(config, args) + # BIN_ROOT does not normally appear in the configuration dictionary. Set a + # default (which could be 'None') + self.config_dict.setdefault('BIN_ROOT', bin_root) + self.root_dict = config_util.extract_roots(self.config_path, self.config_dict) + self.logger.log("root dictionary: %s" % self.root_dict, 1) + + def run(self): + if self.list_extensions: + self.enumerate_extensions() + + def enumerate_extensions(self): + ext_root = self.root_dict['EXT_ROOT'] + try: + exts = os.listdir(ext_root) + if exts: + for f in exts: + self.logger.log(f, level=0) + else: + self.logger.log("Extension cache is '%s'" % ext_root, level=2) + self.logger.log("No extensions installed", level=0) + except OSError: + self.logger.log("No extension cache '%s'" % ext_root, level=2) + +if __name__=="__main__" : + main() + diff --git a/bin/weewxd.py b/bin/weewxd.py deleted file mode 120000 index 0df1e0eb..00000000 --- a/bin/weewxd.py +++ /dev/null @@ -1 +0,0 @@ -./weewxd \ No newline at end of file diff --git a/bin/weewxd.py b/bin/weewxd.py new file mode 100755 index 00000000..79b04e5b --- /dev/null +++ b/bin/weewxd.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# +# Copyright (c) 2009-2015 Tom Keffer +# +# See the file LICENSE.txt for your full rights. +# +"""Entry point to the weewx weather system.""" +import sys +from optparse import OptionParser + +# First import any user extensions: +import user.extensions #@UnusedImport +# Now the engine +import weewx.engine + +usagestr = """ + %prog config_path [--daemon] [--pidfile=PIDFILE] [--exit] [--loop-on-init] + [--version] [--help] + + Entry point to the weewx weather program. Can be run directly, or as a daemon + by specifying the '--daemon' option. + +Arguments: + config_path: Path to the weewx configuration file to be used. +""" + +#=============================================================================== +# function parseArgs() +#=============================================================================== + +def parseArgs(): + """Parse any command line options.""" + + parser = OptionParser(usage=usagestr) + parser.add_option("-d", "--daemon", action="store_true", dest="daemon", help="Run as a daemon") + parser.add_option("-p", "--pidfile", type="string", dest="pidfile", help="Path to process ID file", default="/var/run/weewx.pid") + parser.add_option("-v", "--version", action="store_true", dest="version", help="Display version number then exit") + parser.add_option("-x", "--exit", action="store_true", dest="exit" , help="Exit on I/O and database errors instead of restarting") + parser.add_option("-r", "--loop-on-init", action="store_true", dest="loop_on_init" , help="Loop if device is not ready on startup") + (options, args) = parser.parse_args() + + if options.version: + print weewx.__version__ + sys.exit() + + if len(args) < 1: + sys.stderr.write("Missing argument(s).\n") + sys.stderr.write(parser.parse_args(["--help"])) + sys.exit(weewx.CMD_ERROR) + + return options, args + +#=============================================================================== +# Main entry point +#=============================================================================== + +# Get the command line options and arguments: +(options, args) = parseArgs() + +# Fire up the engine. +weewx.engine.main(options, args)