mirror of
https://github.com/weewx/weewx.git
synced 2026-06-10 10:05:20 -04:00
The database to be used is now nominated by the more intuitive keyword 'database' (instead of 'binding').
This commit is contained in:
3
TODO.txt
3
TODO.txt
@@ -1,8 +1,5 @@
|
||||
TODO before the next release:
|
||||
|
||||
Come up with more consistent names for database symbolic names such
|
||||
as 'archive_database' vs the database name. Maybe 'binding'?
|
||||
|
||||
Allow any archive database to have its daily summary rebuilt.
|
||||
|
||||
Capture LOOP data for highs and lows
|
||||
|
||||
@@ -32,7 +32,7 @@ usage="""%prog: [config_path] [--help]
|
||||
[--create-archive] [--drop-daily] [--backfill-daily]
|
||||
[--reconfigure]
|
||||
[--string-check] [--fix]
|
||||
[--binding=BINDING_NAME]"""
|
||||
[--database=DATABASE_NAME]"""
|
||||
|
||||
epilog="""If you are using the MySQL database it is assumed that you have the
|
||||
appropriate permissions for the requested operation."""
|
||||
@@ -64,19 +64,19 @@ def main():
|
||||
help="Check a sqlite version of the archive database for embedded strings in it.")
|
||||
parser.add_option("--fix", dest="fix", action="store_true",
|
||||
help="If a string is found, fix it.")
|
||||
parser.add_option("--binding", dest="binding", metavar="BINDING_NAME",
|
||||
default='wx_binding',
|
||||
help="The symbolic name of the database the action is to be applied to. Default is 'wx_binding'")
|
||||
parser.add_option("--database", dest="symname", metavar="DATABASE_NAME",
|
||||
default='wx_database',
|
||||
help="The symbolic name of the database the action is to be applied to. Default is 'wx_database'")
|
||||
|
||||
# Now we are ready to parse the command line:
|
||||
(options, args) = parser.parse_args()
|
||||
config_fn, config_dict = weeutil.weeutil.read_config(options.cfgfn, args)
|
||||
print "Using configuration file %s." % config_fn
|
||||
|
||||
db_binding = options.binding
|
||||
database_name = config_dict['Databases'][db_binding]
|
||||
database_dict, database_cls = weewx.archive.prep_database(config_dict['Databases'], db_binding)
|
||||
print "Using database binding '%s', which is bound to database '%s'" % (db_binding, database_name)
|
||||
db_symname = options.symname
|
||||
database_name = config_dict['Databases'][db_symname]
|
||||
database_dict, database_cls = weewx.archive.prep_database(config_dict['Databases'], db_symname)
|
||||
print "Using database symname '%s', which is bound to database '%s'" % (db_symname, database_name)
|
||||
|
||||
if options.create_archive:
|
||||
createMainDatabase(database_dict, database_cls, database_name)
|
||||
@@ -88,10 +88,10 @@ def main():
|
||||
backfillDaily(database_dict, database_cls, database_name)
|
||||
|
||||
if options.reconfigure:
|
||||
reconfigMainDatabase(config_dict, db_binding)
|
||||
reconfigMainDatabase(config_dict, db_symname)
|
||||
|
||||
if options.string_check:
|
||||
string_check(config_dict, options.fix, db_binding)
|
||||
string_check(config_dict, options.fix, db_symname)
|
||||
|
||||
def createMainDatabase(database_dict, database_cls, database_name):
|
||||
"""Create a weewx archive database"""
|
||||
|
||||
@@ -689,18 +689,18 @@ class DBCache(object):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def get_database(self, database='wx_binding'):
|
||||
if database not in self.archive_cache:
|
||||
db_dict, db_cls = prep_database(self.db_dicts, database)
|
||||
self.archive_cache[database] = db_cls.open(db_dict)
|
||||
return self.archive_cache[database]
|
||||
def get_database(self, symname='wx_database'):
|
||||
if symname not in self.archive_cache:
|
||||
db_dict, db_cls = prep_database(self.db_dicts, symname)
|
||||
self.archive_cache[symname] = db_cls.open(db_dict)
|
||||
return self.archive_cache[symname]
|
||||
|
||||
#===============================================================================
|
||||
# Utilities
|
||||
#===============================================================================
|
||||
|
||||
def prep_database(databases_dict, archive_binding_name='wx_binding'):
|
||||
database_name = databases_dict[archive_binding_name]
|
||||
def prep_database(databases_dict, archive_database_symname='wx_database'):
|
||||
database_name = databases_dict[archive_database_symname]
|
||||
database_dict = databases_dict[database_name]
|
||||
database_manager = databases_dict[database_name].get('manager', 'weewx.stats.WXDaySummaryArchive')
|
||||
database_cls = weeutil.weeutil._get_object(database_manager)
|
||||
|
||||
@@ -102,7 +102,7 @@ class StdReportEngine(threading.Thread):
|
||||
continue
|
||||
|
||||
# Add the default database source.
|
||||
skin_dict['database'] = 'wx_binding'
|
||||
skin_dict['database'] = 'wx_database'
|
||||
|
||||
# Inject any overrides the user may have specified in the weewx.conf
|
||||
# configuration file for all reports:
|
||||
|
||||
@@ -15,16 +15,16 @@ import weewx.units
|
||||
#===============================================================================
|
||||
|
||||
class DBFactory(object):
|
||||
"""Binds a database cache, with a default binding."""
|
||||
"""Binds a database cache, with a default database symname."""
|
||||
|
||||
def __init__(self, db_cache, default_binding='wx_binding'):
|
||||
def __init__(self, db_cache, default_symname='wx_database'):
|
||||
self.cache = db_cache
|
||||
self.default_binding = default_binding
|
||||
self.default_symname = default_symname
|
||||
|
||||
def get_database(self, binding=None):
|
||||
if binding is None:
|
||||
binding = self.default_binding
|
||||
return self.cache.get_database(binding)
|
||||
def get_database(self, database=None):
|
||||
if database is None:
|
||||
database = self.default_symname
|
||||
return self.cache.get_database(database)
|
||||
|
||||
#===============================================================================
|
||||
# Class FactoryBinder
|
||||
@@ -34,7 +34,7 @@ class FactoryBinder(object):
|
||||
"""Binds a DBFactory, a timespan, and a default archive database together.
|
||||
|
||||
This class sits on the top of chain of helper classes that enable
|
||||
syntax such as $db($binding='wx_binding').month.rain.sum in the Cheetah templates."""
|
||||
syntax such as $db($database='wx_database').month.rain.sum in the Cheetah templates."""
|
||||
|
||||
def __init__(self, dbfactory, endtime_ts,
|
||||
formatter=weewx.units.Formatter(), converter=weewx.units.Converter(), **option_dict):
|
||||
@@ -45,8 +45,8 @@ class FactoryBinder(object):
|
||||
self.converter = converter
|
||||
self.option_dict = option_dict
|
||||
|
||||
def db(self, binding=None):
|
||||
opendb = self.dbfactory.get_database(binding)
|
||||
def db(self, database=None):
|
||||
opendb = self.dbfactory.get_database(database)
|
||||
return DatabaseBinder(opendb, self.endtime_ts, self.formatter, self.converter, **self.option_dict)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
|
||||
@@ -582,8 +582,8 @@ class StdArchive(StdService):
|
||||
|
||||
archive_schema_str = config_dict['StdArchive'].get('archive_schema', 'user.schemas.defaultArchiveSchema')
|
||||
archive_schema = weeutil.weeutil._get_object(archive_schema_str)
|
||||
archive_binding = config_dict['StdArchive'].get('binding', 'wx_binding')
|
||||
db_dict, db_cls = weewx.archive.prep_database(config_dict['Databases'], archive_binding)
|
||||
archive_symname = config_dict['StdArchive'].get('database', 'wx_database')
|
||||
db_dict, db_cls = weewx.archive.prep_database(config_dict['Databases'], archive_symname)
|
||||
# This will create the database if it doesn't exist, then return an
|
||||
# opened instance of Archive. It also attaches a reference to the engine, so other
|
||||
# services can use it.
|
||||
|
||||
12
weewx.conf
12
weewx.conf
@@ -348,8 +348,8 @@ version = 2.6.3
|
||||
# Where the generated reports should go, relative to WEEWX_ROOT:
|
||||
HTML_ROOT = public_html
|
||||
|
||||
# The database binding to be used in the reports
|
||||
binding = wx_binding
|
||||
# The database to be used in the reports
|
||||
database = wx_database
|
||||
|
||||
# Each subsection represents a report you wish to run:
|
||||
[[StandardReport]]
|
||||
@@ -512,8 +512,8 @@ version = 2.6.3
|
||||
# Thereafter, the types are retrieved from the database.
|
||||
archive_schema = user.schemas.defaultArchiveSchema
|
||||
|
||||
# The database binding to be used.
|
||||
binding = wx_binding
|
||||
# The database to be used.
|
||||
database = wx_database
|
||||
|
||||
##############################################################################
|
||||
|
||||
@@ -530,9 +530,9 @@ version = 2.6.3
|
||||
[Databases]
|
||||
# This section lists possible databases.
|
||||
|
||||
# The binding to be used for the weather data. It should match
|
||||
# The database to be used for the weather data. It should match
|
||||
# one of the sections below.
|
||||
wx_binding = archive_sqlite
|
||||
wx_database = archive_sqlite
|
||||
|
||||
[[archive_sqlite]]
|
||||
root = %(WEEWX_ROOT)s
|
||||
|
||||
Reference in New Issue
Block a user