Skip to content

Commit

Permalink
[Timezones.py] Multiple fixes (#1570)
Browse files Browse the repository at this point in the history
- Fix initialisation in "Classic" mode.
- Fix "posix" and "right" zoneinfo files not being properly suppressed.
- Fix the value of the "TZ" shell variable.
- Fix logging messages referring to "Directories".
  • Loading branch information
IanSav committed Mar 18, 2020
1 parent cb3dac2 commit 6c741a2
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions lib/python/Components/Timezones.py
Expand Up @@ -76,22 +76,27 @@ def InitTimeZones():
config.timezone.area.value = "Generic"
try:
tzLink = path.realpath("/etc/localtime")[20:]
tzSplit = tzLink.find("/")
if tzSplit == -1:
tzArea = "Generic"
tzVal = tzLink
else:
tzArea = tzLink[:tzSplit]
tzVal = tzLink[tzSplit + 1:]
msgs = []
if config.timezone.area.value != tzArea:
msgs.append("area '%s' != '%s'" % (tzArea, config.timezone.area.value))
# config.timezone.area.value = tzArea
if config.timezone.val.value != tzVal:
msgs.append("zone '%s' != '%s'" % (tzVal, config.timezone.val.value))
# config.timezone.val.value = tzVal
if config.timezone.area.value == "Classic":
if config.timezone.val.value != tzLink:
msgs.append("time zone '%s' != '%s'" % (tzLink, config.timezone.val.value))
config.timezone.val.value = tzLink
else:
tzSplit = tzLink.find("/")
if tzSplit == -1:
tzArea = "Generic"
tzVal = tzLink
else:
tzArea = tzLink[:tzSplit]
tzVal = tzLink[tzSplit + 1:]
if config.timezone.area.value != tzArea:
msgs.append("area '%s' != '%s'" % (tzArea, config.timezone.area.value))
config.timezone.area.value = tzArea
if config.timezone.val.value != tzVal:
msgs.append("zone '%s' != '%s'" % (tzVal, config.timezone.val.value))
config.timezone.val.value = tzVal
if len(msgs):
print "[Timezones] Warning: System timezone does not match Enigma2 timezone (%s)!" % ",".join(msgs)
print "[Timezones] Warning: System timezone does not match Enigma2 timezone (%s), setting Enigma2 to system timezone!" % ",".join(msgs)
except (IOError, OSError):
pass

Expand Down Expand Up @@ -146,7 +151,7 @@ def loadTimezones(self):
}
for (root, dirs, files) in walk(TIMEZONE_DATA):
base = root[len(TIMEZONE_DATA):]
if base in ("posix", "right"): # Skip these alternate copies of the timezone data if they exist.
if base.startswith("posix") or base.startswith("right"): # Skip these alternate copies of the timezone data if they exist.
continue
if base == "":
base = "Generic"
Expand Down Expand Up @@ -274,18 +279,18 @@ def activateTimezone(self, zone, area, runCallbacks=True):
tz = "UTC"
file = path.join(TIMEZONE_DATA, tz)
print "[Timezones] Setting timezone to '%s'." % tz
environ["TZ"] = tz
try:
unlink("/etc/localtime")
except (IOError, OSError) as err:
if err.errno != errno.ENOENT: # No such file or directory
print "[Directories] Error %d: Unlinking '/etc/localtime'! (%s)" % (err.errno, err.strerror)
print "[Timezones] Error %d: Unlinking '/etc/localtime'! (%s)" % (err.errno, err.strerror)
pass
try:
symlink(file, "/etc/localtime")
except (IOError, OSError) as err:
print "[Directories] Error %d: Linking '%s' to '/etc/localtime'! (%s)" % (err.errno, file, err.strerror)
print "[Timezones] Error %d: Linking '%s' to '/etc/localtime'! (%s)" % (err.errno, file, err.strerror)
pass
environ["TZ"] = ":%s" % tz
try:
time.tzset()
except Exception:
Expand Down

0 comments on commit 6c741a2

Please sign in to comment.