Skip to content

Commit

Permalink
Deploy all - Use the current project instead of asking for the direct…
Browse files Browse the repository at this point in the history
…ory & zip paths
  • Loading branch information
mdouchin committed Mar 15, 2021
1 parent 5c94538 commit 23e9a5f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/processing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br> |
CLONE_FTP_PROTOCOL|Clone (S)FTP protocol|Enum||✓||Values: SFTP, FTP <br>|
CLONE_FTP_HOST|Clone FTP Server host|String||✓|||
CLONE_FTP_PORT|Clone FTP Server port|Number||✓||Default: 2021 <br> Type: Integer<br> Min: -1.7976931348623157e+308, Max: 1.7976931348623157e+308 <br>|
Expand Down Expand Up @@ -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/ <br> |
LOCAL_QGIS_PROJECT_FOLDER|Local desktop QGIS project folder|File||✓|||
ZIP_FILE|Database ZIP archive path|File||||Default: /tmp/central_database_package.zip <br> |
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 <br> |
CLONE_FTP_PROTOCOL|Clone (S)FTP protocol|Enum||✓||Values: SFTP, FTP <br>|
CLONE_FTP_HOST|Clone FTP Server host|String||✓|||
CLONE_FTP_PORT|Clone FTP Server port|Number||✓||Default: 2021 <br> Type: Integer<br> Min: -1.7976931348623157e+308, Max: 1.7976931348623157e+308 <br>|
Expand Down
Binary file modified docs/processing/lizsync-deploy_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/processing/lizsync-send_projects_and_files_to_clone_ftp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 33 additions & 41 deletions lizsync/processing/algorithms/deploy_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
__copyright__ = '(C) 2018 by 3liz'

import os
import tempfile

from platform import system as psys

from qgis.core import (
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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:
Expand All @@ -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]
Expand All @@ -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(
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 3 additions & 1 deletion lizsync/processing/algorithms/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 23e9a5f

Please sign in to comment.