Решение на In-memory файлова система от Ивайло Цанков

Обратно към всички решения

Към профила на Ивайло Цанков

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 1 успешни тест(а)
  • 17 неуспешни тест(а)

Код

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

Лог от изпълнението

EEEEEEEEEEEEEE.EEE
======================================================================
ERROR: test_create_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_create_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_create (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_space_consumption (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_to_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_to_missing_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_link_create (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_minimal (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_mounting (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_move_not_to_a_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_move_overwrite (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_out_of_space (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_overwrite (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_remove_empty_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_remove_nonempty_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_symlink_to_missing_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_valid_move (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 18 tests in 34.135s

FAILED (errors=17)

История (1 версия и 0 коментара)

Ивайло обнови решението на 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