generate_timezone_data.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python
  2. # Copyright 2024 Google LLC
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import tools.timezones
  16. from resources.types.resource_definition import ResourceDefinition
  17. from resources.types.resource_object import ResourceObject
  18. from io import BytesIO
  19. def wafrule(task):
  20. olson_database = task.inputs[0].abspath()
  21. reso = generate_resource_object(olson_database)
  22. reso.dump(task.outputs[0])
  23. def generate_resource_object(olson_database):
  24. zoneinfo_list = tools.timezones.build_zoneinfo_list(olson_database)
  25. dstrule_list = tools.timezones.dstrules_parse(olson_database)
  26. zonelink_list = tools.timezones.zonelink_parse(olson_database)
  27. print("{} {} {}".format(len(zoneinfo_list),
  28. len(dstrule_list),
  29. len(zonelink_list)))
  30. data_file = BytesIO()
  31. tools.timezones.zoneinfo_to_bin(zoneinfo_list, dstrule_list, zonelink_list, data_file)
  32. reso = ResourceObject(
  33. ResourceDefinition('raw', 'TIMEZONE_DATABASE', None),
  34. data_file.getvalue())
  35. return reso