target_unit removed; only unit_system remains; reviewed gettext.py (not complete)

This commit is contained in:
roe-dl
2021-04-25 15:54:47 +02:00
parent 5ea72bbf26
commit 44e2f14dc5
4 changed files with 40 additions and 60 deletions

View File

@@ -48,44 +48,27 @@
"""
from weewx.cheetahgenerator import SearchList
from weewx.units import ValueTuple,ValueHelper
import configobj
import weeutil.weeutil
import weeutil.config
import os
import os.path
#from weewx.units import ValueTuple,ValueHelper
#import configobj
#import weeutil.weeutil
#import weeutil.config
#import os
#import os.path
try:
# Test for new-style weewx v4 logging by trying to import weeutil.logger
import weeutil.logger
import logging
# Test for new-style weewx v4 logging by trying to import weeutil.logger
import weeutil.logger
import logging
log = logging.getLogger(__name__)
log = logging.getLogger(__name__)
def logdbg(msg):
log.debug(msg)
def logdbg(msg):
log.debug(msg)
def loginf(msg):
log.info(msg)
def loginf(msg):
log.info(msg)
def logerr(msg):
log.error(msg)
except ImportError:
# Old-style weewx logging
import syslog
def logmsg(level, msg):
syslog.syslog(level, 'gettext: %s' % msg)
def logdbg(msg):
logmsg(syslog.LOG_DEBUG, msg)
def loginf(msg):
logmsg(syslog.LOG_INFO, msg)
def logerr(msg):
logmsg(syslog.LOG_ERR, msg)
def logerr(msg):
log.error(msg)
class Gettext(SearchList):
@@ -94,6 +77,8 @@ class Gettext(SearchList):
"""Create an instance of the class"""
super(Gettext,self).__init__(generator)
# get the set language code
# (needed for things like <html lang="...">
self.lang = self.generator.skin_dict.get('lang','undefined')
_idx = self.lang.rfind('/')
if _idx>=0:
@@ -102,16 +87,17 @@ class Gettext(SearchList):
if _idx>=0:
self.lang = self.lang[:_idx]
# check if skin_dict contains a section [Labels][[Generic]]
# get it, if it is there, otherwise use an empty dict
self.labels_dict={}
if 'Labels' in self.generator.skin_dict:
if 'Generic' in self.generator.skin_dict['Labels']:
self.labels_dict = self.generator.skin_dict['Labels']['Generic']
d=self.generator.skin_dict
if 'Texts' in d:
self.text_dict = d['Texts']
elif 'Templates' in d:
self.text_dict = d['Templates']
# check if skin_dict contains a section [Texts]
# get if it is there, otherwise use an empty dict
if 'Texts' in self.generator.skin_dict:
self.text_dict = self.generator.skin_dict['Texts']
else:
self.text_dict = {}
if not isinstance(self.text_dict,dict):

View File

@@ -309,34 +309,28 @@ class StdReportEngine(threading.Thread):
lang_config_path, report, e)
raise
# The key 'target_unit' or 'unit_system' defines the target unit
# The key 'unit_system' defines the target unit
# system to be used with the report. The value can be 'US',
# 'METRIC', 'METRICWX', or 'METRICDE'
# Check if a target unit system is defined.
if 'target_unit' in self.config_dict['StdReport'][report]:
# 'target_unit' is set in weewx.conf
target_unit = self.config_dict['StdReport'][report]['target_unit']
elif 'unit_system' in self.config_dict['StdReport'][report]:
if 'unit_system' in self.config_dict['StdReport'][report]:
# 'unit_system' is set in weewx.conf
target_unit = self.config_dict['StdReport'][report]['unit_system']
elif 'target_unit' in skin_dict:
# 'target_unit' is set in skin.conf
target_unit = skin_dict['target_unit']
unit_system = self.config_dict['StdReport'][report]['unit_system']
elif 'unit_system' in skin_dict:
# 'unit_system' is set in skin.conf
target_unit = skin_dict['unit_system']
unit_system = skin_dict['unit_system']
else:
# No unit system defined. Use defaults.
target_unit = None
log.debug("target unit system for report '%s': %s" % (report,target_unit))
unit_system = None
log.debug("unit system for report '%s': %s" % (report,unit_system))
# If a target unit system is defined get the appropriate dict
# If a unit system is defined get the appropriate dict
# out of units.py.
if target_unit:
if unit_system:
try:
merge_dict = weewx.units.std_groups[weewx.units.unit_constants[target_unit]]
merge_dict = weewx.units.std_groups[weewx.units.unit_constants[unit_system]]
except (KeyError,IndexError):
merge_dict = {}
@@ -346,7 +340,7 @@ class StdReportEngine(threading.Thread):
weeutil.config.merge_config(skin_dict, merge_dict)
if self.first_run:
log.info("Using unit system %s for report '%s'" %
(target_unit, report))
(unit_system, report))
except (SyntaxError,TypeError,IOError) as e:
log.error("error merging target unit system for report '%s'" % report)
pass

View File

@@ -443,7 +443,8 @@ Version: 4.6
<p>
Each report has a <em>skin</em> associated with it. For most reports, the relationship with the skin is an
obvious one: it contains the templates, any auxiliary files such as background GIFs or CSS style sheets, and
obvious one: it contains the templates, any auxiliary files such as background
GIFs or CSS style sheets, files with localization data, and
a <em>skin configuration file</em>, <span class="code">skin.conf</span>. If you will, the skin controls the
<em>look and feel </em>of the report. Note that more than one report can use the same skin. For example, you
might want to run a report that uses US Customary units, then run another report against the same skin, but
@@ -1206,12 +1207,12 @@ db_manager.getSql("SELECT SUM(rain) FROM %s "\
<span class="highlight"> [[SeasonsUSReport]]</span>
skin = Seasons
<span class="higlight">target_unit = US</span>
<span class="higlight">unit_system = US</span>
enable = true
<span class="highlight"> [[SeasonsMetricReport]]
skin = Seasons
target_unit = METRIC
unit_system = METRIC
enable = true
HTML_ROOT = public_html/metric</pre>
<p>

View File

@@ -2264,7 +2264,7 @@ longitude = -77.0366</pre>
<p>
These are the four reports that actually generate HTML files and plots. They all ship in the standard WeeWX
distribution. They all use US Customary units by default, but this can be changed
by setting the option <span class="code">target_unit</span>/<span
by setting the option <span
class="code">unit_system</span> or
by editing section <a href="#Section_Defaults"><span
class="code">[StdReport][[Defaults]]</span></a>.
@@ -2297,8 +2297,7 @@ longitude = -77.0366</pre>
the file according to the list in ISO&nbsp;639-1.
</p>
<p><span class="config_option">target_unit</span><br/>
<span class="config_option">unit_system</span></p>
<p><span class="config_option">unit_system</span></p>
<p>
Which unit system to use with the skin. That can be
<span class="code">US</span>,