All pastes #9977 Raw Edit

Anonymous

public text v1 · immutable
#9977 ·published 2005-04-21 07:12 UTC
rendered paste body
import string, os

class command:

    

    def check(self):
        return len(self.pam)


    
    def cd(self):
        if self.fullpam!='0':
            if(os.path.isdir(self.fullpam)):
                os.chdir(self.fullpam)
            else:
                print "Wrong directory.."
        else:
            os.chdir("..")



    def delc(self):
        if self.fullpam!='0':
            if os.path.isfile(self.fullpam):
                os.remove(self.fullpam)
            else: print "No file like that"
        else: print "Shall I delete nothing?"



    def dirc(self):
        if self.fullpam!='0':
            if os.path.isdir(self.fullpam):
                for zuck in os.listdir(self.fullpam):
                    if os.path.isdir(self.fullpam + "/" + zuck): zuck = "[" + zuck + "]"
                    print zuck
            else: print "Wrong directory"
        else:
            for zuck in os.listdir(''):
                    if os.path.isdir(zuck): zuck = "[" + zuck + "]"
                    print zuck


    def dird(self):
        if self.fullpam!='0':
            if os.path.isdir(self.fullpam):
                for zuck in os.listdir(self.fullpam):
                    if os.path.isdir(self.fullpam + "/" + zuck):
                        print "[" + zuck + "]"
                    else:
                        print zuck + " "*(30-len(zuck)) + str(os.path.getsize(self.fullpam + "/" + zuck))
            else: print "Wrong directory"
        else:
            for zuck in os.listdir(''):
                    if os.path.isdir(zuck):
                        print "[" + zuck + "]"
                    else:
                        print zuck + " "*(30-len(zuck)) + str(os.path.getsize(zuck))


    def rename(self):
        if len(self.pam)==2:
            print os.rename(self.pam[0],self.pam[1])
        else:
            print "too less/many arguments..."
                







    def failed(self):
        print "failed"
    
    def startit(self):

        
        self.ic = {"exit":exit,"cd":self.cd,"del":self.delc,"dir":self.dirc,"dird":self.dird,"ren":self.rename}
        
        self.pam = []
        self.pasta = string.split(self.stuck," ")
        self.comm = self.pasta[0]
        for l in range(1,len(self.pasta)):
            self.pam.append(self.pasta[l])
        
        if(len(self.pam)!=0):
            self.fullpam = self.pam[0]
            for s in range(1,len(self.pam)):
                self.fullpam = self.fullpam + " " + self.pam[s]
        else: 
            self.fullpam = '0'
        
        self.ic.get(self.comm,self.failed)()

    


while 1:
    comm = command()
    comm.stuck = raw_input(os.getcwd() + ">")
    comm.startit()