From 1b0c0fffb1b6267c2ad00c6c45a2a1d2af013aac Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 18 Jul 2024 14:41:57 -0400 Subject: [PATCH 1/2] Use ServiceGenerator logging conventions some as other tools. Some other tooling is using NAME.VERSION.json for the file names, so follow that style. They also use "index.json" for the directory listing, so use that also. --- Tools/ServiceGenerator/SGMain.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/ServiceGenerator/SGMain.m b/Tools/ServiceGenerator/SGMain.m index c3c24c850..64cb2e815 100644 --- a/Tools/ServiceGenerator/SGMain.m +++ b/Tools/ServiceGenerator/SGMain.m @@ -435,7 +435,7 @@ - (void)printUsage:(FILE *)outputFile brief:(BOOL)brief { - (void)maybeLogAPI:(GTLRDiscovery_RestDescription *)api { if (self.apiLogDir == nil) return; - NSString *fileName = [NSString stringWithFormat:@"%@_%@.json", + NSString *fileName = [NSString stringWithFormat:@"%@.%@.json", api.name, api.version]; NSString *filePath = [self.apiLogDir stringByAppendingPathComponent:fileName]; NSError *writeErr = nil; @@ -1186,7 +1186,7 @@ - (void)stateDirectory { } else { GTLRDiscovery_DirectoryList *apiList = (GTLRDiscovery_DirectoryList *)object; if (self.apiLogDir != nil) { - NSString *filePath = [self.apiLogDir stringByAppendingPathComponent:@"DirectoryList.json"]; + NSString *filePath = [self.apiLogDir stringByAppendingPathComponent:@"index.json"]; NSError *writeErr = nil; if (![apiList.JSONString writeToFile:filePath atomically:YES From 5718c6bc16e3b3c3abdf35df379ba8802d3ab902 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 18 Jul 2024 15:28:05 -0400 Subject: [PATCH 2/2] Simple util for extracting file paths from a cache dir. --- Tools/preferred_paths_from_cache.py | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 Tools/preferred_paths_from_cache.py diff --git a/Tools/preferred_paths_from_cache.py b/Tools/preferred_paths_from_cache.py new file mode 100755 index 000000000..54412cdec --- /dev/null +++ b/Tools/preferred_paths_from_cache.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +# +# Copyright 2024 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +"""Helper to act on a directory of cached discovery data.""" + +import argparse +import json +import os +import sys + +def Main(args): + """Main method.""" + parser = argparse.ArgumentParser() + parser.add_argument('--index-name', default="index.json") + parser.add_argument('--skip', default=[], action='append') + parser.add_argument('cache_dir') + opts = parser.parse_args(args) + + index_path = os.path.join(opts.cache_dir, opts.index_name) + with open(index_path, 'r') as fp: + services = json.load(fp).get('items') + + file_names = [] + for x in services: + if not x.get("preferred"): + continue + name = x.get('name') + if name in opts.skip: + continue + version = x.get('version') + file_names.append(f'{name}.{version}.json') + + perferred_paths = [ + os.path.join(opts.cache_dir, x) + for x in file_names + ] + print(" ".join(perferred_paths)) + +if __name__ == '__main__': + sys.exit(Main(sys.argv[1:]))