Changeset 1143 for ZMS/trunk/_fileutil.py
- Timestamp:
- 07.09.2010 21:50:47 (21 months ago)
- File:
-
- 1 edited
-
ZMS/trunk/_fileutil.py (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ZMS/trunk/_fileutil.py
r1140 r1143 59 59 60 60 61 # ------------------------------------------------------------------------------ 62 #_fileutil.importZexp:63 # 64 #Import file from specified path.65 # ------------------------------------------------------------------------------ 61 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 62 _fileutil.importZexp: 63 64 Import file from specified path. 65 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 66 66 def importZexp(self, filename): 67 67 filepath = INSTANCE_HOME + '/import/' + filename … … 70 70 71 71 72 # ------------------------------------------------------------------------------ 73 #_fileutil.extractFilename:74 # 75 #Extract filename from path.76 #IN: path77 # ------------------------------------------------------------------------------ 72 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 73 _fileutil.extractFilename: 74 75 Extract filename from path. 76 IN: path 77 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 78 78 def extractFilename(path, sep=None): 79 79 if sep is None: … … 84 84 85 85 86 # ------------------------------------------------------------------------------ 87 #_fileutil.extractFileExt:88 # 89 #Extract fileextension from path.90 #IN: path91 #OUT: extension92 # ------------------------------------------------------------------------------ 86 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 87 _fileutil.extractFileExt: 88 89 Extract fileextension from path. 90 IN: path 91 OUT: extension 92 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 93 93 def extractFileExt(path): 94 94 items = path.split('.') … … 97 97 98 98 99 # ------------------------------------------------------------------------------ 100 #_fileutil.getOSPath:101 # 102 #Return path with OS separators.103 # ------------------------------------------------------------------------------ 99 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 100 _fileutil.getOSPath: 101 102 Return path with OS separators. 103 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 104 104 def getOSPath(path, sep=None, chs=range(32)+[34,60,62,63,127]): 105 105 if sep is None: sep = os.sep … … 115 115 116 116 117 # ------------------------------------------------------------------------------ 118 #_fileutil.getFilePath:119 # 120 #Extract filepath from path (cut-off filename).121 #IN: path122 #OUT: filepath123 # ------------------------------------------------------------------------------ 117 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 118 _fileutil.getFilePath: 119 120 Extract filepath from path (cut-off filename). 121 IN: path 122 OUT: filepath 123 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 124 124 def getFilePath(path): 125 125 items = getOSPath(path).split(os.sep) … … 133 133 134 134 135 # ------------------------------------------------------------------------------ 136 #_fileutil.findExtension:137 # 138 #Searches path and all subdirectories for file with extension and returns139 #complete filepath. Returns None if no file with specified extension exists.140 #IN: extension141 #path142 #OUT: filepath143 # ------------------------------------------------------------------------------ 135 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 136 _fileutil.findExtension: 137 138 Searches path and all subdirectories for file with extension and returns 139 complete filepath. Returns None if no file with specified extension exists. 140 IN: extension 141 path 142 OUT: filepath 143 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 144 144 def findExtension(extension, path, deep=1): 145 145 rtn = None … … 158 158 159 159 160 # ------------------------------------------------------------------------------ 161 #_fileutil.readPath:162 # 163 #Reads path.164 # ------------------------------------------------------------------------------ 160 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 161 _fileutil.readPath: 162 163 Reads path. 164 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 165 165 def readPath(path, data=True, recursive=True): 166 166 l = [] … … 213 213 214 214 215 # ------------------------------------------------------------------------------ 216 #_fileutil.readFile:217 # 218 #Reads file (threshold for filesteam_iterator is 128 kb).219 # ------------------------------------------------------------------------------ 215 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 216 _fileutil.readFile: 217 218 Reads file (threshold for filesteam_iterator is 128 kb). 219 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 220 220 def readFile(filename, mode='b', threshold=2 << 16): 221 221 size = os.path.getsize( filename) … … 237 237 238 238 239 # ------------------------------------------------------------------------------ 240 #_fileutil.importPath:241 # 242 #Imports path.243 # ------------------------------------------------------------------------------ 239 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 240 _fileutil.importPath: 241 242 Imports path. 243 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 244 244 def importPath(self, path): 245 245 path = getOSPath(path) … … 259 259 260 260 261 # ------------------------------------------------------------------------------ 262 #_fileutil.remove:263 # 264 #Removes path (and all its subdirectories if deep==1).265 # ------------------------------------------------------------------------------ 261 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 262 _fileutil.remove: 263 264 Removes path (and all its subdirectories if deep==1). 265 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 266 266 def remove(path, deep=0): 267 267 path = getOSPath(path) … … 281 281 282 282 283 # ------------------------------------------------------------------------------ 284 #_fileutil.getDataSizeStr:285 # 286 #Display string for file-size.287 # ------------------------------------------------------------------------------ 283 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 284 _fileutil.getDataSizeStr: 285 286 Display string for file-size. 287 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 288 288 def getDataSizeStr(len): 289 289 s = '' … … 308 308 309 309 310 # ------------------------------------------------------------------------------ 311 #_fileutil.executeCommand:312 # ------------------------------------------------------------------------------ 310 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 311 _fileutil.executeCommand: 312 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 313 313 def executeCommand(path, command): 314 314 os.chdir(path) 315 315 os.system(command) 316 316 317 318 # ------------------------------------------------------------------------------ 319 #_fileutil.exportObj:320 # ------------------------------------------------------------------------------ 317 318 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 319 _fileutil.exportObj: 320 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 321 321 def exportObj(obj, filename, filetype='b'): 322 322 323 323 #-- Try to create directory-tree. 324 324 filename = getOSPath(filename) … … 358 358 359 359 360 # ------------------------------------------------------------------------------ 361 #_fileutil.mkDir:362 # 363 #Make directory.364 # ------------------------------------------------------------------------------ 360 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 361 _fileutil.mkDir: 362 363 Make directory. 364 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 365 365 def mkDir(path): 366 366 try: … … 370 370 371 371 372 # ------------------------------------------------------------------------------ 373 #_fileutil.readDir374 # ------------------------------------------------------------------------------ 372 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 373 _fileutil.readDir 374 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 375 375 def readDir(path): 376 376 obs = [] … … 399 399 ################################################################################ 400 400 401 # ------------------------------------------------------------------------------ 402 #_fileutil.getZipArchive:403 # 404 #Extract files from zip-archive and return list of extracted files.405 # ------------------------------------------------------------------------------ 401 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 402 _fileutil.getZipArchive: 403 404 Extract files from zip-archive and return list of extracted files. 405 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 406 406 def getZipArchive(f): 407 407 l = [] … … 428 428 429 429 430 # ------------------------------------------------------------------------------ 431 #_fileutil.extractZipArchive:432 # 433 #Unpack ZIP-Archive.434 # ------------------------------------------------------------------------------ 430 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 431 _fileutil.extractZipArchive: 432 433 Unpack ZIP-Archive. 434 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 435 435 def extractZipArchive(file): 436 436 l = [] … … 455 455 456 456 457 # ------------------------------------------------------------------------------ 458 # _fileutil.buildZipArchive: 459 # 460 # Pack ZIP-Archive and return data. 461 # ------------------------------------------------------------------------------ 457 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 458 _fileutil.writeZipFile: 459 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 462 460 def writeZipFile( zf, basepath, path, filter): 463 461 for file in os.listdir( path): … … 474 472 zf.write( filepath, arcname) 475 473 474 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 475 _fileutil.buildZipArchive: 476 477 Pack ZIP-Archive and return data. 478 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 476 479 def buildZipArchive( files, get_data=True): 477 480
Note: See TracChangeset
for help on using the changeset viewer.
