<s> import os <EOL> """<STR_LIT>""" <EOL> OPEN_FUNC = open <EOL> sep = os . sep <EOL> try : <EOL> import types <EOL> LIST_TYPE = types . ListType <EOL> except Exception : <EOL> LIST_TYPE = list <EOL> """<STR_LIT>""" <EOL> def _is_list ( e ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( e , LIST_TYPE ) <EOL> def _to_list ( e ) : <EOL> """<STR_LIT>""" <EOL> return e if _is_list ( e ) else [ e ] <EOL> """<STR_LIT>""" <EOL> def isfile ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> return os . path . isfile ( path , ** kwargs ) <EOL> def isdir ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> return os . path . isdir ( path , ** kwargs ) <EOL> def rename ( oldPath , newPath , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . rename ( oldPath , newPath , ** kwargs ) <EOL> def copy ( srcPath , destPath ) : <EOL> """<STR_LIT>""" <EOL> import shutils <EOL> return shutil . copy ( srcPath , destPath ) <EOL> def truncate ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> rmfiles ( list ( path ) ) <EOL> rmdirs ( listdirs ( path ) ) <EOL> def chdir ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . chdir ( path , ** kwargs ) <EOL> def chown ( path , user = None , group = None ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> import pwd <EOL> import grp <EOL> uid = pwd . getpwnam ( user ) . pw_uid if user else - <NUM_LIT:1> <EOL> gid = grp . getgrnam ( group ) . gr_gid if group else - <NUM_LIT:1> <EOL> return os . chown ( path , uid , gid ) <EOL> def chmod ( path , mode ) : <EOL> """<STR_LIT>""" <EOL> import os , stat <EOL> st = os . stat ( path ) <EOL> return os . chmod ( path , mode ) <EOL> def link ( srcPath , destPath ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . link ( srcPath , destPath ) <EOL> def symlink ( srcPath , destPath ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . symlink ( srcPath , destPath ) <EOL> def stat ( path ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . stat ( path ) <EOL> def ctime ( path ) : <EOL> """<STR_LIT>""" <EOL> return stat ( path ) . st_ctime <EOL> def atime ( path ) : <EOL> """<STR_LIT>""" <EOL> return stat ( path ) . st_atime <EOL> def mtime ( path ) : <EOL> """<STR_LIT>""" <EOL> return stat ( path ) . st_mtime <EOL> def mode ( path ) : <EOL> """<STR_LIT>""" <EOL> return stat ( path ) . st_mode <EOL> def abspath ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> return os . path . abspath ( path , ** kwargs ) <EOL> def normalize ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> return os . path . normpath ( path , ** kwargs ) <EOL> def rm ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . unlink ( path , ** kwargs ) <EOL> def unlink ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return rm ( * args , ** kwargs ) <EOL> def rmdir ( path , recursive = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if recursive : <EOL> import shutil <EOL> return shutil . rmtree ( path , ** kwargs ) <EOL> else : <EOL> import os <EOL> return os . remdir ( path , ** kwargs ) <EOL> def rmfiles ( paths , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for p in paths : <EOL> rm ( p , ** kwargs ) <EOL> def rmdirs ( paths , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for p in paths : <EOL> rmdir ( p , ** kwargs ) <EOL> def mkdir ( path , recursive = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> if recursive : <EOL> os . makedirs ( path , ** kwargs ) <EOL> else : <EOL> os . mkdir ( path , ** kwargs ) <EOL> def touch ( path ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> try : <EOL> OPEN_FUNC ( path , '<STR_LIT>' ) . close ( ) <EOL> except IOError : <EOL> os . utime ( path , None ) <EOL> def exists ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> return os . path . exists ( path , ** kwargs ) <EOL> def access ( path , ** kwargs ) : <EOL> pass <EOL> def list ( path = '<STR_LIT:.>' ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> for f in os . listdir ( path ) : <EOL> if isfile ( join ( path , f ) ) : <EOL> yield join ( path , f ) if path != '<STR_LIT:.>' else f <EOL> def listdirs ( path = '<STR_LIT:.>' ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> for f in os . listdir ( path ) : <EOL> if isdir ( join ( path , f ) ) : <EOL> yield join ( path , f ) if path != '<STR_LIT:.>' else f <EOL> def find ( pattern , path = '<STR_LIT:.>' , exclude = None , recursive = True ) : <EOL> """<STR_LIT>""" <EOL> import fnmatch <EOL> import os <EOL> if recursive : <EOL> for root , dirnames , filenames in os . walk ( path ) : <EOL> for pat in _to_list ( pattern ) : <EOL> for filename in fnmatch . filter ( filenames , pat ) : <EOL> filepath = join ( abspath ( root ) , filename ) <EOL> for excl in _to_list ( exclude ) : <EOL> if excl and fnmatch . fnmatch ( filepath , excl ) : <EOL> break <EOL> else : <EOL> yield filepath <EOL> else : <EOL> for pat in _to_list ( pattern ) : <EOL> for filename in fnmatch . filter ( list ( path ) , pat ) : <EOL> filepath = join ( abspath ( path ) , filename ) <EOL> for excl in _to_list ( exclude ) : <EOL> if excl and fnmatch . fnmatch ( filepath , excl ) : <EOL> break <EOL> else : <EOL> yield filepath <EOL> def finddirs ( pattern , path = '<STR_LIT:.>' , exclude = None , recursive = True ) : <EOL> """<STR_LIT>""" <EOL> import fnmatch <EOL> import os <EOL> if recursive : <EOL> for root , dirnames , filenames in os . walk ( path ) : <EOL> for pat in _to_list ( pattern ) : <EOL> for dirname in fnmatch . filter ( dirnames , pat ) : <EOL> dirpath = join ( abspath ( root ) , dirname ) <EOL> for excl in _to_list ( exclude ) : <EOL> if excl and fnmatch . fnmatch ( dirpath , excl ) : <EOL> break <EOL> else : <EOL> yield dirpath <EOL> else : <EOL> for pat in _to_list ( pattern ) : <EOL> for dirname in fnmatch . filter ( listdirs ( path ) , pat ) : <EOL> dirpath = join ( abspath ( path ) , dirname ) <EOL> for excl in _to_list ( exclude ) : <EOL> if excl and fnmatch . fnmatch ( dirpath , excl ) : <EOL> break <EOL> else : <EOL> yield dirpath <EOL> def open ( path , mode = '<STR_LIT:r>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return OPEN_FUNC ( path , mode , ** kwargs ) <EOL> def write ( path , content , encoding = "<STR_LIT>" , append = False , raw = False ) : <EOL> """<STR_LIT>""" <EOL> mode = '<STR_LIT:wb>' if not append else '<STR_LIT>' <EOL> with OPEN_FUNC ( path , mode ) as _file : <EOL> if raw : <EOL> import shutil <EOL> shutil . copyfileobj ( content , _file ) <EOL> else : <EOL> _file . write ( content . encode ( encoding ) ) <EOL> def read ( path , encoding = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> with OPEN_FUNC ( path , '<STR_LIT:rb>' ) as _file : <EOL> cont = _file . read ( ) <EOL> return cont . decode ( encoding ) <EOL> def get ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import cPickle as pickle <EOL> except : <EOL> import pickle <EOL> with open ( path , '<STR_LIT:rb>' ) as file : <EOL> return pickle . load ( file ) <EOL> def put ( path , obj ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import cPickle as pickle <EOL> except : <EOL> import pickle <EOL> with open ( path , '<STR_LIT:wb>' ) as file : <EOL> return pickle . dump ( obj , file ) <EOL> def join ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> if _is_list ( args [ <NUM_LIT:0> ] ) : <EOL> return os . path . join ( * args [ <NUM_LIT:0> ] ) <EOL> return os . path . join ( * args , ** kwargs ) <EOL> def cwd ( ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> return os . getcwd ( ) <EOL> def home ( ) : <EOL> """<STR_LIT>""" <EOL> from os . path import expanduser <EOL> return expanduser ( "<STR_LIT>" ) <EOL> def extname ( path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> name , ext = os . path . splitext ( path , ** kwargs ) <EOL> return ext <EOL> def basename ( path , ext = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> if ext is False : <EOL> return os . path . basename ( path ) . replace ( extname ( path ) , "<STR_LIT>" ) <EOL> else : <EOL> return os . path . basename ( path ) . replace ( ext , "<STR_LIT>" ) <EOL> def dirname ( path ) : <EOL> """<STR_LIT>""" <EOL> import os . path <EOL> return os . path . dirname ( path ) <EOL> def add_suffix ( path , suffix = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> return join ( dirname ( path ) , basename ( path , ext = False ) + suffix + extname ( path ) ) <EOL> def add_prefix ( path , prefix = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> return join ( dirname ( path ) , prefix + basename ( path ) ) <EOL> def addpath ( path ) : <EOL> """<STR_LIT>""" <EOL> import sys <EOL> if not exists ( path ) : <EOL> raise ValueError ( '<STR_LIT>' % path ) <EOL> sys . path . insert ( <NUM_LIT:1> , path ) <EOL> """<STR_LIT>""" <EOL> def append ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return write ( * args , append = True , ** kwargs ) <EOL> def filename ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return basename ( * args , ** kwargs ) <EOL> def extension ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return extname ( * args , ** kwargs ) <EOL> def cd ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return chdir ( * args , ** kwargs ) </s>
