-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_system.py
41 lines (28 loc) · 1.03 KB
/
file_system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import exceptions
from directory import Directory
from file import File
class FileSystem:
def __init__(self, size):
self.size = size
self.available_size = size - 1
self.__nodes = {'/': None}
def get_node(self, path):
if path not in self.__nodes:
raise exceptions.NodeDoesNotExistError
return self.__nodes[path]
# Не очакваме случая: directory=True и len(content) > 0
def create(self, path, directory=False, content=''):
if path[:path.rfind('/') + 1] not in self.__nodes:
raise exceptions.DestinationNodeDoesNotExistError
node_size = len(content) + 1
if node_size > self.available_size:
raise exceptions.NotEnoughSpaceError
if path in self.__nodes:
raise exceptions.DestinationNodeExistError
if directory:
self.__nodes[path] = Directory()
else:
self.__nodes[path] = File(content)
self.available_size -= node_size
fs = File(20)
print(fs.size)