Ивайло обнови решението на 30.04.2015 16:59 (преди над 9 години)
+class FileSystemError(BaseException):
+ pass
+
+
+class NodeDoesNotExistError(FileSystemError):
+ pass
+
+
+class DestinationNodeDoesNotExistError(NodeDoesNotExistError):
+ pass
+
+
+class SourceNodeDoesNotExistError(NodeDoesNotExistError):
+ pass
+
+
+class NotEnoughSpaceError(FileSystemError):
+ pass
+
+
+class DestinationNodeExistsError(FileSystemError):
+ pass
+
+
+class NonExplicitDirectoryDeletionError(FileSystemError):
+ pass
+
+
+class NonEmptyDirectoryDeletionError(FileSystemError):
+ pass
+
+
+class DestinationNotADirectoryError(FileSystemError):
+ pass
+
+
+class DirectoryHardLinkError(FileSystemError):
+ pass
+
+
+class NotAMountpointError(FileSystemError):
+ pass
+
+
+class LinkPathError(FileSystemError):
+ pass
+
+
+class FileSystemMountError(FileSystemError):
+ pass
+
+
+class MountPointDoesNotExistError(FileSystemMountError):
+ pass
+
+
+class MountPointNotADirectoryError(FileSystemMountError):
+ pass
+
+
+class MountPointNotEmptyError(FileSystemMountError):
+ pass
+
+
+class FileSystemEntry:
+ def __init__(self, is_directory, absolute_path):
+ self.is_directory = is_directory
+ self.absolute_path = absolute_path
+
+ def get_path(self):
+ return self.absolute_path
+
+
+class File(FileSystemEntry):
+ def __init__(self, absolute_path, content):
+ FileSystemEntry.__init__(self, False, absolute_path)
+
+ self.content = content
+ self.size = 0
+ self.update_size()
+
+ def append(self, text):
+ self.content += text
+ self.update_size()
+
+ def truncate(self, text):
+ self.content = text
+ self.update_size()
+
+ def update_size(self):
+ self.size = len(self.content) + 1
+
+
+class Directory(FileSystemEntry):
+ def __init__(self, absolute_path):
+ FileSystemEntry.__init__(self, True, absolute_path)
+ self.directories = []
+ self.files = []
+ self.nodes = []
+
+
+class FileSystem:
+ def __init__(self, size):
+ self.size = size
+ self.available_size = size
+ self.root = Directory("/")
+
+ def get_node(self, path):
+ queue = []
+ queue.append(self.root)
+
+ while queue:
+ fs_entry = queue.pop(0)
+ if fs_entry.get_path() == path:
+ return fs_entry
+
+ if fs_entry.is_directory:
+ for node in fs_entry.nodes:
+ queue.append(node)
+
+ raise NodeDoesNotExistError
+
+ def create(self, path, directory=False, content=""):
+ pass
+
+ def remove(path, directory=False, force=False):
+ pass
+
+ def move(source, destination):
+ pass
+
+ def link(source, destination, symbolic=True):
+ pass
+
+ def mount(file_system, path):
+ pass
+
+ def unmount(path):
+ pass