class FileNode: def __init__(self, filename, depth=0): """This function initializes our FileNode Args: filename (string): The filename of the current node. depth (int, optional): The depth of the current node,. Defaults to 0. """ self.filename = filename self.depth = depth # Hint: It is best to implement the subdirectory into a dictionary with keys being the filename and the values being the actual object FileNode. self.subdirectories = {} def __delete__(self): """This function overrides the default deletion of the current object and also deletes the subdirectories""" for v in self.subdirectories.values(): del v self.subdirectories.clear() def insert(self, filename, path, depth): """This function inserts the file into a specific path. If the path does not exist, then the folder is not created. Args: filename (string): The filename of the current folder to be inserted path (lists of string): The path of the filename depth (int): The depth of the node to be inserted. """ # Part A. Implement the insertion of a new file here. If the given path does not exist, then you may skip the file. def print_dir(self): """This prints the current directory and accesses the subdirectories as well.""" # Part B. Implement the printing of the directory here. # You should access subdirectories first before moving to the next folder within the same directory. #### Do not modify this object #### class FileSystem: def __init__(self, root_dir): """This is the FileSystem implementation. A root node is required once an instance is created Args: root_dir (string): Filename of the root node for the file system. """ self.root = FileNode(root_dir) def __delete__(self): """Deletes the filesystem by deleting the root and deleting the subdirectories automatically due to the override function.""" del self.root def insert(self, filename, path): """Inserts a new file with the given path starting from the root node. Args: filename (string): The filename of the folder to be inserted. path (string): The path of the folder to be inserted """ self.root.insert(filename, path, 1) def print_system(self): """Prints the directory in the given format""" self.root.print_dir() if __name__ == "__main__": root_dir = input() n = int(input()) filenames = [] for i in range(n): # Part C. Implement parsing of input lines. pass #### DO NOT MODIFY BELOW #### fs = FileSystem(root_dir) for f, p in filenames: fs.insert(f, p) fs.print_system()
class FileNode: def __init__(self, filename, depth=0): """This function initializes our FileNode Args: filename (string): The filename of the current node. depth (int, optional): The depth of the current node,. Defaults to 0. """ self.filename = filename self.depth = depth # Hint: It is best to implement the subdirectory into a dictionary with keys being the filename and the values being the actual object FileNode. self.subdirectories = {} def __delete__(self): """This function overrides the default deletion of the current object and also deletes the subdirectories""" for v in self.subdirectories.values(): del v self.subdirectories.clear() def insert(self, filename, path, depth): """This function inserts the file into a specific path. If the path does not exist, then the folder is not created. Args: filename (string): The filename of the current folder to be inserted path (lists of string): The path of the filename depth (int): The depth of the node to be inserted. """ # Part A. Implement the insertion of a new file here. If the given path does not exist, then you may skip the file. def print_dir(self): """This prints the current directory and accesses the subdirectories as well.""" # Part B. Implement the printing of the directory here. # You should access subdirectories first before moving to the next folder within the same directory. #### Do not modify this object #### class FileSystem: def __init__(self, root_dir): """This is the FileSystem implementation. A root node is required once an instance is created Args: root_dir (string): Filename of the root node for the file system. """ self.root = FileNode(root_dir) def __delete__(self): """Deletes the filesystem by deleting the root and deleting the subdirectories automatically due to the override function.""" del self.root def insert(self, filename, path): """Inserts a new file with the given path starting from the root node. Args: filename (string): The filename of the folder to be inserted. path (string): The path of the folder to be inserted """ self.root.insert(filename, path, 1) def print_system(self): """Prints the directory in the given format""" self.root.print_dir() if __name__ == "__main__": root_dir = input() n = int(input()) filenames = [] for i in range(n): # Part C. Implement parsing of input lines. pass #### DO NOT MODIFY BELOW #### fs = FileSystem(root_dir) for f, p in filenames: fs.insert(f, p) fs.print_system()
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
will give thumbs up if correct!
PYTHON Activity
(see pic)
Code for COPY (Template):
class FileNode:
def __init__(self, filename, depth=0):
"""This function initializes our FileNode
Args:
filename (string): The filename of the current node.
depth (int, optional): The depth of the current node,. Defaults to 0.
"""
self.filename = filename
self.depth = depth
# Hint: It is best to implement the subdirectory into a dictionary with keys being the filename and the values being the actual object FileNode.
self.subdirectories = {}
def __delete__(self):
"""This function overrides the default deletion of the current object and also deletes the subdirectories"""
for v in self.subdirectories.values():
del v
self.subdirectories.clear()
def insert(self, filename, path, depth):
"""This function inserts the file into a specific path.
If the path does not exist, then the folder is not created.
Args:
filename (string): The filename of the current folder to be inserted
path (lists of string): The path of the filename
depth (int): The depth of the node to be inserted.
"""
# Part A. Implement the insertion of a new file here. If the given path does not exist, then you may skip the file.
def print_dir(self):
"""This prints the current directory and accesses the subdirectories as well."""
# Part B. Implement the printing of the directory here.
# You should access subdirectories first before moving to the next folder within the same directory.
#### Do not modify this object ####
class FileSystem:
def __init__(self, root_dir):
"""This is the FileSystem implementation. A root node is required once an instance is created
Args:
root_dir (string): Filename of the root node for the file system.
"""
self.root = FileNode(root_dir)
def __delete__(self):
"""Deletes the filesystem by deleting the root and deleting the subdirectories automatically due to the override function."""
del self.root
def insert(self, filename, path):
"""Inserts a new file with the given path starting from the root node.
Args:
filename (string): The filename of the folder to be inserted.
path (string): The path of the folder to be inserted
"""
self.root.insert(filename, path, 1)
def print_system(self):
"""Prints the directory in the given format"""
self.root.print_dir()
if __name__ == "__main__":
root_dir = input()
n = int(input())
filenames = []
for i in range(n):
# Part C. Implement parsing of input lines.
pass
#### DO NOT MODIFY BELOW ####
fs = FileSystem(root_dir)
for f, p in filenames:
fs.insert(f, p)
fs.print_system()
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education