66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
|
#!/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:]))
|
||
|
|