Compare commits
No commits in common. "663b5f6d372b92448d299fffe43cc16f11ad7c2a" and "55026aa62683fdc1029cb64cbd2ca344d4567272" have entirely different histories.
663b5f6d37
...
55026aa626
@ -1,64 +1,2 @@
|
|||||||
#!/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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user