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 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:]))