ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/dtflickr/trunk/dtflickr/update.py
Revision: 13
Committed: 2008-07-25T04:54:05-07:00 (16 years, 10 months ago) by douglas
Content type: text/x-python
File size: 2527 byte(s)
Log Message:
OIC, merge fail long ago, grr!

File Contents

# Content
1 #!/usr/bin/env python
2 # Flickr API Update
3 #
4 # Douglas Thrift
5 #
6 # $Id$
7
8 # Copyright 2008 Douglas Thrift
9 #
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 # http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21
22 from __future__ import with_statement
23 from __init__ import Flickr
24 import optparse
25 import os.path
26
27 if __name__ == '__main__':
28 parser = optparse.OptionParser()
29
30 parser.add_option('-a', '--api-key', action = 'store', dest = 'api_key', help = 'Flickr API key')
31
32 options = parser.parse_args()[0]
33
34 if options.api_key is None:
35 parser.error('-a or --api-key not specified')
36
37 flickr = Flickr(options.api_key)
38 namespaces = {}
39
40 for method in flickr.reflection.getMethods().methods.method:
41 info = flickr.reflection.getMethodInfo(method_name = method)
42 namespace, method = str(method).split('.', 1)
43
44 assert namespace == 'flickr'
45
46 namespace, method = method.rsplit('.', 1)
47 documentation = str(info.method.name).strip() + '\n\n ' + str(info.method.description).strip()
48
49 if len(info.arguments.argument) != 1:
50 documentation += '\n\n Arguments:'
51
52 for argument in info.arguments.argument:
53 if argument.name != 'api_key':
54 documentation += '\n\n ' + argument.name + ' ('
55
56 if int(argument.optional) == 0:
57 documentation += 'Required'
58 else:
59 documentation += 'Optional'
60
61 documentation += ')\n ' + str(argument)
62
63 try:
64 namespaces[namespace].append((method, documentation))
65 except KeyError:
66 namespaces[namespace] = [(method, documentation)]
67
68 namespaces = namespaces.items()
69
70 namespaces.sort()
71
72 with open(os.path.join(os.path.dirname(__file__), '_methods.py'), 'wb') as python:
73 python.write('# Flickr API Methods\n#\n# Douglas Thrift\n#\n# $' + 'Id$\n\nnamespaces = (\n')
74
75 for namespace, methods in namespaces:
76 python.write('\t(\'' + namespace + '\', (\n')
77
78 for method, documentation in methods:
79 python.write('\t\t(\'' + method + '\', ' + repr(documentation) + '),\n')
80
81 python.write('\t)),\n')
82
83 python.write(')\n\ndef namespace(namespace):\n\treturn namespace.title().replace(\'.\', \'\')\n')

Properties

Name Value
svn:executable *
svn:keywords Id