File indexing completed on 2024-04-14 05:31:56

0001 #!/usr/bin/env python
0002 
0003 
0004 #  SPDX-FileCopyrightText: 2018 Klaralvdalens Datakonsult AB a KDAB Group company info@kdab.com
0005 #  SPDX-License-Identifier: LGPL-2.0-or-later
0006 
0007 
0008 # This is my quick and dirty script to generate clazy app images on each release
0009 # Requires iamsergio/clazy-centos68 docker image to work
0010 
0011 import sys, os
0012 
0013 CLAZY_SHA1 = ''
0014 WORK_FOLDER = '/tmp/clazy_work/'
0015 DOCKER_IMAGE = 'iamsergio/clazy-centos68'
0016 DEST_FILE = WORK_FOLDER + '/Clazy-x86_64.AppImage'
0017 
0018 def print_usage():
0019     print(sys.argv[0] + ' <clazy sha1>')
0020 
0021 def run_command(cmd, abort_on_error = True):
0022     print(cmd)
0023     success = (os.system(cmd) == 0)
0024     if abort_on_error and not success:
0025         sys.exit(1)
0026 
0027     return success
0028 
0029 def prepare_folder():
0030     run_command('rm -rf ' + WORK_FOLDER)
0031     os.mkdir(WORK_FOLDER)
0032 
0033 def make_appimage_in_docker():
0034     cmd = 'docker run -i -t -v %s:%s %s %s' % (WORK_FOLDER, WORK_FOLDER, DOCKER_IMAGE, 'bash -c "cd /clazy/ && git pull && /clazy/dev-scripts/docker/make_appimage.sh %s %s"' % (CLAZY_SHA1, str(os.getuid())))
0035     if not run_command(cmd):
0036         print('Error running docker. Make sure docker is running and that you have ' + DOCKER_IMAGE)
0037 
0038     os.environ['ARCH'] = 'x86_64'
0039     if not run_command('appimagetool-x86_64.AppImage %s/clazy.AppDir/ %s' % (WORK_FOLDER, DEST_FILE)):
0040         return False
0041 
0042     return True
0043 
0044 
0045 def clazy_source_directory():
0046     return os.path.dirname(os.path.realpath(__file__)) + '/../'
0047 
0048 def run_tests():
0049     os.chdir(clazy_source_directory() + '/tests/')
0050     os.environ['CLAZY_CXX'] = '/tmp/clazy_work//Clazy-x86_64.AppImage'
0051     os.environ['CLAZYSTANDALONE_CXX'] = '/tmp/clazy_work//Clazy-x86_64.AppImage --standalone'
0052     return run_command("./run_tests.py --verbose")
0053 
0054 
0055 if len(sys.argv) != 2:
0056     print_usage();
0057     sys.exit(1)
0058 
0059 
0060 CLAZY_SHA1 = sys.argv[1]
0061 
0062 prepare_folder()
0063 
0064 if not make_appimage_in_docker():
0065     sys.exit(1)
0066 
0067 if not run_tests():
0068     sys.exit(1)
0069 
0070 print('')
0071 run_command('sha1sum ' + DEST_FILE)
0072 run_command('sha256sum ' + DEST_FILE)
0073 
0074 sign_script = os.getenv('CLAZY_SIGN_SCRIPT', '')
0075 
0076 if sign_script:
0077     os.chdir(WORK_FOLDER)
0078     if not run_command(sign_script + ' ' + DEST_FILE):
0079         print('Error signing file')
0080         sys.exit(1)
0081 
0082 print('')
0083 print('Success: ' + DEST_FILE)