tzdatautil.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright 2017 The Android Open Source Project
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import print_function
  15. import os
  16. import sys
  17. """Shared functions for use in tzdata scripts."""
  18. def GetIanaTarFile(dir_name, file_type):
  19. matching_files = []
  20. for filename in os.listdir(dir_name):
  21. if filename.startswith('tz%s20' % file_type) and filename.endswith('.tar.gz'):
  22. matching_files.append(filename);
  23. if len(matching_files) == 0:
  24. return None
  25. elif len(matching_files) == 1:
  26. return '%s/%s' % (dir_name, matching_files[0])
  27. else:
  28. print('Multiple tz%s files found unexpectedly %s' % (file_type, matching_files))
  29. sys.exit(1)