diff --git a/bin/weecfg/extension.py b/bin/weecfg/extension.py index cafb8cb4..ad73cce9 100644 --- a/bin/weecfg/extension.py +++ b/bin/weecfg/extension.py @@ -13,6 +13,7 @@ # -user/installer/pmon/ # The extension's installer subdirectory # -user/installer/pmon/install.py # The copy of the installer for the extension +import glob import os import shutil import sys @@ -385,15 +386,15 @@ class ExtensionEngine(object): # Now go through all the files of the source tuple for install_file in source_tuple[1]: dst_file = ExtensionEngine._strip_leading_dir( - install_file) + install_file) destination_path = os.path.abspath( os.path.join(self.root_dict[root_type], dst_file)) + file_name = os.path.basename(destination_path) + # There may be a versioned skin.conf. Delete it by adding a wild card. + # Similarly, be sure to delete Python files with .pyc or .pyo extensions. + if file_name == 'skin.conf' or file_name.endswith('py'): + destination_path += "*" N += self.delete_file(destination_path) - if destination_path.endswith('.py'): - N += self.delete_file( - destination_path.replace('.py', '.pyc'), False) - N += self.delete_file( - destination_path.replace('.py', '.pyo'), False) # Accumulate all directories under 'skins' if root_type == 'SKIN_ROOT': dst_dir = ExtensionEngine._strip_leading_dir( @@ -416,22 +417,27 @@ class ExtensionEngine(object): self.delete_directory(dirpath) def delete_file(self, filename, report_errors=True): - """Delete the given file from the file system. + """Delete files from the file system. - filename: The path to the file to be deleted. + filename: The path to the file(s) to be deleted. Can include wildcards. report_errors: If true, report an error if the file is missing or cannot be deleted. Otherwise don't. In - neither case will an exception be raised. """ - try: - self.logger.log("Deleting file %s" % filename, level=2) + neither case will an exception be raised. + + Returns: The number of files deleted + """ + n_deleted = 0 + for fn in glob.glob(filename): + self.logger.log("Deleting file %s" % fn, level=2) if not self.dry_run: - os.remove(filename) - return 1 - except OSError as e: - if report_errors: - self.logger.log("Delete failed: %s" % e, level=4) - return 0 + try: + os.remove(fn) + n_deleted += 1 + except OSError as e: + if report_errors: + self.logger.log("Delete failed: %s" % e, level=4) + return n_deleted def delete_directory(self, directory, report_errors=True): """Delete the given directory from the file system. diff --git a/bin/weecfg/test/expected/weewx39_expected.conf b/bin/weecfg/test/expected/weewx39_expected.conf index 01bbb4f6..c880b8e4 100644 --- a/bin/weecfg/test/expected/weewx39_expected.conf +++ b/bin/weecfg/test/expected/weewx39_expected.conf @@ -380,6 +380,196 @@ version = 3.9.0 ############################################################################## +# Default values for skins + +[Defaults] + + # The following section is for managing the selection and formatting of units. + [[Units]] + + # The following section sets what unit to use for each unit group. + # NB: The unit is always in the singular. I.e., 'mile_per_hour', + # NOT 'miles_per_hour' + [[[Groups]]] + group_altitude = foot # Options are 'foot' or 'meter' + group_degree_day = degree_F_day # Options are 'degree_F_day' or 'degree_C_day' + group_direction = degree_compass + group_moisture = centibar + group_percent = percent + group_pressure = inHg # Options are 'inHg', 'mmHg', 'mbar', or 'hPa' + group_radiation = watt_per_meter_squared + group_rain = inch # Options are 'inch', 'cm', or 'mm' + group_rainrate = inch_per_hour # Options are 'inch_per_hour', 'cm_per_hour', or 'mm_per_hour' + group_speed = mile_per_hour # Options are 'mile_per_hour', 'km_per_hour', 'knot', or 'meter_per_second' + group_speed2 = mile_per_hour2 # Options are 'mile_per_hour2', 'km_per_hour2', 'knot2', or 'meter_per_second2' + group_temperature = degree_F # Options are 'degree_F' or 'degree_C' + group_uv = uv_index + group_volt = volt + + # The following are used internally and should not be changed: + group_count = count + group_interval = minute + group_time = unix_epoch + group_elapsed = second + + # The following section sets the string formatting for each type of unit. + [[[StringFormats]]] + + centibar = %.0f + cm = %.2f + cm_per_hour = %.2f + degree_C = %.1f + degree_F = %.1f + degree_compass = %.0f + foot = %.0f + hPa = %.1f + hour = %.1f + inHg = %.3f + inch = %.2f + inch_per_hour = %.2f + km_per_hour = %.0f + km_per_hour2 = %.1f + knot = %.0f + knot2 = %.1f + mbar = %.1f + meter = %.0f + meter_per_second = %.1f + meter_per_second2 = %.1f + mile_per_hour = %.0f + mile_per_hour2 = %.1f + mm = %.1f + mmHg = %.1f + mm_per_hour = %.1f + percent = %.0f + second = %.0f + uv_index = %.1f + volt = %.1f + watt_per_meter_squared = %.0f + NONE = " N/A" + + # The following section sets the label to be used for each type of unit + [[[Labels]]] + + centibar = " cb" + cm = " cm" + cm_per_hour = " cm/hr" + degree_C = °C + degree_F = °F + degree_compass = ° + foot = " feet" + hPa = " hPa" + inHg = " inHg" + inch = " in" + inch_per_hour = " in/hr" + km_per_hour = " km/h" + km_per_hour2 = " km/h" + knot = " knots" + knot2 = " knots" + mbar = " mbar" + meter = " meters" + meter_per_second = " m/s" + meter_per_second2 = " m/s" + mile_per_hour = " mph" + mile_per_hour2 = " mph" + mm = " mm" + mmHg = " mmHg" + mm_per_hour = " mm/hr" + percent = % + volt = " V" + watt_per_meter_squared = " W/m²" + day = " day", " days" + hour = " hour", " hours" + minute = " minute", " minutes" + second = " second", " seconds" + NONE = "" + + # The following section sets the string format to be used for each time scale. + # The values below will work in every locale, but they may not look + # particularly attractive. See the Customization Guide for alternatives. + [[[TimeFormats]]] + + day = %X + week = %X (%A) + month = %x %X + year = %x %X + rainyear = %x %X + current = %x %X + ephem_day = %X + ephem_year = %x %X + + [[[Ordinates]]] + # Ordinal directions. The last one should be for no wind direction + directions = N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW, N/A + + # The following section sets the base temperatures used for the calculation + # of heating and cooling degree-days. + [[[DegreeDays]]] + # Base temperature for heating days, with unit: + heating_base = 65, degree_F + # Base temperature for cooling days, with unit: + cooling_base = 65, degree_F + + # A trend takes a difference across a time period. The following section sets + # the time period, and how big an error is allowed to still be counted + # as the start or end of a period. + [[[Trend]]] + time_delta = 10800 # 3 hours + time_grace = 300 # 5 minutes + + # Labels used in this skin + [[Labels]] + + # Set to hemisphere abbreviations suitable for your location: + hemispheres = N, S, E, W + # Formats to be used for latitude whole degrees, longitude whole degrees, + # and minutes: + latlon_formats = %02d, %03d, %05.2f + + # Generic labels, keyed by an observation type. + [[[Generic]]] + + barometer = Barometer + dewpoint = Dew Point + ET = ET + heatindex = Heat Index + inHumidity = Inside Humidity + inTemp = Inside Temperature + outHumidity = Humidity + outTemp = Temperature + radiation = Radiation + rain = Rain + rainRate = Rain Rate + UV = UV Index + windDir = Wind Direction + windGust = Gust Speed + windGustDir = Gust Direction + windSpeed = Wind Speed + windchill = Wind Chill + windgustvec = Gust Vector + windvec = Wind Vector + extraTemp1 = Temperature1 + extraTemp2 = Temperature2 + extraTemp3 = Temperature3 + + # Sensor status indicators + + rxCheckPercent = Signal Quality + txBatteryStatus = Transmitter + windBatteryStatus = Wind + rainBatteryStatus = Rain + outTempBatteryStatus = Outside Temperature + inTempBatteryStatus = Inside Temperature + consBatteryVoltage = Console + heatingVoltage = Heating + supplyVoltage = Supply + referenceVoltage = Reference + + [[Almanac]] + # The labels to be used for the phases of the moon: + moon_phases = New, Waxing crescent, First quarter, Waxing gibbous, Full, Waning gibbous, Last quarter, Waning crescent + +############################################################################## + # This section configures the internal weewx engine. [Engine] diff --git a/bin/weecfg/test/expected/weewx_user_expected.conf b/bin/weecfg/test/expected/weewx_user_expected.conf index 19e91237..17e0c76b 100644 --- a/bin/weecfg/test/expected/weewx_user_expected.conf +++ b/bin/weecfg/test/expected/weewx_user_expected.conf @@ -425,6 +425,196 @@ version = 3.9.0a3 ############################################################################## +# Default values for skins + +[Defaults] + + # The following section is for managing the selection and formatting of units. + [[Units]] + + # The following section sets what unit to use for each unit group. + # NB: The unit is always in the singular. I.e., 'mile_per_hour', + # NOT 'miles_per_hour' + [[[Groups]]] + group_altitude = foot # Options are 'foot' or 'meter' + group_degree_day = degree_F_day # Options are 'degree_F_day' or 'degree_C_day' + group_direction = degree_compass + group_moisture = centibar + group_percent = percent + group_pressure = inHg # Options are 'inHg', 'mmHg', 'mbar', or 'hPa' + group_radiation = watt_per_meter_squared + group_rain = inch # Options are 'inch', 'cm', or 'mm' + group_rainrate = inch_per_hour # Options are 'inch_per_hour', 'cm_per_hour', or 'mm_per_hour' + group_speed = mile_per_hour # Options are 'mile_per_hour', 'km_per_hour', 'knot', or 'meter_per_second' + group_speed2 = mile_per_hour2 # Options are 'mile_per_hour2', 'km_per_hour2', 'knot2', or 'meter_per_second2' + group_temperature = degree_F # Options are 'degree_F' or 'degree_C' + group_uv = uv_index + group_volt = volt + + # The following are used internally and should not be changed: + group_count = count + group_interval = minute + group_time = unix_epoch + group_elapsed = second + + # The following section sets the string formatting for each type of unit. + [[[StringFormats]]] + + centibar = %.0f + cm = %.2f + cm_per_hour = %.2f + degree_C = %.1f + degree_F = %.1f + degree_compass = %.0f + foot = %.0f + hPa = %.1f + hour = %.1f + inHg = %.3f + inch = %.2f + inch_per_hour = %.2f + km_per_hour = %.0f + km_per_hour2 = %.1f + knot = %.0f + knot2 = %.1f + mbar = %.1f + meter = %.0f + meter_per_second = %.1f + meter_per_second2 = %.1f + mile_per_hour = %.0f + mile_per_hour2 = %.1f + mm = %.1f + mmHg = %.1f + mm_per_hour = %.1f + percent = %.0f + second = %.0f + uv_index = %.1f + volt = %.1f + watt_per_meter_squared = %.0f + NONE = " N/A" + + # The following section sets the label to be used for each type of unit + [[[Labels]]] + + centibar = " cb" + cm = " cm" + cm_per_hour = " cm/hr" + degree_C = °C + degree_F = °F + degree_compass = ° + foot = " feet" + hPa = " hPa" + inHg = " inHg" + inch = " in" + inch_per_hour = " in/hr" + km_per_hour = " km/h" + km_per_hour2 = " km/h" + knot = " knots" + knot2 = " knots" + mbar = " mbar" + meter = " meters" + meter_per_second = " m/s" + meter_per_second2 = " m/s" + mile_per_hour = " mph" + mile_per_hour2 = " mph" + mm = " mm" + mmHg = " mmHg" + mm_per_hour = " mm/hr" + percent = % + volt = " V" + watt_per_meter_squared = " W/m²" + day = " day", " days" + hour = " hour", " hours" + minute = " minute", " minutes" + second = " second", " seconds" + NONE = "" + + # The following section sets the string format to be used for each time scale. + # The values below will work in every locale, but they may not look + # particularly attractive. See the Customization Guide for alternatives. + [[[TimeFormats]]] + + day = %X + week = %X (%A) + month = %x %X + year = %x %X + rainyear = %x %X + current = %x %X + ephem_day = %X + ephem_year = %x %X + + [[[Ordinates]]] + # Ordinal directions. The last one should be for no wind direction + directions = N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW, N/A + + # The following section sets the base temperatures used for the calculation + # of heating and cooling degree-days. + [[[DegreeDays]]] + # Base temperature for heating days, with unit: + heating_base = 65, degree_F + # Base temperature for cooling days, with unit: + cooling_base = 65, degree_F + + # A trend takes a difference across a time period. The following section sets + # the time period, and how big an error is allowed to still be counted + # as the start or end of a period. + [[[Trend]]] + time_delta = 10800 # 3 hours + time_grace = 300 # 5 minutes + + # Labels used in this skin + [[Labels]] + + # Set to hemisphere abbreviations suitable for your location: + hemispheres = N, S, E, W + # Formats to be used for latitude whole degrees, longitude whole degrees, + # and minutes: + latlon_formats = %02d, %03d, %05.2f + + # Generic labels, keyed by an observation type. + [[[Generic]]] + + barometer = Barometer + dewpoint = Dew Point + ET = ET + heatindex = Heat Index + inHumidity = Inside Humidity + inTemp = Inside Temperature + outHumidity = Humidity + outTemp = Temperature + radiation = Radiation + rain = Rain + rainRate = Rain Rate + UV = UV Index + windDir = Wind Direction + windGust = Gust Speed + windGustDir = Gust Direction + windSpeed = Wind Speed + windchill = Wind Chill + windgustvec = Gust Vector + windvec = Wind Vector + extraTemp1 = Temperature1 + extraTemp2 = Temperature2 + extraTemp3 = Temperature3 + + # Sensor status indicators + + rxCheckPercent = Signal Quality + txBatteryStatus = Transmitter + windBatteryStatus = Wind + rainBatteryStatus = Rain + outTempBatteryStatus = Outside Temperature + inTempBatteryStatus = Inside Temperature + consBatteryVoltage = Console + heatingVoltage = Heating + supplyVoltage = Supply + referenceVoltage = Reference + + [[Almanac]] + # The labels to be used for the phases of the moon: + moon_phases = New, Waxing crescent, First quarter, Waxing gibbous, Full, Waning gibbous, Last quarter, Waning crescent + +############################################################################## + [Engine] #