Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 1 | # 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 | |
| 17 | For the given API, retrieve the discovery document, |
| 18 | strip out the guts of each method description |
| 19 | and put : |
| 20 | """ |
| 21 | |
| 22 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 23 | |
| 24 | import os |
| 25 | import os.path |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 26 | import sys |
| 27 | |
Joe Gregorio | b843fa2 | 2010-12-13 16:26:07 -0500 | [diff] [blame] | 28 | from anyjson import simplejson |
Joe Gregorio | e6efd53 | 2010-09-20 11:13:50 -0400 | [diff] [blame] | 29 | |
| 30 | |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 31 | def main(): |
| 32 | for filename in sys.argv[1:]: |
| 33 | f = file(filename, "r") |
| 34 | dis = simplejson.load(f) |
| 35 | f.close() |
| 36 | |
Joe Gregorio | 3b3a191 | 2010-11-04 19:37:05 -0400 | [diff] [blame] | 37 | api = dis['name'] |
| 38 | version = dis['version'] |
| 39 | resources = dis['resources'] |
Joe Gregorio | 6d5e94f | 2010-08-25 23:49:30 -0400 | [diff] [blame] | 40 | for res_name, res_desc in resources.iteritems(): |
| 41 | methods = res_desc['methods'] |
| 42 | for method_name, method_desc in methods.iteritems(): |
| 43 | methods[method_name] = {} |
| 44 | path, basename = os.path.split(filename) |
| 45 | newfilename = os.path.join(path, "skel-" + basename) |
| 46 | f = file(newfilename, "w") |
| 47 | simplejson.dump(dis, f, sort_keys=True, indent=2 * ' ') |
| 48 | f.close() |
| 49 | |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | main() |