Решение на In-memory файлова система от Виктор Драганов

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

Към профила на Виктор Драганов

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 4 успешни тест(а)
  • 14 неуспешни тест(а)

Код

class FileSystem:
"""docstring for FileSystem"""
def __init__(self, input_size):
self.__size = input_size
self.__available_size = input_size - 1
self.__nodes = []
def size(self):
return self.__size
def available_size(self):
return self.__available_size
def get_node(self, path):
searched_path = self.__get_split_path(path)
if searched_path == []:
return self.__nodes
searched_nodes = self.__nodes
node_found = -1
while len(searched_path) > 0:
name = searched_path[0]
node_found = self.__find_node_by_name(searched_nodes, name)
if node_found == -1:
raise NodeDoesNotExistError
searched_path = searched_path[1:]
if not node_found.is_directory():
if len(searched_path) == 0:
return node_found
else:
# File can't contain any nodes!
# Example: '/home/file.txt/dir1' is invalid path!
raise NodeDoesNotExistError
searched_nodes = node_found._nodes
if node_found == -1:
raise NodeDoesNotExistError
return node_found
def create(self, path, directory=False, content=''):
try:
self.get_node(path)
raise DestinationNodeExistsError
print('YMU')
except NodeDoesNotExistError:
searched_path = self.__get_split_path(path)
name = searched_path[-1]
new_node = self.__create_new_node(name, directory, content)
if directory:
new_node_size = 1
else:
new_node_size = new_node.size()
if self.__available_size - new_node_size < 0:
raise NotEnoughSpaceError
else:
self.__available_size -= new_node_size # Assigning 'memory'
if len(searched_path) == 1:
# Created directly in the file system nodes.
self.__nodes.append(new_node)
else:
path_to_create = path[0:path.rfind('/')]
if self.get_node(path_to_create).is_directory():
self.get_node(path_to_create)._nodes.append(new_node)
else:
raise AttemptingToCreateInFileError
# Must raise an error if attempting to create in file.
def remove(self, path, directory=False, force=True):
node_to_remove = self.get_node(path)
if node_to_remove.is_directory():
if not directory:
raise NonExplicitDirectoryDeletionError
elif not (node_to_remove._nodes == [] or force):
# If directory is not empty and force is False.
raise NonEmptyDirectoryDeletionError
else:
self.__available_size += 1
# Detach the node from upper directory.
self.get_node(self.__upper_path(path)).remove(node_to_remove)
else:
self.__available_size += node_to_remove.size()
self.get_node(self.__upper_path(path)).remove(node_to_remove)
# REALLOCATE MEMORY!!! -> Done!
def move(self, source, destination):
try:
node_to_move = self.get_node(source)
except NodeDoesNotExistError:
raise SourceNodeDoesNotExistError
except:
print('Unknown error! Please keep calm & code more Python!')
try:
destination_node = self.get_node(destination)
except NodeDoesNotExistError:
raise DestinationNodeDoesNotExistError
if not destination_node.is_directory():
raise DestinationNotADirectoryError
if not (self.__find_node_by_name(destination_node._nodes,
node_to_move.name()) == -1):
# If there is already a node with such name in the destination.
raise DestinationNodeExistsError
destination_node._nodes.append(node_to_move)
self.get_node(__upper_path(source)).remove(node_to_move)
def link(self, source, destination, symbolic=True):
pass
# TO IMPLEMENT
def mount(self, file_system, path):
try:
directory_to_mount = self.get_node(path)
except NodeDoesNotExistError:
raise MountPointDoesNotExistError
if not directory_to_mount.is_directory():
raise MountPointNotADirectoryError
elif directory_to_mount.nodes == []:
raise MountPointNotEmptyError
directory_to_mount._nodes = file_system.__nodes
def unmount(self, path):
directory_to_unmount = self.get_node(path)
if (directory_to_unmount._nodes == [] or not
directory_to_unmount._nodes[0].owner == self):
raise NotAMountPointError
def __create_new_node(self, name, directory=False, content=''):
if directory:
new_node = Directory(name)
else:
new_node = File(name, content)
new_node._owner = self
return new_node
def __find_node_by_name(self, nodes, name):
# Searches for a node in given collection.
# Returns -1 if there is none with such name.
for node in nodes:
if node.name() == name:
return node
return -1
def __get_split_path(self, path):
# Returns a list of all directories of the given argument.
# Since the split gives one '' element in the list, it's not included.
# __get_split_path('/home/dir1/dir2') returns [home, dir1, dir2]
return path.split('/')[1:]
def __upper_path(self, path):
# Returns the path one level/floor before the given argument.
# __upper_path('/home/dir1/dir2') returns '/home/dir1'
return path[0:path.rfind('/')]
###
class Node:
""" A Node object represents a node from a FileSystem object's content.
It 'knows' it's name(str), if it is a directory(bool) and it's
owner(reference to a FileSystem object).
"""
def __init__(self, name, is_directory):
self.__name = name
self.__is_directory = is_directory
self.__owner = None
def is_directory(self):
return self.__is_directory
def name(self):
return self.__name
def _get_owner(self):
return self.__owner
def _set_owner(self, file_system):
if not type(file_system) is FileSystem:
raise NotAValidOwnerError
self.__owner = file_system
class Directory(Node):
"""docstring for Directory"""
def __init__(self, name):
super(Directory, self).__init__(name, True)
self._nodes = []
def directories(self):
dirs = []
for i in range(0, len(_nodes) - 1):
if _nodes[i].is_directory():
dirs.append(_nodes[i])
return dirs
def files(self):
files = []
for i in range(0, len(_nodes) - 1):
if not _nodes[i].is_directory():
files.append(_nodes[i])
return files
def nodes(self):
return self._nodes
class File(Node):
"""docstring for File"""
def __init__(self, name, content):
super(File, self).__init__(name, False)
self.__content = content
def append(self, text):
if self._owner.available_size < len(text):
raise NotEnoughSpaceError
self.__content += text
self._owner.available_size -= len(text)
def content(self):
return self.__content
def size(self):
return len(self.__content) + 1
def truncate(self, text):
if self._owner.available_size - len(self.__content) < len(text):
raise NotEnoughSpaceError
self.__content = text
###
# Exeptions:
###
class FileSystemError(BaseException):
# All exeptions inherit FileSystemError !
pass
class NodeDoesNotExistError(FileSystemError):
pass
class DestinationNodeDoesNotExistError(NodeDoesNotExistError):
pass
class SourceNodeDoesNotExistError(NodeDoesNotExistError):
pass
class NotEnoughSpaceError(FileSystemError):
pass
class DestinationNodeExistsError(FileSystemError):
pass
class DestinationNotADirectoryError(FileSystemError):
pass
# remove()
class NonExplicitDirectoryDeletionError(FileSystemError):
pass
class NonEmptyDirectoryDeletionError(FileSystemError):
pass
# link()
class DirectoryHardLinkError(FileSystemError):
pass
# mount()
class FileSystemMountError(FileSystemError):
pass
class MountPointNotEmptyError(FileSystemMountError):
pass
class MountPointNotADirectoryError(FileSystemMountError):
pass
class MountPointDoesNotExistError(FileSystemMountError):
pass
# unmount()
class NotAMountPointError(FileSystemMountError):
pass
# MY ERRORS:
class NotAValidOwnerError(FileSystemError):
pass
class AttemptingToCreateInFileError(FileSystemError):
pass

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

