Example #1
0
def _download_git(url, tag, dst, pkg, version):
    name = '{0}-{1}'.format(pkg, version)
    fn = name + '.tar.gz'

    if os.path.isfile(os.path.join(
            dst, fn)) and not os.path.isdir(os.path.join(dst, name)):
        return fn

    safe_rmdir(os.path.join(dst, name))

    cmd = ['git', 'clone', url, name]
    ret, out, err = call(cmd, cwd=dst)
    if ret != 0:
        raise Exception('Download git Failed: {0}'.format(url))

    cmd = ['git', 'checkout', tag]
    ret, out, err = call(cmd, cwd=os.path.join(dst, name))
    if ret != 0:
        raise Exception('Git checkout Failed: {0}'.format(url))

    safe_rmdir(os.path.join(dst, name, '.git'))

    cmd = ['tar', '-czf', fn, name]
    ret, out, err = call(cmd, cwd=dst)
    if ret != 0:
        raise Exception('Tar git repo Failed: {0}'.format(name))

    #safe_rmdir(os.path.join(dst, name))

    return fn
Example #2
0
def run(param):
    release_version = param['config_scenario']['version']

    if len(param['command']) > 1:
        destination = param['command'][1]
    else:
        destination = os.getcwd()

    destination = expand_path(destination)
    pack_dir = os.path.join(destination, 'pack_' + release_version)

    for category in param['config_package_install']:
        for subdir in param['config_package_install'][category]:
            for package in param['config_package_install'][category][subdir]:
                for version, value in param['config_package_install'][
                        category][subdir][package].items():
                    pkg_cfg = value['config_origin']

                    download = pkg_cfg.get('install', {}).get('download')
                    if not download:
                        continue

                    url = pkg_cfg.get('source', {}).get('url')
                    if not url:
                        continue

                    pkg_dir = os.path.join(pack_dir, package, version)
                    safe_mkdir(pkg_dir)

                    _logger.info('Packing {0}...'.format(package))

                    if download == 'http':
                        url = url.format(version=version)
                        pkg_file = _download_http(url, pkg_dir)
                    elif download == 'svn':
                        url = url.format(version=version)
                        pkg_file = _download_svn(url, pkg_dir, package,
                                                 version)
                    elif download == 'git':
                        tag = pkg_cfg.get('source', {}).get('tag', 'master')
                        tag = tag.format(version=version)
                        pkg_file = _download_git(url, tag, pkg_dir, package,
                                                 version)
                    else:
                        _logger.warn('Package {0} not packed'.format(package))
                        continue

                    with open(os.path.join(pkg_dir, 'md5sum.txt'), 'w') as f:
                        call(['md5sum', pkg_file], cwd=pkg_dir, stdout=f)
                    with open(os.path.join(pkg_dir, 'sha1sum.txt'), 'w') as f:
                        call(['sha1sum', pkg_file], cwd=pkg_dir, stdout=f)
                    with open(os.path.join(pkg_dir, 'url.txt'), 'w') as f:
                        f.write(url + '\n')

                    _logger.info('Package {0} packed'.format(package))

    _logger.info('All packages in version {0} packed in {1}'.format(
        release_version, pack_dir))
Example #3
0
    def execute(self, config_user, config_version, destination):
        release_version = config_version.get('version')

        try:
            config_release = ConfigRelease(config_version)
        except ConfigReleaseError:
            _logger.debug(
                'Install release definition: {0}'.format(release_version))
            install = Install(config_user, config_version)
            config_release = install.config_release()

        self.__pkg_mgr = PackageManager(config_version, config_release)

        if not destination:
            destination = os.getcwd()
        destination = expand_path(destination)
        pack_dir = os.path.join(destination, 'pack_' + release_version)

        for pkg, pkg_info in self.__pkg_mgr.package_all().items():
            version = pkg_info.get('package', {}).get('version')
            if not version:
                continue

            download = pkg_info.get('install', {}).get('download')
            if not download:
                continue

            url = download.get('param', {}).get('url')
            if not url:
                continue
            url = url.format(version=version)

            pkg_dir = os.path.join(pack_dir, pkg, version)
            safe_mkdir(pkg_dir)

            _logger.info('Packing {0}...'.format(pkg))

            if download.get('handler') == 'http':
                pkg_file = _download_http(url, pkg_dir)
            elif download.get('handler') == 'svn':
                pkg_file = _download_svn(url, pkg_dir, pkg, version)

            with open(os.path.join(pkg_dir, 'md5sum.txt'), 'w') as f:
                call(['md5sum', pkg_file], cwd=pkg_dir, stdout=f)
            with open(os.path.join(pkg_dir, 'sha1sum.txt'), 'w') as f:
                call(['sha1sum', pkg_file], cwd=pkg_dir, stdout=f)
            with open(os.path.join(pkg_dir, 'url.txt'), 'w') as f:
                f.write(url + '\n')

            _logger.info('Package {0} packed'.format(pkg))

        _logger.info('All packages in version {0} packed in {1}'.format(
            release_version, pack_dir))
Example #4
0
def _download_svn(url, dst, pkg, version):
    name = '{0}-{1}'.format(pkg, version)
    fn = name + '.tar.gz'

    if os.path.isfile(os.path.join(
            dst, fn)) and not os.path.isdir(os.path.join(dst, name)):
        return fn

    cmd = ['svn', 'export', '--force', url, name]
    ret, out, err = call(cmd, cwd=dst)
    if ret != 0:
        raise Exception('Download svn Failed: {0}'.format(url))

    cmd = ['tar', '-czf', fn, name]
    ret, out, err = call(cmd, cwd=dst)
    if ret != 0:
        raise Exception('Tar svn repo Failed: {0}'.format(name))

    safe_rmdir(os.path.join(dst, name))

    return fn
Example #5
0
def _download_http(url, dst):
    pos = url.rfind('/')
    if pos == -1:
        raise Exception('Can not find file name from url: {0}'.format(url))
    fn = url[pos + 1:]
    fntmp = fn + '.tmp'

    if os.path.isfile(os.path.join(dst, fn)):
        return fn

    cmd = ['curl', '-f', '-L', '-s', '-S', '-R', '-o', fntmp, url]
    ret, out, err = call(cmd, cwd=dst)
    if ret != 0:
        raise Exception('Download http Failed {0} "{1}": {2}'.format(
            ret, url, out))

    cmd = ['mv', fntmp, fn]
    ret, out, err = call(cmd, cwd=dst)
    if ret != 0:
        raise Exception('Rename Failed {0} "{1}": {2}'.format(ret, fn, out))

    return fn
Example #6
0
def _library_dir(env):
    lib_dir = [
        x for x in env.get('LD_LIBRARY_PATH', '').split(os.pathsep) if x
    ]

    try:
        env_new = env.copy()
        env_new['PATH'] = env['PATH'] + os.pathsep + os.pathsep.join(
            ['/sbin', '/usr/sbin', '/usr/local/sbin'])
        ret, out, err = call(['ldconfig', '-v', '-N'],
                             stderr=subprocess.PIPE,
                             env=env_new)
        for m in re.finditer('^(.*?):', out.decode(), flags=re.MULTILINE):
            lib_dir.append(m.group(1))
    except Exception as e:
        _logger.warn('Command ldconfig error: {0}'.format(e))
        lib_dir += ['/lib', '/lib64', '/usr/lib', '/usr/lib64']
    return lib_dir
Example #7
0
def _execute_shell(cmd, script):
    ret, out, err = call(cmd, stderr=subprocess.PIPE, input=script.encode())
    return out.decode()