Change add zoneinfo_priority param to gettz().

Change patch zoneinfo file location to SickGear zoneinfo_dir.
This commit is contained in:
Prinz23 2017-08-02 14:08:44 +01:00 committed by JackDandy
parent ad3f8c9584
commit 7d068d496b
3 changed files with 46 additions and 35 deletions

View file

@ -1,6 +1,7 @@
Libs with customisations...
/lib/dateutil/zoneinfo/__init__.py
/lib/dateutil/tz/tz.py
/lib/hachoir_core/config.py
/lib/hachoir_core/stream/input_helpers.py
/lib/hachoir_metadata/jpeg.py

View file

@ -1347,7 +1347,7 @@ else:
TZPATHS = []
def gettz(name=None):
def gettz(name=None, zoneinfo_priority=False):
tz = None
if not name:
try:
@ -1381,43 +1381,47 @@ def gettz(name=None):
else:
tz = None
else:
for path in TZPATHS:
filepath = os.path.join(path, name)
if not os.path.isfile(filepath):
filepath = filepath.replace(' ', '_')
if zoneinfo_priority:
from dateutil.zoneinfo import get_zonefile_instance
tz = get_zonefile_instance().get(name)
if not tz:
for path in TZPATHS:
filepath = os.path.join(path, name)
if not os.path.isfile(filepath):
continue
try:
tz = tzfile(filepath)
break
except (IOError, OSError, ValueError):
pass
else:
tz = None
if tzwin is not None:
filepath = filepath.replace(' ', '_')
if not os.path.isfile(filepath):
continue
try:
tz = tzwin(name)
except WindowsError:
tz = None
tz = tzfile(filepath)
break
except (IOError, OSError, ValueError):
pass
else:
tz = None
if tzwin is not None:
try:
tz = tzwin(name)
except WindowsError:
tz = None
if not tz:
from dateutil.zoneinfo import get_zonefile_instance
tz = get_zonefile_instance().get(name)
if not zoneinfo_priority and not tz:
from dateutil.zoneinfo import get_zonefile_instance
tz = get_zonefile_instance().get(name)
if not tz:
for c in name:
# name must have at least one offset to be a tzstr
if c in "0123456789":
try:
tz = tzstr(name)
except ValueError:
pass
break
else:
if name in ("GMT", "UTC"):
tz = tzutc()
elif name in time.tzname:
tz = tzlocal()
if not tz:
for c in name:
# name must have at least one offset to be a tzstr
if c in "0123456789":
try:
tz = tzstr(name)
except ValueError:
pass
break
else:
if name in ("GMT", "UTC"):
tz = tzutc()
elif name in time.tzname:
tz = tzlocal()
return tz

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import warnings
import json
import os
from tarfile import TarFile
from pkgutil import get_data
@ -9,6 +10,9 @@ from contextlib import closing
from dateutil.tz import tzfile
from sickbeard import encodingKludge as ek
import sickbeard
__all__ = ["get_zonefile_instance", "gettz", "gettz_db_metadata", "rebuild"]
ZONEFILENAME = "dateutil-zoneinfo.tar.gz"
@ -22,7 +26,9 @@ class tzfile(tzfile):
def getzoneinfofile_stream():
try:
return BytesIO(get_data(__name__, ZONEFILENAME))
# return BytesIO(get_data(__name__, ZONEFILENAME))
with open(ek.ek(os.path.join, sickbeard.ZONEINFO_DIR, ZONEFILENAME), 'rb') as f:
return BytesIO(f.read())
except IOError as e: # TODO switch to FileNotFoundError?
warnings.warn("I/O error({0}): {1}".format(e.errno, e.strerror))
return None