bundle.py 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
# Copyright (C) 2015 GRNET S.A.
#
# 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 <http://www.gnu.org/licenses/>.
#

import os
import sys
import shutil
import json


APP = 'baas'
DISTPATH = 'dist'

OS_OPTIONS = [
    "win64",
    "osx64",
    "linux64",
    "win32",
    "osx32",
    "linux32",
]


def get_version():
    pkg_file = os.path.join('baas', 'package.json')
    with open(pkg_file) as f:
        info = json.load(f)
        return info.get('version', '')


def main():
    os.chdir(os.path.dirname(os.path.realpath(__file__)))

    if len(sys.argv) < 2 or sys.argv[1] not in OS_OPTIONS:
        print "Select one of: %s" % " ".join(OS_OPTIONS)
        exit(1)

    osarg = sys.argv[1]
    descr = "-".join(sys.argv[1:])
    version = get_version()

    os.chdir(DISTPATH)
    filename = '%s-%s-%s' % (APP, version, descr)
56 57
    if not osarg.startswith('linux'):
        base_dir = '%s.app' % APP if osarg.startswith("osx") else APP
58
        arch_name = "%s.zip" % filename
59
        os.system("/usr/bin/zip -ry %s %s" % (arch_name, base_dir))
60
    else:
61 62
        arch_type = 'gztar'
        base_dir = APP
63 64 65 66 67 68
        arch_name = shutil.make_archive(
            filename, arch_type, root_dir='.', base_dir=base_dir)
    print "Wrote %s" % os.path.join(DISTPATH, arch_name)

if __name__ == "__main__":
    main()