Пример #1
0
def run(param):
    format_dict = {}
    format_dict.update(param['package_path'])
    format_dict.update(param['config_package'].get('path', {}))

    cwd = param['action_param'].get('cwd', '{main_dir}').format(**format_dict)

    cmd = param['action_param']['cmd']
    if not isinstance(cmd[0], list):
        cmd = [cmd]

    env = param.get('env')
    env_cmd = env.copy()
    for k, v in param['action_param'].get('env', {}).items():
        env_cmd[k] = v.format(**format_dict)

    ret = 0
    with open(param['log_file'], 'w') as f:
        for c in cmd:
            ret = call_and_log(c, log=f, cwd=cwd, env=env)
            if ret != 0:
                return {
                    'success':
                    False,
                    'message':
                    'Command "{0}" failed with exit code: {0}'.format(c, ret)
                }

    return {
        'success': ret == 0,
        'message': 'Command exit code: {0}'.format(ret)
    }
Пример #2
0
def run(param):
    version = param['version']

    tar_filename = param['config_package']['source']['file'].format(
        version=version)
    tar_file = os.path.join(param['package_path']['misc_dir'], 'download',
                            tar_filename)
    main_dir = param['config_package']['source'].get(
        'main', '').format(version=version)

    dst_dir = param['config_package'].get('path', {}).get('source')
    if not dst_dir:
        return {'success': False, 'message': 'Path "source" is not specified'}

    safe_rmdir(dst_dir)
    safe_mkdir(dst_dir)

    if main_dir:
        strip_number = main_dir.strip(os.sep).count(os.sep) + 1
        cmd = [
            'tar', '--strip-components',
            str(strip_number), '-xvf', tar_file, main_dir
        ]
    else:
        cmd = ['tar', '-xvf', tar_file]

    with open(param['log_file'], 'w') as f:
        ret = call_and_log(cmd, log=f, cwd=dst_dir)

    return {'success': ret == 0, 'message': 'Tar exit code: {0}'.format(ret)}
Пример #3
0
def run(param):
    package_dir = param['pkg_info']['dir']['package']
    cwd = param['action_param'].get('cwd', package_dir)

    cmd = param['action_param']['cmd']
    if not isinstance(cmd[0], list):
        cmd = [cmd]

    env = param.get('env')
    env_cmd = env.copy()
    for k, v in param['action_param'].get('env', {}).items():
        env_cmd[k] = v.format(**param['pkg_dir_list'])

    ret = 0
    with open(param['log_file'], 'w') as f:
        for c in cmd:
            ret = call_and_log(c, log=f, cwd=package_dir, env=env)
            if ret != 0:
                return {
                    'success':
                    False,
                    'message':
                    'Command "{0}" failed with exit code: {0}'.format(c, ret)
                }

    return {
        'success': ret == 0,
        'message': 'Command exit code: {0}'.format(ret)
    }
Пример #4
0
def run(param):
    build_dir = param['config_package'].get('path', {}).get('build')
    if not build_dir:
        return {'success': False, 'message': 'Path "build" is not specified'}

    install_dir = param['config_package'].get('path', {}).get('install')
    if not install_dir:
        return {'success': False, 'message': 'Path "install" is not specified'}

    safe_mkdir(install_dir)

    install_args = param['config_package'].get('make_install',
                                               {}).get('args', ['install'])
    install_args = ensure_list(install_args)

    env = param.get('env')
    env_install = env.copy()
    for k, v in param['config_package'].get('make_install',
                                            {}).get('env', {}).items():
        env_install[k] = v.format(**param['config_package'].get('path', {}))

    with open(param['log_file'], 'w') as f:
        cmd = ['make'] + install_args
        ret = call_and_log(cmd, log=f, cwd=build_dir, env=env_install)

    return {
        'success': ret == 0,
        'message': 'Make install exit code: {0}'.format(ret)
    }
