rendered paste bodyimport string, os
class command:
def check(self):
return len(self.pam)
def mkdir(self):
if os.path.isdir(self.fullpam)==0:
os.mkdir(self.fullpam,0)
else: print "Directory is allready exists"
def rmdir(self):
if os.path.isdir(self.fullpam):
os.rmdir(self.fullpam)
else: print "Wrong directory"
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 cat(self):
if os.path.isfile(self.fullpam):
f = open(self.fullpam,"r")
print f.read()
f.close()
else: print "No file like that.."
def echo(self):
zplat = string.split(self.fullpam,"->")
if len(zplat)>=2:
f = open(zplat[1],"a")
f.write(zplat[0])
f.close()
else: print self.fullpam
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,"mkdir":self.mkdir,"rmdir":self.rmdir,"echo":self.echo,"cat":self.cat}
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()