diff --git a/CHANGELOG.md b/CHANGELOG.md index b827320..550ddb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.5.1 - 2021-03-15 +* Deploy all - Use the current project instead of asking for the directory & zip paths * Fix SFTP sync & PostgreSQL dump algorithms in Windows context * Add the Synchronize database button in the main tab of the dock diff --git a/docs/processing/README.md b/docs/processing/README.md index fed1bb7..5c01394 100644 --- a/docs/processing/README.md +++ b/docs/processing/README.md @@ -56,6 +56,7 @@ OUTPUT_STRING|Output message|String|| | ID | Description | Type | Info | Required | Advanced | Option | |:-:|:-:|:-:|:-:|:-:|:-:|:-:| LOCAL_QGIS_PROJECT_FOLDER|Local desktop QGIS project folder|File||✓||| +WINSCP_BINARY_PATH|WinSCP binary path|File|||✓|Default: /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/lizsync/install/WinSCP
| CLONE_FTP_PROTOCOL|Clone (S)FTP protocol|Enum||✓||Values: SFTP, FTP
| CLONE_FTP_HOST|Clone FTP Server host|String||✓||| CLONE_FTP_PORT|Clone FTP Server port|Number||✓||Default: 2021
Type: Integer
Min: -1.7976931348623157e+308, Max: 1.7976931348623157e+308
| @@ -189,9 +190,8 @@ OUTPUT_STRING|Output message|String|| CONNECTION_NAME_CENTRAL|PostgreSQL connection to the central database|String|The PostgreSQL connection to the central database.|✓||| CONNECTION_NAME_CLONE|PostgreSQL connection to the clone database|String|The PostgreSQL connection to the clone database.|✓||| POSTGRESQL_BINARY_PATH|PostgreSQL binary path|File||✓|✓|Default: /usr/bin/
| -LOCAL_QGIS_PROJECT_FOLDER|Local desktop QGIS project folder|File||✓||| -ZIP_FILE|Database ZIP archive path|File||||Default: /tmp/central_database_package.zip
| RECREATE_CLONE_SERVER_ID|Recreate clone server id. Do it only to fully reset the clone ID !|Boolean||✓|✓|| +WINSCP_BINARY_PATH|WinSCP binary path|File|||✓|Default: /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/lizsync/install/WinSCP
| CLONE_FTP_PROTOCOL|Clone (S)FTP protocol|Enum||✓||Values: SFTP, FTP
| CLONE_FTP_HOST|Clone FTP Server host|String||✓||| CLONE_FTP_PORT|Clone FTP Server port|Number||✓||Default: 2021
Type: Integer
Min: -1.7976931348623157e+308, Max: 1.7976931348623157e+308
| diff --git a/docs/processing/lizsync-deploy_all.png b/docs/processing/lizsync-deploy_all.png index 15b086f..e9eaf59 100644 Binary files a/docs/processing/lizsync-deploy_all.png and b/docs/processing/lizsync-deploy_all.png differ diff --git a/docs/processing/lizsync-send_projects_and_files_to_clone_ftp.png b/docs/processing/lizsync-send_projects_and_files_to_clone_ftp.png index 9c32421..f4782e5 100644 Binary files a/docs/processing/lizsync-send_projects_and_files_to_clone_ftp.png and b/docs/processing/lizsync-send_projects_and_files_to_clone_ftp.png differ diff --git a/lizsync/processing/algorithms/deploy_all.py b/lizsync/processing/algorithms/deploy_all.py index c80a73b..de9bc47 100644 --- a/lizsync/processing/algorithms/deploy_all.py +++ b/lizsync/processing/algorithms/deploy_all.py @@ -14,7 +14,7 @@ __copyright__ = '(C) 2018 by 3liz' import os -import tempfile + from platform import system as psys from qgis.core import ( @@ -50,9 +50,7 @@ class DeployAll(BaseProcessingAlgorithm): CONNECTION_NAME_CLONE = 'CONNECTION_NAME_CLONE' POSTGRESQL_BINARY_PATH = 'POSTGRESQL_BINARY_PATH' - LOCAL_QGIS_PROJECT_FOLDER = 'LOCAL_QGIS_PROJECT_FOLDER' RECREATE_CLONE_SERVER_ID = 'RECREATE_CLONE_SERVER_ID' - ZIP_FILE = 'ZIP_FILE' WINSCP_BINARY_PATH = 'WINSCP_BINARY_PATH' CLONE_FTP_PROTOCOL = 'CLONE_FTP_PROTOCOL' @@ -174,34 +172,6 @@ def initAlgorithm(self, config): param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) - # Local directory containing the files to send to the clone by FTP - local_qgis_project_folder = ls.variable('local/qgis_project_folder') - param =QgsProcessingParameterFile( - self.LOCAL_QGIS_PROJECT_FOLDER, - tr('Local desktop QGIS project folder'), - defaultValue=local_qgis_project_folder, - behavior=QgsProcessingParameterFile.Folder, - optional=False - ) - self.addParameter(param) - - # Database ZIP archive file - database_archive_file = ls.variable('general/database_archive_file') - if not database_archive_file: - database_archive_file = os.path.join( - tempfile.gettempdir(), - 'central_database_package.zip' - ) - param = QgsProcessingParameterFile( - self.ZIP_FILE, - tr('Database ZIP archive path'), - defaultValue=database_archive_file, - behavior=QgsProcessingParameterFile.File, - optional=True, - extension='zip' - ) - self.addParameter(param) - # Recreate clone server id param = QgsProcessingParameterBoolean( self.RECREATE_CLONE_SERVER_ID, @@ -250,6 +220,8 @@ def initAlgorithm(self, config): # port clone_ftp_port = ls.variable('ftp:clone/port') + if not clone_ftp_port: + clone_ftp_port = '8022' param = QgsProcessingParameterNumber( self.CLONE_FTP_PORT, tr('Clone FTP Server port'), @@ -278,6 +250,8 @@ def initAlgorithm(self, config): # remote directory clone_ftp_remote_dir = ls.variable('ftp:clone/remote_directory') + if not clone_ftp_remote_dir: + clone_ftp_remote_dir = 'storage/downloads/qgis/' param = QgsProcessingParameterString( self.CLONE_FTP_REMOTE_DIR, tr('Clone FTP Server remote directory'), @@ -314,6 +288,24 @@ def initAlgorithm(self, config): def checkParameterValues(self, parameters, context): + # Check current project has a file + path = context.project().absoluteFilePath() + if not path: + msg = tr('You must save the current project before running this algorithm') + return False, msg + + # Check the current project has been exported + project = context.project() + project_directory = project.absolutePath() + output_directory = project_directory + '/' + project.baseName() + '_mobile' + if not os.path.isdir(output_directory): + msg = tr( + 'The current project has not been exported to a mobile version.' + ' You need to use the algorithm "Package project and data from the central server"' + ' (Procesing algorithm id: lizync.package_all)' + ) + return False, msg + # Check FTP binary status, msg = checkFtpBinary() if not status: @@ -334,16 +326,9 @@ def checkParameterValues(self, parameters, context): return False, tr('The needed PostgreSQL binaries cannot be found in the specified path') # Check zip archive path - database_archive_file = self.parameterAsString(parameters, self.ZIP_FILE, context) + database_archive_file = os.path.join(output_directory, 'lizsync.zip') if not os.path.exists(database_archive_file): - database_archive_file = os.path.join( - tempfile.gettempdir(), - 'central_database_package.zip' - ) - ok = os.path.exists(database_archive_file) - if not ok: return False, tr("The ZIP archive does not exists in the specified path") + ": {0}".format(database_archive_file) - parameters[self.ZIP_FILE] = database_archive_file # Check connections connection_name_central = parameters[self.CONNECTION_NAME_CENTRAL] @@ -368,12 +353,18 @@ def processAlgorithm(self, parameters, context, feedback): self.OUTPUT_STRING: msg } + # Get current project needed information + project = context.project() + project_directory = project.absolutePath() + output_directory = project_directory + '/' + project.baseName() + '_mobile' + # Deploy database server package + database_archive_file = os.path.join(output_directory, 'lizsync.zip') params = { 'CONNECTION_NAME_CENTRAL': parameters[self.CONNECTION_NAME_CENTRAL], 'CONNECTION_NAME_CLONE': parameters[self.CONNECTION_NAME_CLONE], 'POSTGRESQL_BINARY_PATH': parameters[self.POSTGRESQL_BINARY_PATH], - 'ZIP_FILE': parameters[self.ZIP_FILE], + 'ZIP_FILE': database_archive_file, 'RECREATE_CLONE_SERVER_ID': parameters[self.RECREATE_CLONE_SERVER_ID], } processing.run( @@ -404,7 +395,8 @@ def processAlgorithm(self, parameters, context, feedback): # Send projects and files to clone FTP params = { - 'LOCAL_QGIS_PROJECT_FOLDER': parameters[self.LOCAL_QGIS_PROJECT_FOLDER], + 'LOCAL_QGIS_PROJECT_FOLDER': project_directory, + 'WINSCP_BINARY_PATH': parameters[self.WINSCP_BINARY_PATH], 'CLONE_FTP_PROTOCOL': parameters[self.CLONE_FTP_PROTOCOL], 'CLONE_FTP_HOST': parameters[self.CLONE_FTP_HOST], 'CLONE_FTP_PORT': parameters[self.CLONE_FTP_PORT], diff --git a/lizsync/processing/algorithms/tools.py b/lizsync/processing/algorithms/tools.py index cc69ba4..f3a4630 100644 --- a/lizsync/processing/algorithms/tools.py +++ b/lizsync/processing/algorithms/tools.py @@ -343,8 +343,10 @@ def run_command(cmd, myenv, feedback): env=myenv, universal_newlines=True, encoding='utf8', - text=True, + # not available in old versios of Python 3 + # text=True, ) + stdout = [] while proc.poll() is None: for line in proc.stdout: