diff --git a/server/server.py b/server/server.py index 6101458..a938dc7 100644 --- a/server/server.py +++ b/server/server.py @@ -5,7 +5,7 @@ from executor import Executor class Server: - def __init__(self, homeDirectory: str, sessionTimeout: int = 120, availableServer: bool = True, + def __init__(self, homeDirectory: str = "", sessionTimeout: int = 120, availableServer: bool = True, currentDirectory: str = ""): self.isAuthenticated = False self.homeDirectory = homeDirectory @@ -17,11 +17,68 @@ class Server: self.currentDirectory = currentDirectory self.executor = Executor(homeDirectory) - def login(username: str, password: str) -> bool: - pass + def login(self, username: str, password: str) -> bool: + pass - def logout() -> None: - pass + def logout(self) -> None: + pass - def execute(command: str, firstParam: str, secondParam: str) -> bool: - pass + def parseCommand(self, command: str) -> str: + parsedCommand = command.split(" ") + if len(parsedCommand) > 3: + return "ERROR" + # TODO: Ez igy gecironda, ezt meg kene csinalni rendesen. + elif len(parsedCommand) == 1: + return self.execute(parsedCommand[0]) + elif len(parsedCommand) == 2: + return self.execute(parsedCommand[0], parsedCommand[1]) + elif len(parsedCommand) == 3: + return self.execute(parsedCommand[0], parsedCommand[1], parsedCommand[2]) + + def execute(self, command: str, firstParam: str = "", secondParam: str = "") -> str: + if self.homeDirectory == "" or self.currentDirectory == "" or self.executor.currentDirectory == "" or self.executor.baseDir == "": + raise Exception("Directories must not be empty string. Did the user log in?") + if command == "MKD": + if secondParam != "": + return "ERROR" + else: + return self.executor.createDirectory(firstParam) + elif command == "RMD": + if secondParam != "": + return "ERROR" + else: + return self.executor.removeDirectory(firstParam) + elif command == "GWD": + if secondParam != "" or firstParam != "": + return "ERROR" + else: + return self.executor.getCurrentDirectory() + elif command == "CWD": + if secondParam != "": + return "ERROR" + else: + return self.executor.setCurrentDirectory(firstParam) + elif command == "LST": + if secondParam != "" or firstParam != "": + return "ERROR" + else: + return self.executor.listCurrentDirectoryContent() + elif command == "RMF": + if secondParam != "": + return "ERROR" + else: + return self.executor.removeFileInCurrentDirectory(firstParam) + elif command == "UPL": + if secondParam != "": + return "ERROR" + else: + # TODO + pass + elif command == "DNL": + if secondParam != "": + return "ERROR" + else: + # TODO + pass + else: + return "ERROR"