1#!/usr/bin/env python
2
3
4#  This file is part of the clazy static checker.
5
6#  Copyright (C) 2018 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
7
8#  This library is free software; you can redistribute it and/or
9#  modify it under the terms of the GNU Library General Public
10#  License as published by the Free Software Foundation; either
11#  version 2 of the License, or (at your option) any later version.
12
13#  This library is distributed in the hope that it will be useful,
14#  but WITHOUT ANY WARRANTY; without even the implied warranty of
15#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16#  Library General Public License for more details.
17
18#  You should have received a copy of the GNU Library General Public License
19#  along with this library; see the file COPYING.LIB.  If not, write to
20#  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21#  Boston, MA 02110-1301, USA.
22
23
24# This is my quick and dirty script to generate clazy app images on each release
25# Requires iamsergio/clazy-centos68 docker image to work
26
27import sys, os, getpass
28
29CLAZY_SHA1 = ''
30WORK_FOLDER = '/tmp/clazy_work/'
31DOCKER_IMAGE = 'iamsergio/clazy-centos68'
32DEST_FILE = WORK_FOLDER + '/Clazy-x86_64.AppImage'
33
34def print_usage():
35    print sys.argv[0] + ' <clazy sha1>'
36
37def run_command(cmd, abort_on_error = True):
38    print cmd
39    success = (os.system(cmd) == 0)
40    if abort_on_error and not success:
41        sys.exit(1)
42
43    return success
44
45def prepare_folder():
46    run_command('rm -rf ' + WORK_FOLDER)
47    os.mkdir(WORK_FOLDER)
48
49def make_appimage_in_docker():
50    cmd = 'docker run -i -t -v %s:%s %s %s' % (WORK_FOLDER, WORK_FOLDER, DOCKER_IMAGE, 'bash -c "/clazy/dev-scripts/docker/make_appimage.sh %s %s"' % (CLAZY_SHA1, str(os.getuid())))
51    if not run_command(cmd):
52        print 'Error running docker. Make sure docker is running and that you have ' + DOCKER_IMAGE
53
54    os.environ['ARCH'] = 'x86_64'
55    if not run_command('appimagetool-x86_64.AppImage %s/clazy.AppDir/ %s' % (WORK_FOLDER, DEST_FILE)):
56        return False
57
58    return True
59
60
61def clazy_source_directory():
62    return os.path.dirname(os.path.realpath(__file__)) + '/../'
63
64def run_tests():
65    os.chdir(clazy_source_directory() + '/tests/')
66    os.environ['CLAZY_CXX'] = '/tmp/clazy_work//Clazy-x86_64.AppImage'
67    os.environ['CLAZYSTANDALONE_CXX'] = '/tmp/clazy_work//Clazy-x86_64.AppImage --standalone'
68    return run_command("./run_tests.py --verbose")
69
70
71if len(sys.argv) != 2:
72    print_usage();
73    sys.exit(1)
74
75
76CLAZY_SHA1 = sys.argv[1]
77
78prepare_folder()
79
80if not make_appimage_in_docker():
81    sys.exit(1)
82
83if not run_tests():
84    sys.exit(1)
85
86print ''
87run_command('sha1sum ' + DEST_FILE)
88run_command('sha256sum ' + DEST_FILE)
89
90sign_script = os.getenv('CLAZY_SIGN_SCRIPT', '')
91
92if sign_script:
93    os.chdir(WORK_FOLDER)
94    if not run_command(sign_script + ' ' + DEST_FILE):
95        print 'Error signing file'
96        sys.exit(1)
97
98print ''
99print 'Success: ' + DEST_FILE
100