From e7e699b4a6f0f4fcb6dd913e4580cfd16a546657 Mon Sep 17 00:00:00 2001 From: zhangdd-ewan Date: Thu, 21 May 2026 18:20:47 +0800 Subject: [PATCH] =?UTF-8?q?tzdata=E5=AE=9E=E6=97=B6=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd-ewan --- tool/compile_tool/compile.sh | 2 +- tool/compile_tool/zone_compactor.py | 2 +- tool/update_tool/download_iana.py | 119 ---------------------------- 3 files changed, 2 insertions(+), 121 deletions(-) delete mode 100644 tool/update_tool/download_iana.py diff --git a/tool/compile_tool/compile.sh b/tool/compile_tool/compile.sh index a02633d..5754d5c 100755 --- a/tool/compile_tool/compile.sh +++ b/tool/compile_tool/compile.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2026 Huawei Device Co., Ltd. # 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 diff --git a/tool/compile_tool/zone_compactor.py b/tool/compile_tool/zone_compactor.py index c7c39ce..a7cd71f 100644 --- a/tool/compile_tool/zone_compactor.py +++ b/tool/compile_tool/zone_compactor.py @@ -1,4 +1,4 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. +# Copyright (c) 2026 Huawei Device Co., Ltd. # 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 diff --git a/tool/update_tool/download_iana.py b/tool/update_tool/download_iana.py deleted file mode 100644 index d74cfd2..0000000 --- a/tool/update_tool/download_iana.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# -# Copyright (c) 2022 Huawei Device Co., Ltd. -# 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. -# - -import time -import urllib.request as request -import urllib.error as error -import ssl -import tarfile -import sys -import os -import stat - - -def find_current_version(path): - flags = os.O_RDONLY - modes = stat.S_IWUSR | stat.S_IRUSR - with os.fdopen(os.open(path, flags, modes), 'r') as file: - version = file.readline().strip() - return version - - -def try_download(file_type, try_version, save_path, version): - if try_version == version: - print('current version is already the lastest version.') - return 0 - parent_url = "https://data.iana.org/time-zones/releases/" - context = ssl.SSLContext() - try: - file_name = file_type + try_version + '.tar.gz' - data = request.urlopen(parent_url + file_name, context=context) - except error.HTTPError as http_error: - return -1 - print('start to download ' + file_name) - content = data.read() - data.close() - flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL - modes = stat.S_IWUSR | stat.S_IRUSR - with os.fdopen(os.open(save_path + file_name, flags, modes), 'wb+') as file: - file.write(content) - print('download finished!') - return 1 - - -def download(file_type, save_path, version): - local_time = time.localtime(time.time()) - year = local_time[0] - version_suffixes = "zyxwvutsrqponmlkjihgfedcba" - version_index = 0 - - print('start to find the lastest version of tzdata and tzcode.') - status = -1 - while status < 0: - status = try_download(file_type, str(year) + - version_suffixes[version_index], save_path, - version) - if status < 0: - if version_index < 25: - version_index += 1 - else: - year -= 1 - version_index = 0 - if status == 0: - return '' - file_name = file_type + str(year) + version_suffixes[version_index] + \ - '.tar.gz' - return file_name - - -def decompress(file_name, save_path): - tar = tarfile.open(save_path + file_name, "r:gz") - tar.extractall(save_path) - tar.close() - print('decompress finished!') - - -def main(): - file_path = os.path.abspath(__file__) - file_dir = os.path.dirname(file_path) - - version_file_path = file_dir + "/../../data/prebuild/posix/version.txt" - version = find_current_version(version_file_path) - - print('current version is ' + version) - - download_path = file_dir + "/../../data/iana/" - if not os.path.exists(download_path): - os.makedirs(download_path) - file_type = "tzdata" - file_name = download(file_type, download_path, version) - - if file_name != '': - decompress(file_name, download_path) - file_type = "tzcode" - new_version = file_name[6:11] - try_download(file_type, new_version, download_path, version) - decompress(file_type + new_version + '.tar.gz', download_path) - flags = os.O_WRONLY | os.O_CREAT - modes = stat.S_IWUSR | stat.S_IRUSR - with os.fdopen(os.open(os.path.join(download_path, 'version.txt'), flags, modes), 'w') as file: - file.write(new_version + '\n') - - -if __name__ == '__main__': - sys.exit(main())