mirror of
https://github.com/google/glazier.git
synced 2025-12-19 10:17:26 -05:00
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
# Copyright 2016 Google Inc. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""Timezone processing for Windows.
|
|
|
|
> Resource Requirements
|
|
|
|
* resources/cldr/common/supplemental/windowsZones.xml
|
|
The Windows timezone map from http://cldr.unicode.org.
|
|
|
|
"""
|
|
import logging
|
|
from xml.dom.minidom import parse
|
|
from glazier.lib import resources
|
|
import gflags as flags
|
|
|
|
FLAGS = flags.FLAGS
|
|
|
|
RESOURCE_PATH = 'cldr/common/supplemental/windowsZones.xml'
|
|
|
|
flags.DEFINE_string('windows_zones_resource', RESOURCE_PATH,
|
|
'Timezone map file location.')
|
|
|
|
|
|
class TimezoneError(Exception):
|
|
pass
|
|
|
|
|
|
class Timezone(object):
|
|
"""Timezone processing for Windows."""
|
|
|
|
def __init__(self, load_map=False):
|
|
self.zones = {}
|
|
if load_map:
|
|
self.LoadMap()
|
|
|
|
def LoadMap(self):
|
|
res = resources.Resources()
|
|
try:
|
|
win_zones = parse(res.GetResourceFileName(FLAGS.windows_zones_resource))
|
|
except resources.FileNotFound:
|
|
raise TimezoneError('Cannot load zone map from %s.' %
|
|
FLAGS.windows_zones_resource)
|
|
for zone in win_zones.getElementsByTagName('mapZone'):
|
|
self.zones[zone.getAttribute('type')] = zone.getAttribute('other')
|
|
|
|
def TranslateZone(self, name):
|
|
found = None
|
|
try:
|
|
found = self.zones[name]
|
|
except KeyError:
|
|
logging.error('Unable to translate zone %s.', name)
|
|
return found
|