wrapper classes question..

V

vegetax

Hi i made a wrapper class for handling file and dir operations and i wonder,
 whats the performance penalty for making such wrapper classes? is it ok to
make a lot of these wrappers? here it is:

#################
import os

class File(object):

    #access modes
    F_OK = os.F_OK,
    W_OK = os.W_OK,
    R_OK = os.R_OK,
    X_OK = os.X_OK
     
        
    def __init__(s,pathToFile):

 s.path = pathToFile
 s.name = os.path.basename(s.path)
 s.dirName = os.path.dirname(s.path)
 #s.size = path.getsize(s.path)

    
    def size(s):
 return os.path.getsize(s.path)
    
    def open(s,mode='r'):
 return open(s.path,mode)

    def openw(s):
 return open(s.path,'w')

    def access(s,mode):
 return os.access(s.path,mode)
    
    def abspath(s):
 return os.path.abspath(s.path)

    def getatime(s):
 return os.path.getatime(s.path)
    
    def getctime(s):
 return os.path.getctime(s.path)
    
    def isabs(s):
 return os.path.isabs(s.path)

    def isfile(s):
 return os.path.isfile(s.path)

    def isdir(s):
 return os.path.isdir(s.path)

    def ext(s):
 return os.path.splitext(s.path)[1]

    def stat(s):
 return os.stat(s.path)
    
    def access(s,mode):
 return os.access(s.path,mode)

def chdir(path) : os.chdir(path)

def cwd() : return os.getcwd()

def chmod(path,mode): return os.chmod(path,mode)

def chown(path,uid,gid): os.chown(path,uid,gid)

def ln(src,dest): os.symlink(src,dest)

def ls(path): return os.listdir(path)

def mkdir(path,rec=False,mode = 0777) :
    if not rec:
        os.mkdir(path,mode)
    else:
 os.makedirs(path,mode)

def rm(path):    os.remove(path)

def rename(old,new): os.rename(old,new)

def rmdir(path): os.rmdir(path)

def xremove(path) :
    'just unix'
    os.system('rm -rf %s' % path)

def utime(path,times=None):
    'set times of a file\
    times = tuple like (atime,ctime) '
    os.utime(path,times)

if __name__ == '__main__':
    
    f = File('/tmp')
    print f.isfile()
    print f.isdir()
    print f.size()
    print ls('/tmp')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top