1
0
mirror of https://gitlab.com/openlp/runners.git synced 2024-12-21 19:02:48 +00:00

Add a script to upload the OpenLP version to get.openlp.org

This commit is contained in:
Raoul Snyman 2020-04-24 23:06:28 -07:00
parent 5a525e4b5f
commit 59d5ceb146
Signed by: raoul
GPG Key ID: F55BCED79626AE9C
2 changed files with 97 additions and 1 deletions

View File

@ -8,6 +8,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
python3-websockets python3-webob python3-waitress python3-requests python3-pymediainfo \
python3-qtawesome python3-opengl python3-appdirs python3-vlc python3-zeroconf python3-pip \
python3-flake8 python3-flask python3-flask-cors python3-distro flake8 mediainfo mupdf-tools xvfb \
python3-pytestqt twine
python3-pytestqt python3-paramiko twine
ADD fixpaths.py /usr/bin/fixpaths
RUN chmod a+x /usr/bin/fixpaths
ADD uploadversion.py /usr/bin/uploadversion
RUN chmod a+x /usr/bin/uploadversion

94
uploadversion.py Normal file
View File

@ -0,0 +1,94 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2020 OpenLP Developers #
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
"""
A script to get the OpenLP version from the source code and upload it to the appropriate file in
https://get.openlp.org/versions/
"""
import os
from contextlib import contextmanager
from io import StringIO
from subprocess import PIPE, CalledProcessError, run
from paramiko.client import SSHClient, AutoAddPolicy
from paramiko.rsakey import RSAKey
OPENLP_SERVER = 'openlp.io'
OPENLP_USER = 'openlp'
OPENLP_KEY = RSAKey.from_private_key(StringIO(os.environ['SSH_KEY']))
VERSIONS_DIR = '/home/{user}/sites/get.openlp.org/www/versions/'.format(user=OPENLP_USER)
def get_version():
"""Run setup.py and get the version number"""
try:
result = run(['python3', 'setup.py', '--version'], stdout=PIPE)
return result.stdout.strip().decode('utf8')
except CalledProcessError:
return '0.0.0'
def get_version_file(full_version):
"""Return the correct version file for the version"""
bits = full_version.split('.dev')
current_version = {
'full': full_version,
'version': bits[0],
'build': full_version.split('+')[1] if '+' in full_version else None
}
if current_version['build']:
return 'nightly_version.txt'
elif int(current_version['version'].split('.')[1]) % 2 != 0:
return 'dev_version.txt'
else:
return 'version.txt'
@contextmanager
def sftp_connect():
"""Create an SSH connection to the server"""
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.load_system_host_keys()
client.connect(OPENLP_SERVER, username=OPENLP_USER, pkey=OPENLP_KEY)
yield client.open_sftp()
client.close()
def write_version_file(version, version_file):
remote_filename = VERSIONS_DIR + version_file
with sftp_connect() as sftp_client:
remote_file = sftp_client.file(remote_filename, 'w')
remote_file.write(version)
def main():
"""Run the script"""
version = get_version()
print('Version: {version}'.format(version=version))
version_file = get_version_file(version)
print('Version file: {version_file}'.format(version_file=version_file))
write_version_file(version, version_file)
if __name__ == '__main__':
main()