Beispiel #1
0
 def format(self, name):
     thisDrive = Drive(name)
     thisDrive.format()
     thisDrive.write_block(0, "+" + "-" * 127 + ("f:" + " " * 9 + "0000:" + "000 " * 12) * 6)
     global availableBlocksList
     availableBlocksList = ['+'] + ['-' for x in range(127)]
     global availableBlockIndices 
     availableBlockIndices = list(range(1, 128))
     self.currentDrive = thisDrive
     self.rootDirectory = Directory(self.currentDrive, None, 0, None, None) #drive, fileNum, parentBlockNum, parent, name
     self.blocksAvailability = thisDrive.read_block(0)[:127]
Beispiel #2
0
class Volume:
    
    def __init__(self):
        self.currentDrive = None
        self.rootDirectory = None  
        self.blocksAvailability = None      

    def format(self, name):
        thisDrive = Drive(name)
        thisDrive.format()
        thisDrive.write_block(0, "+" + "-" * 127 + ("f:" + " " * 9 + "0000:" + "000 " * 12) * 6)
        global availableBlocksList
        availableBlocksList = ['+'] + ['-' for x in range(127)]
        global availableBlockIndices 
        availableBlockIndices = list(range(1, 128))
        self.currentDrive = thisDrive
        self.rootDirectory = Directory(self.currentDrive, None, 0, None, None) #drive, fileNum, parentBlockNum, parent, name
        self.blocksAvailability = thisDrive.read_block(0)[:127]

    def mkfile(self, path):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes[:-1]:
                lastNode = lastNode.getChild(node)
        except:
            print("Um there is some problem with your input")
        lastNode.addFile(nodes[-1])

    def mkdir(self, path):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes[:-1]:
                lastNode = lastNode.getChild(node)
        except:
            print("Um there is some problem with your input")
        lastNode.addDirectory(nodes[-1])

    def reconnect(self, name):
        self.currentDrive = Drive(name)
        self.rootDirectory = Directory(self.currentDrive, None, 0, None, name)
        self.currentDrive.reconnect()      
        self.blocksAvailability = self.currentDrive.read_block(0)[:127]

    def append(self, path, data):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes:
                lastNode = lastNode.getChild(node)
        except:
            print("Um there is some problem with your input")
        lastNode.appendData(data)
            
    def ls(self, path):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes:
                if node != "":
                    lastNode = lastNode.getChild(node)
            lastNode.list()
        except:
            print("Um there is some problem with your input")

    def print(self, path):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes:
                if node != "":
                    lastNode = lastNode.getChild(node)
            lastNode.print()
        except:
            print("Um there is some problem with your input")

    def delfile(self, path):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes:
                if node != "":
                    lastNode = lastNode.getChild(node)
            lastNode.delete()
        except:
            print("Um there is some problem with your input")

    def deldir(self, path):
        try:
            nodes = path.strip('/').split('/')
            lastNode = self.rootDirectory
            for node in nodes:
                if node != "":
                    lastNode = lastNode.getChild(node)      
            lastNode.delete()
        except:
            print("Um there is some problem with your input")