blob: b7f81e306d6220734f762851527a06322d77c657 [file] [log] [blame]
Neil Fuller56166d32017-06-12 12:57:10 +01001# 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
Luca Stefani136579e2019-01-04 17:09:55 +010015from __future__ import print_function
16
Neil Fuller56166d32017-06-12 12:57:10 +010017import os
18import sys
19
20"""Shared functions for use in tzdata scripts."""
21
Neil Fuller12f61502018-11-06 07:31:05 +000022def GetIanaTarFile(dir_name, file_type):
Neil Fuller56166d32017-06-12 12:57:10 +010023 matching_files = []
24 for filename in os.listdir(dir_name):
Neil Fuller12f61502018-11-06 07:31:05 +000025 if filename.startswith('tz%s20' % file_type) and filename.endswith('.tar.gz'):
Neil Fuller56166d32017-06-12 12:57:10 +010026 matching_files.append(filename);
27
28 if len(matching_files) == 0:
29 return None
30 elif len(matching_files) == 1:
31 return '%s/%s' % (dir_name, matching_files[0])
32 else:
Luca Stefani136579e2019-01-04 17:09:55 +010033 print('Multiple tz%s files found unexpectedly %s' % (file_type, matching_files))
Neil Fuller56166d32017-06-12 12:57:10 +010034 sys.exit(1)
35