mirror of
https://github.com/openharmony/third_party_tzdata.git
synced 2026-07-01 04:25:17 -04:00
!45 merge cherry-260521 into master
tzdata实时编译 Created-by: zhangdd-ewan Commit-by: zhangdd-ewan Merged-by: openharmony_ci Description: ### 一、内容说明(相关的Issue) https://gitcode.com/openharmony/third_party_icu/issues/278 ### 二、建议测试周期和提测地址 建议测试完成时间:xxxx.xx.xx 投产上线时间:xxxx.xx.xx 提测地址:CI环境/压测环境 测试账号: ### 三、变更内容 * 3.1 关联PR列表 * 3.2 数据库和部署说明 1. 常规更新 2. 重启unicorn 3. 重启sidekiq 4. 迁移任务:是否有迁移任务,没有写 "无" 5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无" * 3.4 其他技术优化内容(做了什么,变更了什么) - 重构了 xxxx 代码 - xxxx 算法优化 * 3.5 废弃通知(什么字段、方法弃用?) * 3.6 后向不兼容变更(是否有无法向后兼容的变更?) ### 四、研发自测点(自测哪些?冒烟用例全部自测?) 自测测试结论: ### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方) 检查点: | 需求名称 | 是否影响xx公共模块 | 是否需要xx功能 | 需求升级是否依赖其他子产品 | |------|------------|----------|---------------| | xxx | 否 | 需要 | 不需要 | | | | | | 接口测试: 性能测试: 并发测试: 其他: See merge request: openharmony/third_party_tzdata!45
This commit is contained in:
@@ -25,8 +25,8 @@
|
||||
<policyitem type="copyright" name="Copyright 1989, 1991 The Regents of the University of California." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc=""/>
|
||||
<policyitem type="copyright" name="Copyright 1985, 1987, 1988 The Regents of the University of California." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc=""/>
|
||||
<policyitem type="copyright" name="Copyright 1989 The Regents of the University of California." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc=""/>
|
||||
<policyitem type="license" name="BSD-3-Clause" path="date.c" desc="兼容license"/>
|
||||
<policyitem type="license" name="BSD-3-Clause" path="strftime.c" desc="兼容license"/>
|
||||
<policyitem type="license" name="BSD-3-Clause" path="data/iana/date.c" desc="兼容license"/>
|
||||
<policyitem type="license" name="BSD-3-Clause" path="data/iana/strftime.c" desc="兼容license"/>
|
||||
<policyitem type="license" name="BSD-3-Clause" path="LICENSE" desc="兼容license"/>
|
||||
</policy>
|
||||
</policylist>
|
||||
@@ -38,83 +38,85 @@
|
||||
<filteritem type="filepath" name="data/prebuild/posix/tzdata" desc="packaged binary file"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility, license header policies">
|
||||
<filteritem type="filepath" name="date.1" desc="no license header"/>
|
||||
<filteritem type="filepath" name=".*.3" desc="no license header"/>
|
||||
<filteritem type="filepath" name=".*.5" desc="no license header"/>
|
||||
<filteritem type="filepath" name=".*.8" desc="no license header"/>
|
||||
<filteritem type="filepath" name=".*.awk" desc="no license header"/>
|
||||
<filteritem type="filepath" name=".*.tab" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/date.1" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.3" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.5" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.8" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.awk" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.tab" desc="no license header"/>
|
||||
|
||||
<filteritem type="filepath" name="CONTRIBUTING" desc="no license header"/>
|
||||
<filteritem type="filepath" name="SECURITY" desc="no license header"/>
|
||||
<filteritem type="filepath" name="to2050.tzs" desc="no license header"/>
|
||||
<filteritem type="filepath" name="tzdata.zi" desc="no license header"/>
|
||||
<filteritem type="filepath" name="difftime.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="etcetera" desc="no license header"/>
|
||||
<filteritem type="filepath" name="europe" desc="no license header"/>
|
||||
<filteritem type="filepath" name="tzfile.h" desc="no license header"/>
|
||||
<filteritem type="filepath" name="factory" desc="no license header"/>
|
||||
<filteritem type="filepath" name="africa" desc="no license header"/>
|
||||
<filteritem type="filepath" name="tzselect.ksh" desc="no license header"/>
|
||||
<filteritem type="filepath" name="antarctica" desc="no license header"/>
|
||||
<filteritem type="filepath" name="leap-seconds.list" desc="no license header"/>
|
||||
<filteritem type="filepath" name="version" desc="no license header"/>
|
||||
<filteritem type="filepath" name="asctime.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="leapseconds" desc="no license header"/>
|
||||
<filteritem type="filepath" name="workman.sh" desc="no license header"/>
|
||||
<filteritem type="filepath" name="asia" desc="no license header"/>
|
||||
<filteritem type="filepath" name="australasia" desc="no license header"/>
|
||||
<filteritem type="filepath" name="localtime.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="zdump.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="backward" desc="no license header"/>
|
||||
<filteritem type="filepath" name="backzone" desc="no license header"/>
|
||||
<filteritem type="filepath" name="zic.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="calendars" desc="no license header"/>
|
||||
<filteritem type="filepath" name="northamerica" desc="no license header"/>
|
||||
<filteritem type="filepath" name="private.h" desc="no license header"/>
|
||||
<filteritem type="filepath" name="southamerica" desc="no license header"/>
|
||||
<filteritem type="filepath" name="zoneinfo2tdf.pl" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/CONTRIBUTING" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/SECURITY" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/to2050.tzs" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/tzdata.zi" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/difftime.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/etcetera" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/europe" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/tzfile.h" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/factory" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/africa" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/tzselect.ksh" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/antarctica" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/leap-seconds.list" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/version" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/asctime.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/leapseconds" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/workman.sh" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/asia" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/australasia" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/localtime.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/zdump.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/backward" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/backzone" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/zic.c" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/calendars" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/northamerica" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/private.h" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/southamerica" desc="no license header"/>
|
||||
<filteritem type="filepath" name="data/iana/zoneinfo2tdf.pl" desc="no license header"/>
|
||||
|
||||
</filefilter>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
|
||||
<filteritem type="filepath" name="date.1" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name=".*.3" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name=".*.5" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name=".*.8" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name=".*.awk" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name=".*.tab" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/date.1" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.3" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.5" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.8" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.awk" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.tab" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/.*.py" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/.*.gn" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="tool/.*.java" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="tool/compile_tool/.*.sh" desc="Describe the reason for filtering scan results"/>
|
||||
|
||||
<filteritem type="filepath" name="CONTRIBUTING" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="SECURITY" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="to2050.tzs" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="tzdata.zi" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="difftime.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="etcetera" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="europe" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="tzfile.h" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="factory" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="africa" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="tzselect.ksh" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="antarctica" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="leap-seconds.list" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="version" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="asctime.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="leapseconds" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="workman.sh" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="asia" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="australasia" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="localtime.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="zdump.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="backward" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="backzone" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="zic.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="calendars" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="northamerica" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="private.h" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="southamerica" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="zoneinfo2tdf.pl" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/CONTRIBUTING" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/SECURITY" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/to2050.tzs" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/tzdata.zi" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/difftime.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/etcetera" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/europe" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/tzfile.h" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/factory" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/africa" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/tzselect.ksh" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/antarctica" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/leap-seconds.list" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/version" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/asctime.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/leapseconds" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/workman.sh" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/asia" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/australasia" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/localtime.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/zdump.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/backward" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/backzone" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/zic.c" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/calendars" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/northamerica" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/private.h" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/southamerica" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="data/iana/zoneinfo2tdf.pl" desc="Describe the reason for filtering scan results"/>
|
||||
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"Name": "tzdata",
|
||||
"License": "Public Domain",
|
||||
"License File": "LICENSE",
|
||||
"License File": "data/iana/LICENSE",
|
||||
"Version Number": "2025b",
|
||||
"Upstream URL": "https://github.com/eggert/tz",
|
||||
"Description": "The Time Zone Database (often called tz or zoneinfo) contains code and data that represent the history of local time for many representative locations around the globe."
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"licensePath": "LICENSE",
|
||||
"licensePath": "data/iana/LICENSE",
|
||||
"component": {
|
||||
"name": "tzdata",
|
||||
"subsystem": "thirdparty",
|
||||
|
||||
+16
-2
@@ -13,15 +13,29 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
action("gen_tzdata") {
|
||||
script = "../tool/compile_tool/compile.sh"
|
||||
sources = [ "//third_party/tzdata/tool/compile_tool/compile.sh" ]
|
||||
deps = []
|
||||
|
||||
args = [
|
||||
"-o",
|
||||
"$root_build_dir",
|
||||
]
|
||||
|
||||
outputs = [ "$root_build_dir/thirdparty/tzdata/output/tzdata" ]
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("iana_tzdata") {
|
||||
source = "//third_party/tzdata/data/prebuild/posix/tzdata"
|
||||
source = "$root_build_dir/thirdparty/tzdata/output/tzdata"
|
||||
deps = [ ":gen_tzdata" ]
|
||||
module_install_dir = "etc/zoneinfo"
|
||||
part_name = "tzdata"
|
||||
subsystem_name = "thirdparty"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("timezone_list_cfg") {
|
||||
source = "//third_party/tzdata/data/prebuild/posix/timezone_list.cfg"
|
||||
source = "//third_party/tzdata/data/prebuild/normal/timezone_list.cfg"
|
||||
module_install_dir = "etc/zoneinfo"
|
||||
part_name = "tzdata"
|
||||
subsystem_name = "thirdparty"
|
||||
|
||||
Binary file not shown.
-27946
File diff suppressed because it is too large
Load Diff
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
# 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
|
||||
#
|
||||
# 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.
|
||||
set -e
|
||||
script_path=$(cd $(dirname $0);pwd)
|
||||
iana_path="${script_path}/../../data/iana"
|
||||
posix_path="${iana_path}/../prebuild/posix"
|
||||
zic_path="${iana_path}/../prebuild/tool/linux"
|
||||
|
||||
while getopts "o:b" arg;
|
||||
do
|
||||
case "${arg}" in
|
||||
"o")
|
||||
tool_bin_dir=${OPTARG}
|
||||
;;
|
||||
?)
|
||||
echo "unkonw argument"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "tool_bin_dir--@@:"${tool_bin_dir}
|
||||
make -C ${iana_path}
|
||||
mkdir -p ${zic_path}
|
||||
mkdir -p ${posix_path}
|
||||
mv ${iana_path}/zic ${zic_path}
|
||||
|
||||
state_name=('africa' 'antarctica' 'asia' 'australasia' 'europe' 'etcetera' 'northamerica' 'southamerica' 'backward')
|
||||
for name in ${state_name[@]}
|
||||
do
|
||||
${zic_path}/zic -d ${iana_path}/zoneinfo ${iana_path}/$name
|
||||
done
|
||||
|
||||
rm -rf ${posix_path}/*
|
||||
mv ${iana_path}/zoneinfo/* ${posix_path}
|
||||
#mv ${iana_path}/version.txt ${posix_path}
|
||||
output_path=${script_path}/../../../../${tool_bin_dir}/thirdparty/tzdata/output
|
||||
echo ${output_path}
|
||||
mkdir "${script_path}/../../data/prebuild/posix/output"
|
||||
echo 'compile done'
|
||||
python3 ${script_path}/zone_compactor.py "${script_path}/../../data/prebuild/normal/timezone_list.cfg" ${posix_path} "${output_path}" "tzdata2026b"
|
||||
echo 'package done'
|
||||
exit 0
|
||||
@@ -0,0 +1,139 @@
|
||||
# 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
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
usage: python zone_compactor.py <setup file> <data directory> <output directory> <tzdata version>
|
||||
|
||||
Compile a set of tzfile-formatted files into a single file containing an index.
|
||||
|
||||
The compilation is controlled by a setup file, which is provided as a
|
||||
command-line argument. The setup file has the form:
|
||||
|
||||
Link <toName> <fromName>
|
||||
|
||||
<zone filename>
|
||||
|
||||
|
||||
Note that the links must be declared prior to the zone names.
|
||||
A zone name is a filename relative to the source directory such as
|
||||
'GMT', 'Africa/Dakar', or 'America/Argentina/Jujuy'.
|
||||
|
||||
Use the 'zic' command-line tool to convert from flat files
|
||||
(such as 'africa' or 'northamerica') to a directory
|
||||
hierarchy suitable for this tool (containing files such as 'data/Africa/Abidjan').
|
||||
|
||||
@since 2025/02/08
|
||||
"""
|
||||
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
MAXNAME = 40
|
||||
|
||||
|
||||
class ZoneCompactor:
|
||||
|
||||
def __init__(self, setup_file, data_directory, output_directory, version):
|
||||
zone_ids = []
|
||||
seen = set()
|
||||
with open(setup_file, 'r') as reader:
|
||||
for line in reader:
|
||||
s = line.strip()
|
||||
if s and s not in seen:
|
||||
seen.add(s)
|
||||
zone_ids.append(s)
|
||||
|
||||
all_data = bytearray()
|
||||
offset = 0
|
||||
offsets = {}
|
||||
lengths = {}
|
||||
for zone_id in zone_ids:
|
||||
source_file = os.path.join(data_directory, zone_id)
|
||||
length = os.path.getsize(source_file)
|
||||
offsets[zone_id] = offset
|
||||
lengths[zone_id] = length
|
||||
offset += length
|
||||
with open(source_file, 'rb') as f:
|
||||
all_data.extend(f.read())
|
||||
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
output_path = os.path.join(output_directory, "tzdata")
|
||||
with open(output_path, 'wb') as f:
|
||||
f.write(self._to_ascii(bytearray(12), version))
|
||||
|
||||
index_offset_offset = f.tell()
|
||||
f.write(struct.pack('>i', 0))
|
||||
data_offset_offset = f.tell()
|
||||
f.write(struct.pack('>i', 0))
|
||||
final_offset_offset = f.tell()
|
||||
f.write(struct.pack('>i', 0))
|
||||
|
||||
index_offset = f.tell()
|
||||
sorted_olson_ids = sorted(offsets.keys())
|
||||
for zone_name in sorted_olson_ids:
|
||||
if len(zone_name) >= MAXNAME:
|
||||
raise RuntimeError(f"zone filename too long: {len(zone_name)}")
|
||||
f.write(self._to_ascii(bytearray(MAXNAME), zone_name))
|
||||
offset = offsets.get(zone_name, -1)
|
||||
length = lengths.get(zone_name, -1)
|
||||
if offset != -1 and length != -1:
|
||||
f.write(struct.pack('>i', offset))
|
||||
f.write(struct.pack('>i', length))
|
||||
|
||||
data_offset = f.tell()
|
||||
f.write(all_data)
|
||||
final_offset = f.tell()
|
||||
|
||||
f.seek(index_offset_offset)
|
||||
f.write(struct.pack('>i', index_offset))
|
||||
f.seek(data_offset_offset)
|
||||
f.write(struct.pack('>i', data_offset))
|
||||
f.seek(final_offset_offset)
|
||||
f.write(struct.pack('>i', final_offset))
|
||||
|
||||
@staticmethod
|
||||
def _to_ascii(dst, src):
|
||||
for i, character in enumerate(src):
|
||||
if ord(character) > ord('~'):
|
||||
raise RuntimeError(f"non-ASCII string: {src}")
|
||||
dst[i] = ord(character)
|
||||
return dst
|
||||
|
||||
|
||||
def deep(f, stack, last, result_list):
|
||||
if os.path.isdir(f):
|
||||
stack.append(os.path.basename(f))
|
||||
files = os.listdir(f)
|
||||
for i, file in enumerate(files):
|
||||
deep(os.path.join(f, file), stack, i == len(files) - 1, result_list)
|
||||
else:
|
||||
if not stack:
|
||||
name = os.path.basename(f)
|
||||
if name not in result_list and '.' not in name:
|
||||
result_list.append(name)
|
||||
else:
|
||||
str_path = '/'.join(stack)
|
||||
full_path = str_path + '/' + os.path.basename(f)
|
||||
if full_path not in result_list:
|
||||
result_list.append(full_path)
|
||||
if last:
|
||||
stack.pop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 5:
|
||||
ZoneCompactor(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
|
||||
else:
|
||||
print("input args less then 5!")
|
||||
Reference in New Issue
Block a user