6
6
# to you under the Apache License, Version 2.0 (the
7
7
# "License"); you may not use this file except in compliance
8
8
# with the License. You may obtain a copy of the License at
9
- #
9
+ #
10
10
# http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
# Unless required by applicable law or agreed to in writing,
13
13
# software distributed under the License is distributed on an
14
14
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131
131
'Project' : 'Project' ,
132
132
'Lun' : 'Storage' ,
133
133
'Pool' : 'Pool' ,
134
- 'VPC' : 'VPC' ,
134
+ 'VPC' : 'VPC' ,
135
135
'PrivateGateway' : 'VPC' ,
136
136
'Simulator' : 'simulator' ,
137
137
'StaticRoute' : 'VPC' ,
177
177
178
178
179
179
def choose_category (fn ):
180
- for k , v in known_categories .iteritems ():
180
+ for k , v in known_categories .items ():
181
181
if k in fn :
182
182
return v
183
183
raise Exception ('Need to add a category for %s to %s:known_categories' %
@@ -198,7 +198,8 @@ def choose_category(fn):
198
198
if dirname .startswith ('./' ):
199
199
dirname = dirname [2 :]
200
200
try :
201
- dom = minidom .parse (file (f ))
201
+ with open (f ) as data :
202
+ dom = minidom .parse (data )
202
203
name = dom .getElementsByTagName ('name' )[0 ].firstChild .data
203
204
isAsync = dom .getElementsByTagName ('isAsync' )[0 ].firstChild .data
204
205
category = choose_category (fn )
@@ -210,11 +211,11 @@ def choose_category(fn):
210
211
'async' : isAsync == 'true' ,
211
212
'user' : dirname_to_user [dirname ],
212
213
})
213
- except ExpatError , e :
214
+ except ExpatError as e :
214
215
pass
215
- except IndexError , e :
216
- print fn
217
-
216
+ except IndexError as e :
217
+ print ( fn )
218
+
218
219
219
220
def xml_for (command ):
220
221
name = command ['name' ]
@@ -227,9 +228,9 @@ def xml_for(command):
227
228
228
229
229
230
def write_xml (out , user ):
230
- with file (out , 'w' ) as f :
231
+ with open (out , 'w' ) as f :
231
232
cat_strings = []
232
-
233
+
233
234
for category in categories .keys ():
234
235
strings = []
235
236
for command in categories [category ]:
@@ -244,24 +245,24 @@ def write_xml(out, user):
244
245
i = 0
245
246
for _1 , category , all_strings in cat_strings :
246
247
if i == 0 :
247
- print >> f , '<div class="apismallsections">'
248
- print >> f , '''<div class="apismallbullet_box">
248
+ f . write ( '<div class="apismallsections">\n ' )
249
+ f . write ( '''<div class="apismallbullet_box">
249
250
<h5>%(category)s</h5>
250
251
<ul>
251
252
<xsl:for-each select="commands/command">
252
253
%(all_strings)s
253
254
</xsl:for-each>
254
- </ul>
255
+ </ul>
255
256
</div>
256
257
257
- ''' % locals ()
258
+ ''' % locals ())
258
259
if i == 3 :
259
- print >> f , '</div>'
260
+ f . write ( '</div>\n ' )
260
261
i = 0
261
262
else :
262
263
i += 1
263
264
if i != 0 :
264
- print >> f , '</div>'
265
+ f . write ( '</div>\n ' )
265
266
266
267
267
268
def java_for (command , user ):
@@ -277,7 +278,7 @@ def java_for_user(user):
277
278
for command in categories [category ]:
278
279
if command ['user' ] == user :
279
280
strings .append (java_for (command , user ))
280
- func = user_to_func [user ]
281
+ func = user_to_func [user ]
281
282
all_strings = '' .join (strings )
282
283
return '''
283
284
public void %(func)s() {
@@ -287,8 +288,8 @@ def java_for_user(user):
287
288
288
289
289
290
def write_java (out ):
290
- with file (out , 'w' ) as f :
291
- print >> f , '''/* Generated using gen_toc.py. Do not edit. */
291
+ with open (out , 'w' ) as f :
292
+ f . write ( '''/* Generated using gen_toc.py. Do not edit. */
292
293
293
294
import java.util.HashSet;
294
295
import java.util.Set;
@@ -299,14 +300,15 @@ def write_java(out):
299
300
Set<String> domainAdminCommandNames = new HashSet<String>();
300
301
Set<String> userCommandNames = new HashSet<String>();
301
302
302
- '''
303
- print >> f , java_for_user (REGULAR_USER )
304
- print >> f , java_for_user (ROOT_ADMIN )
305
- print >> f , java_for_user (DOMAIN_ADMIN )
303
+ ''' )
304
+ f . write ( java_for_user (REGULAR_USER ) + " \n " );
305
+ f . write ( java_for_user (ROOT_ADMIN ) + " \n " )
306
+ f . write ( java_for_user (DOMAIN_ADMIN ) + " \n " )
306
307
307
- print >> f , '''
308
+ f . write ( '''
308
309
}
309
- '''
310
+
311
+ ''' )
310
312
311
313
312
314
write_xml ('generatetocforuser_include.xsl' , REGULAR_USER )
0 commit comments