blob: e47e066327d97ed7701c839deee7011ee5253623 [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
15import os
16import sys
17
18"""Shared functions for use in tzdata scripts."""
19
Neil Fullerad3a1e62018-05-14 16:36:40 +010020def GetIanaTarFile(dir_name, file_prefix):
Neil Fuller56166d32017-06-12 12:57:10 +010021 matching_files = []
22 for filename in os.listdir(dir_name):
Neil Fullerad3a1e62018-05-14 16:36:40 +010023 if filename.startswith(file_prefix) and filename.endswith('.tar.gz'):
Neil Fuller56166d32017-06-12 12:57:10 +010024 matching_files.append(filename);
25
26 if len(matching_files) == 0:
27 return None
28 elif len(matching_files) == 1:
29 return '%s/%s' % (dir_name, matching_files[0])
30 else:
Neil Fullerad3a1e62018-05-14 16:36:40 +010031 print 'Multiple %s files found unexpectedly %s' % (file_prefix, matching_files)
Neil Fuller56166d32017-06-12 12:57:10 +010032 sys.exit(1)
33