Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: third_party/recipe_engine/third_party/dateutil/zoneinfo/__init__.py

Issue 1241323004: Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Moved show_me_the_modules into recipe_engine Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/recipe_engine/third_party/dateutil/zoneinfo/__init__.py
diff --git a/third_party/recipe_engine/third_party/dateutil/zoneinfo/__init__.py b/third_party/recipe_engine/third_party/dateutil/zoneinfo/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..9bed6264c8b97230e787e31d56a2b7318d9f63f9
--- /dev/null
+++ b/third_party/recipe_engine/third_party/dateutil/zoneinfo/__init__.py
@@ -0,0 +1,87 @@
+"""
+Copyright (c) 2003-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
+
+This module offers extensions to the standard python 2.3+
+datetime module.
+"""
+from 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)

Powered by Google App Engine
This is Rietveld 408576698