1#!/usr/bin/python 2# Copyright (C) 2021-2022 Free Software Foundation, Inc. 3# This file is part of the GNU C Library. 4# 5# The GNU C Library is free software; you can redistribute it and/or 6# modify it under the terms of the GNU Lesser General Public 7# License as published by the Free Software Foundation; either 8# version 2.1 of the License, or (at your option) any later version. 9# 10# The GNU C Library is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13# Lesser General Public License for more details. 14# 15# You should have received a copy of the GNU Lesser General Public 16# License along with the GNU C Library; if not, see 17# <https://www.gnu.org/licenses/>. 18 19def get_glibc_shared_code(path): 20 """ Get glibc shared code information from a file 21 22 The input file must have project names in their own line ending with a colon 23 and all shared files in the project on their own lines following the project 24 name. Whitespaces are ignored. Lines with # as the first non-whitespace 25 character are ignored. 26 27 Args: 28 path: The path to file containing shared code information. 29 30 Returns: 31 A dictionary with project names as key and lists of files as values. 32 """ 33 34 projects = {} 35 with open(path, 'r') as f: 36 for line in f.readlines(): 37 line = line.strip() 38 if len(line) == 0 or line[0] == '#': 39 continue 40 if line[-1] == ':': 41 cur = line[:-1] 42 projects[cur] = [] 43 else: 44 projects[cur].append(line) 45 46 return projects 47 48# Function testing. 49import sys 50from os import EX_NOINPUT 51from os.path import exists 52from pprint import * 53 54if __name__ == '__main__': 55 if len(sys.argv) != 2: 56 print('Usage: %s <file name>' % sys.argv[0]) 57 print('Run this script from the base glibc source directory') 58 sys.exit(EX_NOINPUT) 59 60 print('Testing get_glibc_shared_code with %s:\n' % sys.argv[1]) 61 r = get_glibc_shared_code(sys.argv[1]) 62 errors = False 63 for k in r.keys(): 64 for f in r[k]: 65 if not exists(f): 66 print('%s does not exist' % f) 67 errors = True 68 69 if not errors: 70 pprint(r) 71