Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating from a directory of cached discovery data. #651

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tools/ServiceGenerator/SGMain.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions Tools/preferred_paths_from_cache.py
Original file line number Diff line number Diff line change
@@ -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:]))