|
@@ -0,0 +1,58 @@
|
|
|
|
|
+import os, argparse, re
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def solve_task(lines):
|
|
|
|
|
+ current_path = "/"
|
|
|
|
|
+ file_system = FolderNode()
|
|
|
|
|
+ for line in lines:
|
|
|
|
|
+ m = re.match("$ cd (.+)", line)
|
|
|
|
|
+ if (m):
|
|
|
|
|
+ # cd command
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ m = re.match("(\d+) (.+)", line)
|
|
|
|
|
+ if (m):
|
|
|
|
|
+ # file entry
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+class Node:
|
|
|
|
|
+ def __init__(self, parent):
|
|
|
|
|
+ if parent:
|
|
|
|
|
+ self.parent = parent
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.parent = self
|
|
|
|
|
+
|
|
|
|
|
+class FileNode(Node):
|
|
|
|
|
+ def __init__(self, parent):
|
|
|
|
|
+ super().__init__(parent)
|
|
|
|
|
+
|
|
|
|
|
+class FolderNode(Node):
|
|
|
|
|
+ def __init__(self, parent = None):
|
|
|
|
|
+ super().__init__(parent)
|
|
|
|
|
+ self.children = []
|
|
|
|
|
+
|
|
|
|
|
+ def add(self, file, destinationFolder):
|
|
|
|
|
+ destinationFolder.split('/', 1)
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+def read_lines(filename):
|
|
|
|
|
+ lines = []
|
|
|
|
|
+ with open(filename) as infile:
|
|
|
|
|
+ for raw_line in infile:
|
|
|
|
|
+ line = raw_line.rstrip()
|
|
|
|
|
+ lines.append(line)
|
|
|
|
|
+ return lines
|
|
|
|
|
+
|
|
|
|
|
+def parse_arguments():
|
|
|
|
|
+ parser = argparse.ArgumentParser(description="Script that solves the case",epilog="Have a nice day!")
|
|
|
|
|
+ parser.add_argument('filename', nargs='?', default="example.txt", help='Input file')
|
|
|
|
|
+ args = parser.parse_args()
|
|
|
|
|
+ return args
|
|
|
|
|
+
|
|
|
|
|
+def main():
|
|
|
|
|
+ args = parse_arguments()
|
|
|
|
|
+ lines = read_lines(args.filename)
|
|
|
|
|
+ solve_task(lines)
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
|
+ main()
|