Пример #5
0
def run(param):
    version = param['version']

    url = param['config_package']['source']['url'].format(version=version)
    filename = param['config_package']['source']['file'].format(
        version=version)
    md5url = param['config_package']['source'].get('md5url',
                                                   '').format(version=version)
    dst_dir = os.path.join(param['package_path']['misc_dir'], 'download')

    safe_rmdir(dst_dir)
    safe_mkdir(dst_dir)

    with open(param['log_file'], 'w') as f:
        cmd = ['curl', '-v', '-f', '-L', '-s', '-S', '-R', '-O', url]
        ret = call_and_log(cmd, log=f, cwd=dst_dir)
        if ret != 0:
            return {
                'success': False,
                'message':
                'File download error, CURL exit code: {0}'.format(ret)
            }

        if md5url:
            cmd = [
                'curl', '-v', '-f', '-L', '-s', '-S', '-R', '-o', 'md5sum.txt',
                md5url
            ]
            ret = call_and_log(cmd, log=f, cwd=dst_dir)
            if ret != 0:
                return {
                    'success':
                    False,
                    'message':
                    'md5sum download error, CURL exit code: {0}'.format(ret)
                }

            cmd = ['md5sum', '-c', 'md5sum.txt']
            ret = call_and_log(cmd, log=f, cwd=dst_dir)
            if ret != 0:
                return {
                    'success': False,
                    'message': 'md5 checksum error: {0}'.format(ret)
                }

    return {'success': ret == 0, 'message': 'CURL exit code: {0}'.format(ret)}
Пример #6
0
def run(param):
    version = param['version']
    url = param['config_package']['source']['url']
    tag = param['config_package']['source'].get('tag',
                                                '').format(version=version)
    keep_dotgit = param['config_package']['source'].get('keep_dotgit', False)
    branch = param['config_package']['source'].get('branch', 'develop')

    if not tag:
        return {'success': False, 'message': 'Git tag is not specified'}

    source_dir = param['config_package'].get('path', {}).get('source')
    if not source_dir:
        return {'success': False, 'message': 'Path "source" is not specified'}

    safe_rmdir(source_dir)
    safe_mkdir(source_dir)

    with open(param['log_file'], 'w') as f:
        cmd = ['git', 'clone', url, source_dir]
        ret = call_and_log(cmd, log=f)
        if ret != 0:
            return {
                'success': False,
                'message': 'Git clone exit code: {0}'.format(ret)
            }

        cmd = ['git', 'checkout', tag, '-b', branch]
        ret = call_and_log(cmd, log=f, cwd=source_dir)
        if ret != 0:
            return {
                'success': False,
                'message': 'Git checkout tag exit code: {0}'.format(ret)
            }

    if not keep_dotgit:
        safe_rmdir(os.path.join(source_dir, '.git'))

    return {'success': ret == 0, 'message': 'Git OK'}
Пример #7
0
def run(param):
    version = param['version']
    url = param['config_package']['source']['url'].format(version=version)

    source_dir = param['config_package'].get('path', {}).get('source')
    if not source_dir:
        return {'success': False, 'message': 'Path "source" is not specified'}

    safe_rmdir(source_dir)
    safe_mkdir(source_dir)

    cmd = ['svn', 'export', '--force', url, source_dir]
    with open(param['log_file'], 'w') as f:
        ret = call_and_log(cmd, log=f)

    return {'success': ret == 0, 'message': 'Svn exit code: {0}'.format(ret)}
Пример #8
0
def run(param):
    patch_filename = param['config_package'].get('patch', '')
    if not patch_filename:
        return {'success': False, 'message': 'Patch file not specified'}

    patch_file = os.path.join(param['config_release_path']['content_dir'],
                              'patch', patch_filename)
    if not os.path.isfile(patch_file):
        return {'success': False, 'message': 'Patch file does not exist'}

    source_dir = param['config_package'].get('path', {}).get('source')
    if not source_dir:
        return {'success': False, 'message': 'Path "source" is not specified'}

    cmd = ['patch', '-p1', '-i', patch_file]

    with open(param['log_file'], 'w') as f:
        ret = call_and_log(cmd, log=f, cwd=source_dir)

    return {'success': ret == 0, 'message': 'Patch exit code: {0}'.format(ret)}