.EEEEEEEEE...EEEEE
======================================================================
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_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_file (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 28.153s

FAILED (errors=14)

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

Виктор обнови решението на 30.04.2015 16:10 (преди над 9 години)

+class FileSystem:
+
+ """docstring for FileSystem"""
+
+ def __init__(self, input_size):
+ self.__size = input_size
+ self.__available_size = input_size - 1
+ self.__nodes = []
+
+ def size(self):
+ return self.__size
+
+ def available_size(self):
+ return self.__available_size
+
+ def get_node(self, path):
+ searched_path = self.__get_split_path(path)
+ if searched_path == []:
+ return self.__nodes
+
+ searched_nodes = self.__nodes
+ node_found = -1
+ while len(searched_path) > 0:
+ name = searched_path[0]
+ node_found = self.__find_node_by_name(searched_nodes, name)
+ if node_found == -1:
+ raise NodeDoesNotExistError
+
+ searched_path = searched_path[1:]
+ if not node_found.is_directory():
+ if len(searched_path) == 0:
+ return node_found
+ else:
+ # File can't contain any nodes!
+ # Example: '/home/file.txt/dir1' is invalid path!
+ raise NodeDoesNotExistError
+
+ searched_nodes = node_found._nodes
+
+ if node_found == -1:
+ raise NodeDoesNotExistError
+
+ return node_found
+
+ def create(self, path, directory=False, content=''):
+ try:
+ self.get_node(path)
+ raise DestinationNodeExistsError
+ print('YMU')
+ except NodeDoesNotExistError:
+
+ searched_path = self.__get_split_path(path)
+ name = searched_path[-1]
+ new_node = self.__create_new_node(name, directory, content)
+ if directory:
+ new_node_size = 1
+ else:
+ new_node_size = new_node.size()
+
+ if self.__available_size - new_node_size < 0:
+ raise NotEnoughSpaceError
+ else:
+ self.__available_size -= new_node_size # Assigning 'memory'
+
+ if len(searched_path) == 1:
+ # Created directly in the file system nodes.
+ self.__nodes.append(new_node)
+ else:
+ path_to_create = path[0:path.rfind('/')]
+ if self.get_node(path_to_create).is_directory():
+ self.get_node(path_to_create)._nodes.append(new_node)
+ else:
+ raise AttemptingToCreateInFileError
+ # Must raise an error if attempting to create in file.
+
+ def remove(self, path, directory=False, force=True):
+ node_to_remove = self.get_node(path)
+ if node_to_remove.is_directory():
+ if not directory:
+ raise NonExplicitDirectoryDeletionError
+ elif not (node_to_remove._nodes == [] or force):
+ # If directory is not empty and force is False.
+ raise NonEmptyDirectoryDeletionError
+ else:
+ self.__available_size += 1
+ # Detach the node from upper directory.
+ self.get_node(self.__upper_path(path)).remove(node_to_remove)
+ else:
+ self.__available_size += node_to_remove.size()
+ self.get_node(self.__upper_path(path)).remove(node_to_remove)
+
+ # REALLOCATE MEMORY!!! -> Done!
+
+ def move(self, source, destination):
+ try:
+ node_to_move = self.get_node(source)
+ except NodeDoesNotExistError:
+ raise SourceNodeDoesNotExistError
+ except:
+ print('Unknown error! Please keep calm & code more Python!')
+
+ try:
+ destination_node = self.get_node(destination)
+ except NodeDoesNotExistError:
+ raise DestinationNodeDoesNotExistError
+
+ if not destination_node.is_directory():
+ raise DestinationNotADirectoryError
+
+ if not (self.__find_node_by_name(destination_node._nodes,
+ node_to_move.name()) == -1):
+ # If there is already a node with such name in the destination.
+ raise DestinationNodeExistsError
+
+ destination_node._nodes.append(node_to_move)
+ self.get_node(__upper_path(source)).remove(node_to_move)
+
+ def link(self, source, destination, symbolic=True):
+ pass
+ # TO IMPLEMENT
+
+ def mount(self, file_system, path):
+ pass
+ # TO IMPLEMENT
+
+ def unmount(self, path):
+ pass
+ # TO IMPLEMENT
+
+ def __create_new_node(self, name, directory=False, content=''):
+ if directory:
+ new_node = Directory(name)
+ else:
+ new_node = File(name, content)
+
+ new_node._owner = self
+ return new_node
+
+ def __find_node_by_name(self, nodes, name):
+ # Searches for a node in given collection.
+ # Returns -1 if there is none with such name.
+ for node in nodes:
+ if node.name() == name:
+ return node
+ return -1
+
+ def __get_split_path(self, path):
+ # Returns a list of all directories of the given argument.
+ # Since the split gives one '' element in the list, it's not included.
+ # __get_split_path('/home/dir1/dir2') returns [home, dir1, dir2]
+ return path.split('/')[1:]
+
+ def __upper_path(self, path):
+ # Returns the path one level/floor before the given argument.
+ # __upper_path('/home/dir1/dir2') returns '/home/dir1'
+ return path[0:path.rfind('/')]
+
+ ###
+
+
+class Node:
+
+ """ A Node object represents a node from a FileSystem object's content.
+ It 'knows' it's name(str), if it is a directory(bool) and it's
+ owner(reference to a FileSystem object).
+ """
+
+ def __init__(self, name, is_directory):
+ self.__name = name
+ self.__is_directory = is_directory
+ self.__owner = None
+
+ def is_directory(self):
+ return self.__is_directory
+
+ def name(self):
+ return self.__name
+
+ def _get_owner(self):
+ return self.__owner
+
+ def _set_owner(self, file_system):
+ if not type(file_system) is FileSystem:
+ raise NotAValidOwnerError
+
+ self.__owner = file_system
+
+
+class Directory(Node):
+
+ """docstring for Directory"""
+
+ def __init__(self, name):
+ super(Directory, self).__init__(name, True)
+ self._nodes = []
+
+ def directories(self):
+ dirs = []
+ for i in range(0, len(_nodes) - 1):
+ if _nodes[i].is_directory():
+ dirs.append(_nodes[i])
+ return dirs
+
+ def files(self):
+ files = []
+ for i in range(0, len(_nodes) - 1):
+ if not _nodes[i].is_directory():
+ files.append(_nodes[i])
+ return files
+
+ def nodes(self):
+ return self._nodes
+
+
+class File(Node):
+
+ """docstring for File"""
+
+ def __init__(self, name, content):
+ super(File, self).__init__(name, False)
+ self.__content = content
+
+ def append(self, text):
+ if self._owner.available_size < len(text):
+ raise NotEnoughSpaceError
+
+ self.__content += text
+ self._owner.available_size -= len(text)
+
+ def content(self):
+ return self.__content
+
+ def size(self):
+ return len(self.__content) + 1
+
+ def truncate(self, text):
+ if self._owner.available_size - len(self.__content) < len(text):
+ raise NotEnoughSpaceError
+
+ self.__content = text
+
+ ###
+ # Exeptions:
+ ###
+
+
+class FileSystemError(BaseException):
+ # All exeptions inherit FileSystemError !
+ pass
+
+
+class NodeDoesNotExistError(FileSystemError):
+ pass
+
+
+class DestinationNodeDoesNotExistError(NodeDoesNotExistError):
+ pass
+
+
+class SourceNodeDoesNotExistError(NodeDoesNotExistError):
+ pass
+
+
+class NotEnoughSpaceError(FileSystemError):
+ pass
+
+
+class DestinationNodeExistsError(FileSystemError):
+ pass
+
+
+class DestinationNotADirectoryError(FileSystemError):
+ pass
+ # remove()
+
+
+class NonExplicitDirectoryDeletionError(FileSystemError):
+ pass
+
+
+class NonEmptyDirectoryDeletionError(FileSystemError):
+ pass
+ # link()
+
+
+class DirectoryHardLinkError(FileSystemError):
+ pass
+ # mount()
+
+
+class FileSystemMountError(FileSystemError):
+ pass
+
+
+class MountPointNotEmptyError(FileSystemMountError):
+ pass
+
+
+class MountPointNotADirectoryError(FileSystemMountError):
+ pass
+
+
+class MountPointDoesNotExistError(FileSystemMountError):
+ pass
+ # unmount()
+
+
+class NotAMountPointError(FileSystemMountError):
+ pass
+
+ # MY ERRORS:
+
+
+class NotAValidOwnerError(FileSystemError):
+ pass
+
+
+class AttemptingToCreateInFileError(FileSystemError):
+ pass

Виктор обнови решението на 30.04.2015 16:24 (преди над 9 години)

class FileSystem:
"""docstring for FileSystem"""
def __init__(self, input_size):
self.__size = input_size
self.__available_size = input_size - 1
self.__nodes = []
def size(self):
return self.__size
def available_size(self):
return self.__available_size
def get_node(self, path):
searched_path = self.__get_split_path(path)
if searched_path == []:
return self.__nodes
searched_nodes = self.__nodes
node_found = -1
while len(searched_path) > 0:
name = searched_path[0]
node_found = self.__find_node_by_name(searched_nodes, name)
if node_found == -1:
raise NodeDoesNotExistError
searched_path = searched_path[1:]
if not node_found.is_directory():
if len(searched_path) == 0:
return node_found
else:
# File can't contain any nodes!
# Example: '/home/file.txt/dir1' is invalid path!
raise NodeDoesNotExistError
searched_nodes = node_found._nodes
if node_found == -1:
raise NodeDoesNotExistError
return node_found
def create(self, path, directory=False, content=''):
try:
self.get_node(path)
raise DestinationNodeExistsError
print('YMU')
except NodeDoesNotExistError:
searched_path = self.__get_split_path(path)
name = searched_path[-1]
new_node = self.__create_new_node(name, directory, content)
if directory:
new_node_size = 1
else:
new_node_size = new_node.size()
if self.__available_size - new_node_size < 0:
raise NotEnoughSpaceError
else:
self.__available_size -= new_node_size # Assigning 'memory'
if len(searched_path) == 1:
# Created directly in the file system nodes.
self.__nodes.append(new_node)
else:
path_to_create = path[0:path.rfind('/')]
if self.get_node(path_to_create).is_directory():
self.get_node(path_to_create)._nodes.append(new_node)
else:
raise AttemptingToCreateInFileError
# Must raise an error if attempting to create in file.
def remove(self, path, directory=False, force=True):
node_to_remove = self.get_node(path)
if node_to_remove.is_directory():
if not directory:
raise NonExplicitDirectoryDeletionError
elif not (node_to_remove._nodes == [] or force):
# If directory is not empty and force is False.
raise NonEmptyDirectoryDeletionError
else:
self.__available_size += 1
# Detach the node from upper directory.
self.get_node(self.__upper_path(path)).remove(node_to_remove)
else:
self.__available_size += node_to_remove.size()
self.get_node(self.__upper_path(path)).remove(node_to_remove)
# REALLOCATE MEMORY!!! -> Done!
def move(self, source, destination):
try:
node_to_move = self.get_node(source)
except NodeDoesNotExistError:
raise SourceNodeDoesNotExistError
except:
print('Unknown error! Please keep calm & code more Python!')
try:
destination_node = self.get_node(destination)
except NodeDoesNotExistError:
raise DestinationNodeDoesNotExistError
if not destination_node.is_directory():
raise DestinationNotADirectoryError
if not (self.__find_node_by_name(destination_node._nodes,
node_to_move.name()) == -1):
# If there is already a node with such name in the destination.
raise DestinationNodeExistsError
destination_node._nodes.append(node_to_move)
self.get_node(__upper_path(source)).remove(node_to_move)
def link(self, source, destination, symbolic=True):
pass
# TO IMPLEMENT
def mount(self, file_system, path):
- pass
- # TO IMPLEMENT
+ try:
+ directory_to_mount = self.get_node(path)
+ except NodeDoesNotExistError:
+ raise MountPointDoesNotExistError
+ if not directory_to_mount.is_directory():
+ raise MountPointNotADirectoryError
+
+ elif directory_to_mount.nodes == []:
+ raise MountPointNotEmptyError
+
+ directory_to_mount._nodes = file_system.__nodes
+
def unmount(self, path):
- pass
- # TO IMPLEMENT
+ directory_to_unmount = self.get_node(path)
+ if (directory_to_unmount._nodes == [] or not
+ directory_to_unmount._nodes[0].owner == self):
+ raise NotAMountPointError
def __create_new_node(self, name, directory=False, content=''):
if directory:
new_node = Directory(name)
else:
new_node = File(name, content)
new_node._owner = self
return new_node
def __find_node_by_name(self, nodes, name):
# Searches for a node in given collection.
# Returns -1 if there is none with such name.
for node in nodes:
if node.name() == name:
return node
return -1
def __get_split_path(self, path):
# Returns a list of all directories of the given argument.
# Since the split gives one '' element in the list, it's not included.
# __get_split_path('/home/dir1/dir2') returns [home, dir1, dir2]
return path.split('/')[1:]
def __upper_path(self, path):
# Returns the path one level/floor before the given argument.
# __upper_path('/home/dir1/dir2') returns '/home/dir1'
return path[0:path.rfind('/')]
###
class Node:
""" A Node object represents a node from a FileSystem object's content.
It 'knows' it's name(str), if it is a directory(bool) and it's
owner(reference to a FileSystem object).
"""
def __init__(self, name, is_directory):
self.__name = name
self.__is_directory = is_directory
self.__owner = None
def is_directory(self):
return self.__is_directory
def name(self):
return self.__name
def _get_owner(self):
return self.__owner
def _set_owner(self, file_system):
if not type(file_system) is FileSystem:
raise NotAValidOwnerError
self.__owner = file_system
class Directory(Node):
"""docstring for Directory"""
def __init__(self, name):
super(Directory, self).__init__(name, True)
self._nodes = []
def directories(self):
dirs = []
for i in range(0, len(_nodes) - 1):
if _nodes[i].is_directory():
dirs.append(_nodes[i])
return dirs
def files(self):
files = []
for i in range(0, len(_nodes) - 1):
if not _nodes[i].is_directory():
files.append(_nodes[i])
return files
def nodes(self):
return self._nodes
class File(Node):
"""docstring for File"""
def __init__(self, name, content):
super(File, self).__init__(name, False)
self.__content = content
def append(self, text):
if self._owner.available_size < len(text):
raise NotEnoughSpaceError
self.__content += text
self._owner.available_size -= len(text)
def content(self):
return self.__content
def size(self):
return len(self.__content) + 1
def truncate(self, text):
if self._owner.available_size - len(self.__content) < len(text):
raise NotEnoughSpaceError
self.__content = text
###
# Exeptions:
###
class FileSystemError(BaseException):
# All exeptions inherit FileSystemError !
pass
class NodeDoesNotExistError(FileSystemError):
pass
class DestinationNodeDoesNotExistError(NodeDoesNotExistError):
pass
class SourceNodeDoesNotExistError(NodeDoesNotExistError):
pass
class NotEnoughSpaceError(FileSystemError):
pass
class DestinationNodeExistsError(FileSystemError):
pass
class DestinationNotADirectoryError(FileSystemError):
pass
# remove()
class NonExplicitDirectoryDeletionError(FileSystemError):
pass
class NonEmptyDirectoryDeletionError(FileSystemError):
pass
# link()
class DirectoryHardLinkError(FileSystemError):
pass
# mount()
class FileSystemMountError(FileSystemError):
pass
class MountPointNotEmptyError(FileSystemMountError):
pass
class MountPointNotADirectoryError(FileSystemMountError):
pass
class MountPointDoesNotExistError(FileSystemMountError):
pass
# unmount()
class NotAMountPointError(FileSystemMountError):
pass
# MY ERRORS:
class NotAValidOwnerError(FileSystemError):
pass
class AttemptingToCreateInFileError(FileSystemError):
pass