Add test login to sftp/ftp repository
This commit is contained in:
@@ -127,6 +127,11 @@ class DataSite:
|
|||||||
self.datas['blocs']= blocs
|
self.datas['blocs']= blocs
|
||||||
self.filej.write_text(json.dumps(self.datas, indent=5))
|
self.filej.write_text(json.dumps(self.datas, indent=5))
|
||||||
|
|
||||||
|
def save_server_info(self, serverInfos=dict()):
|
||||||
|
self.datas['publish'] = serverInfos
|
||||||
|
self.filej.write_text(json.dumps(self.datas, indent=5))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_theme(self):
|
def get_theme(self):
|
||||||
return self.datas['config']['theme']
|
return self.datas['config']['theme']
|
||||||
@@ -197,15 +202,30 @@ class DataSite:
|
|||||||
copytree(themesStaticFolder, publicStaticFolder)
|
copytree(themesStaticFolder, publicStaticFolder)
|
||||||
|
|
||||||
|
|
||||||
def publish(self, user:str, password:str, serverAddress:str, serverPort:int, folder:str):
|
def test_server_login(self, serverInfos: dict(), password:str()):
|
||||||
remote_directory = "/remote/dir"
|
|
||||||
|
test_connect = "lftp -u \"{}\",\"{}\" -p {} {} -e 'ls; bye;'".format(serverInfos['username'],
|
||||||
|
password,
|
||||||
|
serverInfos['Port'],
|
||||||
|
serverInfos['Address'])
|
||||||
|
test_login = subprocess.check_output(test_connect, shell=True, stderr=subprocess.STDOUT)
|
||||||
|
if "Login incorrect" in str(test_login) :
|
||||||
|
print ("Mauvais login")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def publish(self, serverInfos=dict(), password=str()):
|
||||||
userDir = Path(PurePosixPath(self.user_folder))
|
userDir = Path(PurePosixPath(self.user_folder))
|
||||||
|
|
||||||
command = "lftp -u \"{}\",\"{}\" -p {} {} -e ' mirror -R public {}; chmod -R o+rx ./; bye;'".format(user,
|
|
||||||
|
command = "lftp -u \"{}\",\"{}\" -p {} {} -e ' mirror -R public {}; chmod -R o+rx ./; bye;'".format(serverInfos['username'],
|
||||||
password,
|
password,
|
||||||
serverPort,
|
serverInfos['Port'],
|
||||||
serverAddress,
|
serverInfos['Address'],
|
||||||
folder)
|
serverInfos['folder'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(command, shell=True, cwd=str(userDir))
|
subprocess.call(command, shell=True, cwd=str(userDir))
|
||||||
except ChildProcessError:
|
except ChildProcessError:
|
||||||
@@ -213,15 +233,6 @@ class DataSite:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def emptyTrash(self):
|
|
||||||
for file in self.trash:
|
|
||||||
try:
|
|
||||||
remove(self.static_path+'img/portfolio/fullsize/'+file)
|
|
||||||
except FileNotFoundError:
|
|
||||||
print (f'Le fichier {file} n\'existe pas')
|
|
||||||
if path.exists((self.static_path+'img/portfolio/thumbnails/'+file)):
|
|
||||||
remove(self.static_path+'img/portfolio/thumbnails/'+file)
|
|
||||||
self.trash.clear()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user