Пример #9
0
def run(param):
    build_dir = param['config_package'].get('path', {}).get('build')
    if not build_dir:
        return {'success': False, 'message': 'Path "build" is not specified'}

    env = param.get('env')
    env_make = env.copy()
    for k, v in param['config_package'].get('make', {}).get('env', {}).items():
        env_make[k] = v

    if 'jobs' in param['config_package'].get('make', {}):
        jobs = param['config_package']['make']['jobs']
    else:
        jobs = param['config_attribute'].get('make_jobs', 1)
    make_opt = ['-j{0}'.format(jobs)]

    with open(param['log_file'], 'w') as f:
        cmd = ['make'] + make_opt
        ret = call_and_log(cmd, log=f, cwd=build_dir, env=env_make)

    return {'success': ret == 0, 'message': 'Make exit code: {0}'.format(ret)}
Пример #10
0
def run(param):
    source_dir = param['config_package'].get('path', {}).get('source')
    if not source_dir:
        return {'success': False, 'message': 'Path "source" is not specified'}

    build_dir = param['config_package'].get('path', {}).get('build')
    if not build_dir:
        return {'success': False, 'message': 'Path "build" is not specified'}

    install_dir = param['config_package'].get('path', {}).get('install')
    if not install_dir:
        return {'success': False, 'message': 'Path "install" is not specified'}


    if source_dir != build_dir:
        safe_rmdir(build_dir)
    safe_mkdir(build_dir)


    cmake_args = param['config_package'].get('cmake', {}).get('args', [])
    cmake_args = ensure_list(cmake_args)
    cmake_args = [p.format(**param['config_package_install_path']) for p in cmake_args]

    if not param['config_package'].get('cmake', {}).get('ignore_install_prefix', False):
        cmake_args.insert(0, '-DCMAKE_INSTALL_PREFIX='+install_dir)

    cmake_var = param['config_package'].get('cmake', {}).get('var', {})
    for k, v in cmake_var.items():
        full_value = v.format(**param['config_package_install_path'])
        full_arg = '-D{0}={1}'.format(k, full_value)
        cmake_args.append(full_arg)


    env = param.get('env')

    with open(param['log_file'], 'w') as f:
        cmd = ['cmake', source_dir] + cmake_args
        ret = call_and_log(cmd, log=f, cwd=build_dir, env=env)

    return {'success': ret==0, 'message': 'CMake exit code: {0}'.format(ret)}
Пример #11
0
def run(param):
    source_dir = param['config_package'].get('path', {}).get('source')
    if not source_dir:
        return {'success': False, 'message': 'Path "source" is not specified'}

    build_dir = param['config_package'].get('path', {}).get('build')
    if not build_dir:
        return {'success': False, 'message': 'Path "build" is not specified'}

    install_dir = param['config_package'].get('path', {}).get('install')
    if not install_dir:
        return {'success': False, 'message': 'Path "install" is not specified'}


    if source_dir != build_dir:
        safe_rmdir(build_dir)
    safe_mkdir(build_dir)


    configure_args = param['config_package'].get('configure', {}).get('args', [])
    configure_args = ensure_list(configure_args)
    configure_args = [p.format(**param['config_package_install_path']) for p in configure_args]

    if not param['config_package'].get('configure', {}).get('ignore_install_prefix', False):
        configure_args.insert(0, '--prefix='+install_dir)

    env = param.get('env')
    env_configure = env.copy()
    for k, v in param['config_package'].get('configure', {}).get('env', {}).items():
        env_configure[k] = v.format(**param['config_package_install_path'])

    configure_path = os.path.join(source_dir, 'configure')


    with open(param['log_file'], 'w') as f:
        cmd = [configure_path] + configure_args
        ret = call_and_log(cmd, log=f, cwd=build_dir, env=env_configure)

    return {'success': ret==0, 'message': 'Configure exit code: {0}'.format(ret)}
Пример #12
0
def _single_command(cmd, f, env):
    try:
        call_and_log(cmd, log=f, env=env)
    except Exception as e:
        f.write('Command error: {0}'.format(e))
        f.flush()