timezone.py 777 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2009 TUBITAK/UEKAE
  5. # Licensed under the GNU General Public License, version 2.
  6. # See the file http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
  7. # Extracts the timezone information from /etc/localtime using
  8. # timezone db from this package.
  9. # Ozan Caglayan <ozan_at_pardus.org.tr> 2009
  10. import os
  11. import sys
  12. import cPickle
  13. from hashlib import sha1
  14. zonedict = "/usr/share/zoneinfo/zoneinfo.dict"
  15. if __name__ == "__main__":
  16. if os.path.exists(zonedict) and os.path.exists("/etc/localtime"):
  17. tzdb = cPickle.Unpickler(open(zonedict, "rb")).load()
  18. tz = tzdb.get(sha1(open("/etc/localtime", "r").read()).hexdigest(), 'Not found')
  19. print "%s" % tz
  20. sys.exit(0)
  21. else:
  22. sys.exit(1)