blob: c0b84ba4c61e57b775890657b3d4f104217cbe9f [file] [log] [blame]
Joe Gregorio6d5e94f2010-08-25 23:49:30 -04001# Copyright (C) 2010 Google Inc.
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
15"""Generate a skeleton discovery extras document.
16
17For the given API, retrieve the discovery document,
18strip out the guts of each method description
19and put :
20"""
21
22__author__ = 'jcgregorio@google.com (Joe Gregorio)'
23
24import os
25import os.path
Joe Gregorio6d5e94f2010-08-25 23:49:30 -040026import sys
27
Joe Gregorioe6efd532010-09-20 11:13:50 -040028try:
29 import simplejson
30except ImportError:
31 try:
32 # Try to import from django, should work on App Engine
33 from django.utils import simplejson
34 except ImportError:
35 # Should work for Python2.6 and higher.
36 import json as simplejson
37
38
Joe Gregorio6d5e94f2010-08-25 23:49:30 -040039def main():
40 for filename in sys.argv[1:]:
41 f = file(filename, "r")
42 dis = simplejson.load(f)
43 f.close()
44
45 data = dis['data']
46 api = data[data.keys()[0]]
47 version = api[api.keys()[0]]
48 resources = version['resources']
49 for res_name, res_desc in resources.iteritems():
50 methods = res_desc['methods']
51 for method_name, method_desc in methods.iteritems():
52 methods[method_name] = {}
53 path, basename = os.path.split(filename)
54 newfilename = os.path.join(path, "skel-" + basename)
55 f = file(newfilename, "w")
56 simplejson.dump(dis, f, sort_keys=True, indent=2 * ' ')
57 f.close()
58
59
60if __name__ == '__main__':
61 main()