mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
0d9fbc1ad7
This version of SickBeard uses both TVDB and TVRage to search and gather it's series data from allowing you to now have access to and download shows that you couldn't before because of being locked into only what TheTVDB had to offer. Also this edition is based off the code we used in our XEM editon so it does come with scene numbering support as well as all the other features our XEM edition has to offer. Please before using this with your existing database (sickbeard.db) please make a backup copy of it and delete any other database files such as cache.db and failed.db if present, we HIGHLY recommend starting out with no database files at all to make this a fresh start but the choice is at your own risk! Enjoy!
87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
"""
|
|
Copyright (c) 2003-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
|
|
|
|
This module offers extensions to the standard python 2.3+
|
|
datetime module.
|
|
"""
|
|
from lib.dateutil.tz import tzfile
|
|
from tarfile import TarFile
|
|
import os
|
|
|
|
__author__ = "Gustavo Niemeyer <gustavo@niemeyer.net>"
|
|
__license__ = "PSF License"
|
|
|
|
__all__ = ["setcachesize", "gettz", "rebuild"]
|
|
|
|
CACHE = []
|
|
CACHESIZE = 10
|
|
|
|
class tzfile(tzfile):
|
|
def __reduce__(self):
|
|
return (gettz, (self._filename,))
|
|
|
|
def getzoneinfofile():
|
|
filenames = os.listdir(os.path.join(os.path.dirname(__file__)))
|
|
filenames.sort()
|
|
filenames.reverse()
|
|
for entry in filenames:
|
|
if entry.startswith("zoneinfo") and ".tar." in entry:
|
|
return os.path.join(os.path.dirname(__file__), entry)
|
|
return None
|
|
|
|
ZONEINFOFILE = getzoneinfofile()
|
|
|
|
del getzoneinfofile
|
|
|
|
def setcachesize(size):
|
|
global CACHESIZE, CACHE
|
|
CACHESIZE = size
|
|
del CACHE[size:]
|
|
|
|
def gettz(name):
|
|
tzinfo = None
|
|
if ZONEINFOFILE:
|
|
for cachedname, tzinfo in CACHE:
|
|
if cachedname == name:
|
|
break
|
|
else:
|
|
tf = TarFile.open(ZONEINFOFILE)
|
|
try:
|
|
zonefile = tf.extractfile(name)
|
|
except KeyError:
|
|
tzinfo = None
|
|
else:
|
|
tzinfo = tzfile(zonefile)
|
|
tf.close()
|
|
CACHE.insert(0, (name, tzinfo))
|
|
del CACHE[CACHESIZE:]
|
|
return tzinfo
|
|
|
|
def rebuild(filename, tag=None, format="gz"):
|
|
import tempfile, shutil
|
|
tmpdir = tempfile.mkdtemp()
|
|
zonedir = os.path.join(tmpdir, "zoneinfo")
|
|
moduledir = os.path.dirname(__file__)
|
|
if tag: tag = "-"+tag
|
|
targetname = "zoneinfo%s.tar.%s" % (tag, format)
|
|
try:
|
|
tf = TarFile.open(filename)
|
|
for name in tf.getnames():
|
|
if not (name.endswith(".sh") or
|
|
name.endswith(".tab") or
|
|
name == "leapseconds"):
|
|
tf.extract(name, tmpdir)
|
|
filepath = os.path.join(tmpdir, name)
|
|
os.system("zic -d %s %s" % (zonedir, filepath))
|
|
tf.close()
|
|
target = os.path.join(moduledir, targetname)
|
|
for entry in os.listdir(moduledir):
|
|
if entry.startswith("zoneinfo") and ".tar." in entry:
|
|
os.unlink(os.path.join(moduledir, entry))
|
|
tf = TarFile.open(target, "w:%s" % format)
|
|
for entry in os.listdir(zonedir):
|
|
entrypath = os.path.join(zonedir, entry)
|
|
tf.add(entrypath, entry)
|
|
tf.close()
|
|
finally:
|
|
shutil.rmtree(tmpdir)
|