Function to upload site in ftp or sftp

This commit is contained in:
2026-05-21 13:02:20 +02:00
committed by kitoy
parent 50829e9f60
commit 5c17b65820
142 changed files with 288 additions and 933 deletions

View File

@@ -4,6 +4,8 @@ from werkzeug.utils import secure_filename
from app.forms import *
from PIL import Image
from pathlib import Path, PurePath, PurePosixPath
from shutil import rmtree, copytree
import subprocess
class DataSite:
user_folder = None
@@ -170,12 +172,40 @@ class DataSite:
print(f"Error removing directory (might not be empty): {e}")
def writeHTML(self, pageName :str, htmlExport :str):
public_folder = Path(PurePosixPath(self.user_folder).joinpath('public'))
pageName = pageName+'.html'
page = Path(PurePosixPath(self.user_folder).joinpath('public', pageName))
page.write_text(htmlExport)
def writeHTML(self, theme:str, pageName :str, htmlExport :str):
publicFolder = Path(PurePosixPath(self.user_folder).joinpath('public'))
themesFolder = Path(PurePosixPath('app').joinpath('templates','themes', self.datas['config']['theme'],'static'))
publicStaticFolder = Path(PurePosixPath(self.user_folder).joinpath('public', 'static'))
if pageName == '/':
pageIndex = publicFolder / 'index.html'
pageIndex.write_text(htmlExport)
else:
pageFolder = Path(PurePosixPath(self.user_folder).joinpath('public', pageName))
pageFolder.mkdir(exist_ok=True)
pageIndex = pageFolder / 'index.html'
pageIndex.write_text(htmlExport)
rmtree (publicStaticFolder, ignore_errors=True)
copytree(themesFolder, publicStaticFolder)
def publish(self, user:str, password:str, serverAddress:str, serverPort:int, folder:str):
remote_directory = "/remote/dir"
userDir = Path(PurePosixPath(self.user_folder))
command = "lftp -u \"{}\",\"{}\" -p {} {} -e ' mirror -R public {}; bye;'".format(user,
password,
serverPort,
serverAddress,
folder)
print(command)
try:
subprocess.call(command, shell=True, cwd=str(userDir))
except ChildProcessError:
return False
return True
def emptyTrash(self):
for file in self.trash: