<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> from __future__ import unicode_literals <EOL> import os <EOL> import glob <EOL> import codecs <EOL> class Dir ( object ) : <EOL> def __init__ ( self , path ) : <EOL> path = os . path . abspath ( path ) <EOL> self . setPath ( path ) <EOL> def setPath ( self , path ) : <EOL> self . path = path <EOL> self . dir = os . path . dirname ( self . path ) <EOL> self . name = os . path . basename ( self . path ) <EOL> self . caption = self . name <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . name , self . path ) <EOL> def getPath ( self ) : <EOL> return self . path <EOL> def getName ( self ) : <EOL> return self . name <EOL> def isTempFile ( self ) : <EOL> state = False <EOL> lower_name = self . name . lower ( ) <EOL> if lower_name == '<STR_LIT>' : <EOL> state = True <EOL> elif lower_name . startswith ( '<STR_LIT:$>' ) or lower_name . startswith ( '<STR_LIT:.>' ) : <EOL> state = True <EOL> elif lower_name . endswith ( '<STR_LIT>' ) or lower_name . endswith ( '<STR_LIT>' ) : <EOL> state = True <EOL> return state <EOL> def isDir ( self ) : <EOL> return os . path . isdir ( self . path ) <EOL> def listAll ( self , pattern = '<STR_LIT:*>' ) : <EOL> all_files = [ ] <EOL> paths = glob . glob ( os . path . join ( self . path , pattern ) ) <EOL> all_files = ( Dir ( path ) for path in paths ) <EOL> all_files = [ f for f in all_files if not f . isTempFile ( ) ] <EOL> all_files . sort ( key = lambda f : f . getName ( ) . lower ( ) ) <EOL> return all_files <EOL> def listDirs ( self , pattern = '<STR_LIT:*>' ) : <EOL> all_files = self . listAll ( pattern ) <EOL> dirs = [ Dir ( f . path ) for f in all_files if f . isDir ( ) ] <EOL> return dirs </s>
