Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (51 sloc) 1.581 kB
#!/usr/bin/python
from dFile import dFile
class dFolder:
def __init__(self, name, parent):
self.name = name
self.files = []
self.folders = []
self.perms = 755
self.parent = parent
def add(self, f):
self.addFile(f) if isinstance(f,dFile) else self.addFolder(f)
def addFile(self, f):
self.files.append(f)
def addFolder(self, f):
self.folders.append(f)
def empty(self):
return len(self.folders)==0 and len(self.files)==0
def getFiles(self):
return sorted(self.files, key=lambda x: x.name)
def getFolders(self):
return sorted(self.folders, key=lambda x: x.name)
def getAll(self):
return sorted(self.files+self.folders, key=lambda x: x.name)
def getName(self):
return 'root' if self.name=='' else self.name
def find(self, name):
f = filter(lambda x: x.name==name, (self.files+self.folders))
return None if len(f)==0 else f[0]
def printf(self):
print self.name+"/ ",
def printl(self):
print "d%s%s%s\t4KB\t%s"%('rwx','r-x','r-x',self.name)
def remove(self):
if self.parent is not None:
self.parent.folders.remove(self)
else:
print "cannot delete hard drive"
def to_s(self, line):
self.printl() if line else self.printf()
def traverse(self, paths, drive=None):
if len(paths)==0: return self
path = paths.pop()
if path=='' and drive is not None:
return drive.traverse(paths)
elif path=='.':
return self.traverse(paths)
elif path=='..':
return None if self.parent is None else self.parent.traverse(paths)
else:
tmp = self.find(path)
return None if tmp is None else tmp.traverse(paths)
Jump to Line
Something went wrong with that request. Please try again.