diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e01a0e0..8dd7e0d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ before_script: stages: - test -# - release + - release tests: stage: test @@ -14,16 +14,14 @@ tests: - "nosetests --with-xunit tests/unittests/" - "sonar-runner" -#releases: -# stage: release -# script: -# - "python scripts/create_release_script.py" -# - "cd source" -# - "python release.py sdist" -# - "cd .." -# - "scripts/deploy_release.sh" -# only: -# - /^[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$/ -# except: -# - branches +releases: + stage: release + script: + - "python scripts/create_release_script.py" + - "python setup.py sdist" + - "scripts/deploy_release.sh" + only: + - /^[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$/ + except: + - branches diff --git a/gate_guard.service b/gate_guard.service new file mode 100644 index 0000000..ed53bc8 --- /dev/null +++ b/gate_guard.service @@ -0,0 +1,10 @@ +[Unit] +Description=Chickenhouse gate guard service +After=multi-user.target + +[Service] +Type=idle +ExecStart=/usr/bin/python /usr/local/lib/python2.7/dist-packages/gate_guard/__init__.py + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/gate_guard/gate.py b/gate_guard/gate.py index a89e145..cbe7588 100644 --- a/gate_guard/gate.py +++ b/gate_guard/gate.py @@ -9,7 +9,6 @@ import data_buffer import light_sensor import engine import power_sensor -from numpy.core.umath import power STATE_INIT = "init" STATE_OPENED = "open" diff --git a/scripts/create_release_script.py b/scripts/create_release_script.py new file mode 100755 index 0000000..5f1d2c5 --- /dev/null +++ b/scripts/create_release_script.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +''' +Created on Mar 13, 2017 + +@author: tkl +''' +import os +import sys + +DAEMON_START_SCRIPT_SRC = 'gate_guard.service' +DAEMON_START_SCRIPT_DST = '/lib/systemd/system/' + DAEMON_START_SCRIPT_SRC + +def main(argv): + project_version = '' + project_name = '' + project_namespace = '' + if os.environ.has_key('CI_BUILD_TAG'): + project_version = str(os.environ.get('CI_BUILD_TAG')).strip() +# else: +# return -1 + + if os.environ.has_key('CI_PROJECT_NAME'): + project_name = str(os.environ.get('CI_PROJECT_NAME')).strip() +# else: +# return -1 + + if os.environ.has_key('CI_PROJECT_NAMESPACE'): + project_namespace = str(os.environ.get('CI_PROJECT_NAMESPACE')).strip() +# else: +# return -1 + + setup_str = ' setup(name=\'' + project_name + '\', ' + setup_str += 'version=\'' + project_version + '\', ' + setup_str += 'author=\'tkl\', ' + setup_str += 'author_email=\'tkl@blackfinn.de\', ' + setup_str += 'url=\'https://files.blackfinn.de/' + project_namespace + \ + '/' + project_name + '\', ' + setup_str += 'packages=[\'gate_guard\']' + setup_str_sdist = setup_str + ', scripts=[\'' + DAEMON_START_SCRIPT_SRC + '\'])\n' + setup_str += ')\n' + + handle = open('setup.py', 'w') + handle.write('#!/usr/bin/env python\n') + handle.write('from distutils.core import setup\n') + handle.write('import shutil\n') + handle.write('import os\n') + handle.write('import stat\n') + handle.write('import sys\n\n') + handle.write('if sys.argv[1] == \'install\':\n') + handle.write(' shutil.copyfile(\'' + DAEMON_START_SCRIPT_SRC + \ + '\', \'' + DAEMON_START_SCRIPT_DST + '\')\n') + handle.write(' os.chmod(\'' + DAEMON_START_SCRIPT_DST + \ + '\', stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)\n') + handle.write(setup_str) + handle.write('elif sys.argv[1] == \'sdist\':\n') + handle.write(setup_str_sdist) + handle.write('\n') + + handle.close() + + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) + diff --git a/scripts/deploy_release.sh b/scripts/deploy_release.sh new file mode 100755 index 0000000..33c9737 --- /dev/null +++ b/scripts/deploy_release.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -x + +if [ -z ${CI_BUILD_TAG+x} ]; then + echo "Tag name not found" + exit 1; +fi +if [ -z ${CI_PROJECT_NAME+x} ]; then + echo "Project name not found" + exit 1; +fi + +delim="-" +file_ext=".tar.gz" +file=$CI_PROJECT_NAME$delim$CI_BUILD_TAG$file_ext +current_dir=`pwd` +release_dir="/dist/" +release_file=$current_dir$release_dir$file + +smbclient //proxy/files 4738tax -U tkl -c "mkdir python ; cd python ; mkdir $CI_PROJECT_NAME ; cd $CI_PROJECT_NAME ; put $release_file $file" diff --git a/scripts/pylint_wrapper.py b/scripts/pylint_wrapper.py old mode 100644 new mode 100755 index a92c426..3ee413a --- a/scripts/pylint_wrapper.py +++ b/scripts/pylint_wrapper.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python ''' Created on Feb 11, 2017