-
Notifications
You must be signed in to change notification settings - Fork 2
/
processArguments.py
executable file
·134 lines (110 loc) · 3.75 KB
/
processArguments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
from bs4 import BeautifulSoup
from processQueryArgument import processQueryArgument
from processBodyArgument import processBodyArgument
import json
import sys
import re
# Constants
DEFAULT = "Default:"
REQUIRED = "required"
# Methods
def processArguments(soup, swggr, path_fields, cursor):
'''
print ' ..... ..... ..... ..... ..... ..... ..... '
print soup.ul.contents
print ' ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ '
sys.exit()
'''
if cursor['path'] in ["/xcards/{card}"] :
debugPrint = True
else :
debugPrint = False
if debugPrint :
print ' ..... ..... ..... ..... ..... ..... ..... '
print path_fields
print 'idBoardStar' in path_fields
print ' ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ '
swagger = swggr['paths'][cursor['path']][cursor['method']]
processed_args = []
for field in path_fields : # process all the fields that form part of the URL
# print "------------ new parameter -- {}".format(field)
name_arg = field.iterkeys().next()
swagger["parameters"].append({
"name" : name_arg
, "required" : True
, "in" : "path"
, "type" : "string"
, "description" : field.itervalues().next()
, "default" : "undefined"
})
processed_args.append(name_arg)
if soup.ul != None :
arguments = soup.ul.contents
idx = -1
modelName = None
action = 'added'
for argument in arguments :
if isinstance(argument, type(soup.li)) :
name_arg = argument.code.span.text
if name_arg not in processed_args :
# idx = idx + 1
# print "#{} -- {}".format(idx, argument)
if cursor['method'] in ["put", "post"] :
# process all the fields that are sent in the body
modelName = processBodyArgument(argument, swggr, cursor)
if cursor['method'] == "put" :
action = 'updated'
else :
# process all the fields that follow the "?" in the URL
processQueryArgument(argument, swggr, cursor)
if modelName :
modelTitle = re.sub(
"([a-z])([A-Z])","\g<1> \g<2>",
modelName
).replace('_', ' ').title()
swagger["parameters"].append({
"name" : "body"
, "required" : True
, "in" : "body"
, "description" : 'Attributes of "' + modelTitle + '" to be ' + action + '.'
, "schema" : { "$ref" : '#/definitions/' + modelName }
})
# add the authorization key field
swagger["parameters"].append({
"name" : "key"
, "required" : True
, "in" : "query"
, "type" : "string"
, "description" : '<a href="https://trello.com/1/appKey/generate" target="_blank">Generate your application key</a>'
, "default" : "undefined"
})
# add the 3rd party token field field
swagger["parameters"].append({
"name" : "token"
, "required" : True
, "in" : "query"
, "type" : "string"
, "description" : '<a href="https://trello.com/docs/gettingstarted/index.html#getting-a-token-from-a-user" target="_blank">Getting a token from a user</a>'
, "default" : "undefined"
})
return
# - - - - - - - - - - -
# Main routine (for testing)
def main():
from test.testdataArguments import test_values
from test.testdataArguments import swagger
from test.testdataArguments import cursor
from test.testdataArguments import pathFields
idx = 0
for frag in test_values :
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
soup = BeautifulSoup(frag)
# if idx == 1 :
if idx != -1 :
processArguments(soup.body.contents[0], swagger, pathFields, cursor)
idx = idx + 1
print(">>~~~~~~~~~~~ ? ~~~~~~~~~~~<<")
print "JSON {}".format(json.dumps(swagger))
print("<<~~~~~~~~~~~~~~~~~~~~~~~~~>>")
if __name__ == "__main__": main()