Ejemplo n.º 1
0
def depend_cmp(what, on, depend_map):
    if depends(what, on, depend_map):
        return 1
    elif depends(on, what, depend_map):
        return -1
    else:
        return uBuild.compare_versions(what, on)
Ejemplo n.º 2
0
def _getNewestPackages(rv, build, packages, filt=None):
    for pkg in packages:
        platform = pkg.package.platform
        if not rv.has_key(platform):
            rv[platform] = {}
        ctype = pkg.package.ctype
        if not rv[platform].has_key(pkg.package.ctype):
            rv[platform][ctype] = {}
        name = pkg.package.name
        if not (rv[platform][ctype].has_key(
                pkg.package.name)) or (uBuild.compare_versions(
                    rv[platform][ctype][name].version, pkg.version) <= 0):
            pkg.tarball_location = None if not build else build.find_valid_tarball(
                pkg)
            if pkg.tarball_location:
                pkg.tarball_location = os.path.realpath(pkg.tarball_location)
            if filt is None or (pkg.package.ctype, pkg.package.name) in filt:
                rv[platform][ctype][name] = pkg
Ejemplo n.º 3
0
def findPackageByPlatform(con, platform, name, ctype):
    platforms = uPEM.getPlatformLine(con, platform)
    cur = con.cursor()
    if _mn_plesk_root is None:
        cur.execute("SELECT default_rootpath FROM hosts WHERE host_id = 1")
        init(None, cur.fetchone()[0])

    cur.execute((
        "SELECT p.pkg_id, p.version FROM packages p WHERE name = %%s AND ctype = %%s AND platform_id IN (%s)"
        % ','.join(['%s'] * len(platforms))),
                [name, ctype] + [p.platform_id for p in platforms])
    pkgs = cur.fetchall()
    rv = None
    for p in pkgs:
        if rv is None or uBuild.compare_versions(p[1], rv[1]) > 0:
            rv = p
    if rv is None:
        raise PackageNotFound(name, ctype, platform)
    return rv
Ejemplo n.º 4
0
def getLatestPackageId(pform_id, pkg):
    """
    Returns pkg_id for the latest version of package pkg for the specified platform
    :param platform_id: id of target platform
    :param pkg: a (ctype, name) structure
    :return: pkg_id
    """
    con = uSysDB.connect()
    cur = con.cursor()
    ctype, name = pkg
    cur.execute(
        "SELECT pkg_id, version FROM packages WHERE platform_id = %s AND ctype = %s AND name = %s",
        pform_id, ctype, name)
    rv = None
    for row in cur.fetchall():
        pkg_id, version = row[0], row[1]
        if rv is None or uBuild.compare_versions(version, rv[1]) > 0:
            rv = pkg_id, version

    if rv is not None or pform_id == 1:
        return rv
    cur.execute("SELECT parent_id FROM platforms WHERE platform_id = %s",
                pform_id)
    return getLatestPackageId(cur.fetchone()[0], pkg)
Ejemplo n.º 5
0
 def compareVersions(v1, v2):
     return uBuild.compare_versions(v1, v2)
Ejemplo n.º 6
0
def _getMaxHelmPackage(helm_packages):
    return sorted(
        helm_packages,
        cmp=lambda x, y: uBuild.compare_versions(x.version, y.version),
        reverse=True)[:1][0]
Ejemplo n.º 7
0
def getPkgsToInstall(con, host_id, upgrade_instructions, newestPackages):
    cur = con.cursor()

    cur.execute(
        "SELECT p.name, p.ctype, p.pkg_id, p.version FROM packages p JOIN components c ON (c.pkg_id = p.pkg_id) WHERE c.host_id = %s ORDER BY c.component_id",
        host_id)
    installed_packages = {}
    installed_packages_sorted = []  # For storing order of installed packages
    installed_pkg_ids = set()
    for row in cur.fetchall():
        installed_packages[(row[0], row[1])] = row[3]
        installed_packages_sorted.append((row[0], row[1]))
        installed_pkg_ids.update([row[2]])

    to_install = []

    unicode_regexp = re.compile("(u'|')")
    if upgrade_instructions is not None:
        to_install_set = set()
        for pkg in upgrade_instructions.packages:
            # do not attempt to upgrade scs:
            name, ctype = pkg
            if (ctype == 'sc') and pkg in installed_packages:
                continue
            if pkg in upgrade_instructions.disabled_packages:
                uLogging.info('Not auto-installing %s-%s, it is disabled',
                              ctype, name)
                continue
            for where in upgrade_instructions.packages[pkg]:
                if where and where in installed_packages:
                    uLogging.debug(
                        unicode_regexp.sub(
                            "", 'Going to upgrade %s because %s is installed' %
                            (pkg, where)))
                    to_install_set.update([pkg])
        # Create list of packages to install in correct order
        # First, add all already installed packages
        for pkg in installed_packages_sorted:
            if pkg in to_install_set:
                to_install.append(pkg)
        # Second, add new packages
        for pkg in to_install_set:
            if pkg not in installed_packages:
                to_install.append(pkg)
    else:
        to_install = [x for x in installed_packages_sorted]

    platform, rootpath = uPEM.getHostInfo(con, host_id)
    platforms_list = uPEM.getPlatformLine(con, platform)
    non_single = []
    single = []
    libs = []
    for pkg in to_install:
        name, ctype = pkg

        found = False
        for ok_pl in platforms_list:
            if newestPackages.has_key(ok_pl) and newestPackages[ok_pl].has_key(
                    ctype) and newestPackages[ok_pl][ctype].has_key(name):
                found = True
                package = newestPackages[ok_pl][ctype][name]
                if hasattr(package, "pkg_id"):
                    name = package.package.name
                    ctype = package.package.ctype
                    if installed_packages.has_key((name, ctype)):
                        installed_version = installed_packages[(name, ctype)]
                        vc = uBuild.compare_versions(installed_version,
                                                     package.version)
                        if vc >= 0:
                            uLogging.info(
                                "%s version %s of %s-%s is already installed",
                                vc and 'Higher' or 'Same', installed_version,
                                ctype, name)
                            continue

                    if ctype == 'other' and name.startswith('lib'):
                        libs.append(package)
                    elif package.package.is_single:
                        single.append(package)
                    else:
                        non_single.append(package)
                    uLogging.info("Will upgrade %s", package)
                else:
                    uLogging.err("No pkg id for package %s", package)
                break
        if not found and upgrade_instructions:
            uLogging.warn(
                unicode_regexp.sub(
                    "", 'Cannot find package %s for platform %s' %
                    (pkg, platform)))
    return libs + single + non_single