66# to you under the Apache License, Version 2.0 (the
77# "License"); you may not use this file except in compliance
88# with the License. You may obtain a copy of the License at
9- #
9+ #
1010# http://www.apache.org/licenses/LICENSE-2.0
11- #
11+ #
1212# Unless required by applicable law or agreed to in writing,
1313# software distributed under the License is distributed on an
1414# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131131 'Project' : 'Project' ,
132132 'Lun' : 'Storage' ,
133133 'Pool' : 'Pool' ,
134- 'VPC' : 'VPC' ,
134+ 'VPC' : 'VPC' ,
135135 'PrivateGateway' : 'VPC' ,
136136 'Simulator' : 'simulator' ,
137137 'StaticRoute' : 'VPC' ,
177177
178178
179179def choose_category (fn ):
180- for k , v in known_categories .iteritems ():
180+ for k , v in known_categories .items ():
181181 if k in fn :
182182 return v
183183 raise Exception ('Need to add a category for %s to %s:known_categories' %
@@ -198,7 +198,8 @@ def choose_category(fn):
198198 if dirname .startswith ('./' ):
199199 dirname = dirname [2 :]
200200 try :
201- dom = minidom .parse (file (f ))
201+ with open (f ) as data :
202+ dom = minidom .parse (data )
202203 name = dom .getElementsByTagName ('name' )[0 ].firstChild .data
203204 isAsync = dom .getElementsByTagName ('isAsync' )[0 ].firstChild .data
204205 category = choose_category (fn )
@@ -210,11 +211,11 @@ def choose_category(fn):
210211 'async' : isAsync == 'true' ,
211212 'user' : dirname_to_user [dirname ],
212213 })
213- except ExpatError , e :
214+ except ExpatError as e :
214215 pass
215- except IndexError , e :
216- print fn
217-
216+ except IndexError as e :
217+ print ( fn )
218+
218219
219220def xml_for (command ):
220221 name = command ['name' ]
@@ -227,9 +228,9 @@ def xml_for(command):
227228
228229
229230def write_xml (out , user ):
230- with file (out , 'w' ) as f :
231+ with open (out , 'w' ) as f :
231232 cat_strings = []
232-
233+
233234 for category in categories .keys ():
234235 strings = []
235236 for command in categories [category ]:
@@ -244,24 +245,24 @@ def write_xml(out, user):
244245 i = 0
245246 for _1 , category , all_strings in cat_strings :
246247 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">
249250<h5>%(category)s</h5>
250251<ul>
251252<xsl:for-each select="commands/command">
252253%(all_strings)s
253254</xsl:for-each>
254- </ul>
255+ </ul>
255256</div>
256257
257- ''' % locals ()
258+ ''' % locals ())
258259 if i == 3 :
259- print >> f , '</div>'
260+ f . write ( '</div>\n ' )
260261 i = 0
261262 else :
262263 i += 1
263264 if i != 0 :
264- print >> f , '</div>'
265+ f . write ( '</div>\n ' )
265266
266267
267268def java_for (command , user ):
@@ -277,7 +278,7 @@ def java_for_user(user):
277278 for command in categories [category ]:
278279 if command ['user' ] == user :
279280 strings .append (java_for (command , user ))
280- func = user_to_func [user ]
281+ func = user_to_func [user ]
281282 all_strings = '' .join (strings )
282283 return '''
283284 public void %(func)s() {
@@ -287,8 +288,8 @@ def java_for_user(user):
287288
288289
289290def 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. */
292293
293294import java.util.HashSet;
294295import java.util.Set;
@@ -299,14 +300,15 @@ def write_java(out):
299300 Set<String> domainAdminCommandNames = new HashSet<String>();
300301 Set<String> userCommandNames = new HashSet<String>();
301302
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 " )
306307
307- print >> f , '''
308+ f . write ( '''
308309}
309- '''
310+
311+ ''' )
310312
311313
312314write_xml ('generatetocforuser_include.xsl' , REGULAR_USER )
0 commit comments