Test for MKD / RMD works like a charm
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DESKTOP-DPA61F8\Benedek 2021-04-26 14:40:32 +02:00
parent 3e0afb0d45
commit b08da25d21
3 changed files with 13 additions and 6 deletions

View File

@ -76,6 +76,7 @@ class Authetication:
shutil.rmtree(self.HOME_DIRECTORY_LOCATION) shutil.rmtree(self.HOME_DIRECTORY_LOCATION)
os.mkdir(self.HOME_DIRECTORY_LOCATION) os.mkdir(self.HOME_DIRECTORY_LOCATION)
os.mkdir(self.HOME_DIRECTORY_LOCATION + os.path.sep + '0')
shutil.rmtree(self.PRIVATE_KEY_DIRECTORY_LOCATION) shutil.rmtree(self.PRIVATE_KEY_DIRECTORY_LOCATION)
os.mkdir(self.PRIVATE_KEY_DIRECTORY_LOCATION) os.mkdir(self.PRIVATE_KEY_DIRECTORY_LOCATION)

View File

@ -2,17 +2,23 @@
import os import os
import re import re
import sys
class Executor: class Executor:
"""This class executes commands recieved by the server""" """This class executes commands recieved by the server"""
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
BASE_PATH = ABSOLUTE_PATH + os.path.sep + 'home' + os.path.sep
DEFAULT_FOLDER = BASE_PATH + '0'
def __init__(self, currentDiectory: str, baseDir: str = ""): def __init__(self, currentDiectory: str, baseDir: str = ""):
self.currentDirectory = currentDiectory self.currentDirectory = currentDiectory
if baseDir == "": if baseDir == "":
self.baseDir = self.currentDirectory self.baseDir = self.DEFAULT_FOLDER
else: else:
self.baseDir = baseDir self.baseDir = self.BASE_PATH + baseDir + os.path.sep
def sanitizeDirectory(self, inDirectory: str) -> str: def sanitizeDirectory(self, inDirectory: str) -> str:
return re.sub('[^a-zA-Z0-9]', '', inDirectory) return re.sub('[^a-zA-Z0-9]', '', inDirectory)
@ -22,13 +28,13 @@ class Executor:
def createDirectory(self, dirName: str) -> str: def createDirectory(self, dirName: str) -> str:
dirName = self.sanitizeDirectory(dirName) dirName = self.sanitizeDirectory(dirName)
actualDirName = os.path.join(self.currentDirectory, dirName) actualDirName: str = os.path.join(self.baseDir,self.currentDirectory,dirName)
os.mkdir(actualDirName) os.mkdir(actualDirName)
return actualDirName return actualDirName
def removeDirectory(self, dirName: str) -> str: def removeDirectory(self, dirName: str) -> str:
dirName = self.sanitizeDirectory(dirName) dirName = self.sanitizeDirectory(dirName)
actualDirName = os.path.join(self.currentDirectory, dirName) actualDirName: str = os.path.join(self.baseDir, self.currentDirectory, dirName)
if actualDirName: if actualDirName:
os.rmdir(actualDirName) os.rmdir(actualDirName)
return actualDirName return actualDirName

View File

@ -21,13 +21,13 @@ class Server:
def login(self, homeDir: str) -> None: def login(self, homeDir: str) -> None:
self.isAuthenticated = True self.isAuthenticated = True
self.executor.baseDir = Executor(homeDir) self.executor = Executor("", homeDir)
def logout(self) -> None: def logout(self) -> None:
self.networkInstance.logout() self.networkInstance.logout()
self.isAuthenticated = False self.isAuthenticated = False
self.availableServer = False self.availableServer = False
self.executor.baseDir = Executor("") self.executor = Executor("")
def parseCommand(self, command: str) -> None: def parseCommand(self, command: str) -> None:
if command == "LINOK": if command == "LINOK":