comparison python/utils.py @ 266:aba9711b3149

small modificatons and reorganization
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 27 Jul 2012 10:29:24 -0400
parents a048066bd20f
children 78922b4de3bf
comparison
equal deleted inserted replaced
265:7a3bf04cf016 266:aba9711b3149
298 else: 298 else:
299 return filename 299 return filename
300 300
301 def cleanFilename(s): 301 def cleanFilename(s):
302 'cleans filenames obtained when contatenating figure characteristics' 302 'cleans filenames obtained when contatenating figure characteristics'
303 return s.replace(' ','-').replace('.','') 303 return s.replace(' ','-').replace('.','').replace('/','-')
304 304
305 def listfiles(dirname, extension, remove = False): 305 def listfiles(dirname, extension, remove = False):
306 '''Returns the list of files with the extension in the directory dirname 306 '''Returns the list of files with the extension in the directory dirname
307 If remove is True, the filenames are stripped from the extension''' 307 If remove is True, the filenames are stripped from the extension'''
308 from os import listdir 308 from os import listdir
311 if remove: 311 if remove:
312 return [removeExtension(f, extension) for f in tmp] 312 return [removeExtension(f, extension) for f in tmp]
313 else: 313 else:
314 return tmp 314 return tmp
315 315
316 def mkdir(dirname):
317 'Creates a directory if it does not exist'
318 import os
319 if not os.path.exists(dirname):
320 os.mkdir(dirname)
321 else:
322 print(dirname+' already exists')
323
316 def removeFile(filename): 324 def removeFile(filename):
317 '''Deletes the file while avoiding raising an error 325 '''Deletes the file while avoiding raising an error
318 if the file does not exist''' 326 if the file does not exist'''
327 import os
319 if (os.path.exists(filename)): 328 if (os.path.exists(filename)):
320 os.remove(filename) 329 os.remove(filename)
330 else:
331 print(filename+' does not exist')
321 332
322 def plotPolygon(poly, options = ''): 333 def plotPolygon(poly, options = ''):
323 from numpy.core.multiarray import array 334 from numpy.core.multiarray import array
324 from matplotlib.pyplot import plot 335 from matplotlib.pyplot import plot
325 from shapely.geometry import Polygon 336 from shapely.geometry import Polygon