Compare commits

...

2 Commits

Author SHA1 Message Date
663b5f6d37
Merge branch 'master' of ssh://git.kmlabz.com:2222/BiztProtoBois/server
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-18 15:25:41 +02:00
e6d36fa1fd
executor almost done 2021-04-18 15:24:31 +02:00

View File

@ -1,2 +1,64 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import re
class Executor:
"""This class executes commands recieved by the server"""
def __init__(self, currentDiectory: str, baseDir: str = ""):
self.currentDirectory = currentDiectory
if baseDir == "":
self.baseDir = self.currentDirectory
else:
self.baseDir = baseDir
def sanitizeDirectory(self, inDirectory: str) -> str:
return re.sub('[^a-zA-Z0-9]', '', inDirectory)
def sanitizeFile(self, inFile: str) -> str:
return re.sub('[^a-zA-Z0-9].[^a-zA-Z0-9]', '', inFile)
def createDirectory(self, dirName: str) -> str:
dirName = self.sanitizeDirectory(dirName)
actualDirName = self.currentDirectory + "/" + dirName
os.mkdir(actualDirName)
return actualDirName
def removeDirectory(self, dirName: str) -> str:
dirName = self.sanitizeDirectory(dirName)
actualDirName = self.currentDirectory + "/" + dirName
os.rmdir(actualDirName)
return actualDirName
def getCurrentDirectory(self) -> str:
return self.currentDirectory
def setCurrentDirectory(self, dirName: str) -> str:
# TODO : Navigate up a directory structure
dirName = self.sanitizeDirectory(dirName)
self.currentDirectory = self.currentDirectory + "/" + dirName
return self.currentDirectory
def listCurrentDirectoryContent(self) -> str:
contents = os.listdir(self.currentDirectory)
strdirectory = ""
for content in contents:
strdirectory += content + ", "
strdirectory = strdirectory[:-1]
return strdirectory
def putFileInCurrentDirectory(self, filename: str, content) -> str:
pass
def getFileInCurrentDirectory(self, file: str):
file = self.sanitizeFile(file)
currentfile = self.currentDirectory + file
return open(currentfile, "r")
def removeFileInCurrentDirectory(self, file: str) -> str:
file = self.sanitizeFile(file)
currentfile = self.currentDirectory + file
os.remove(currentfile)
return currentfile