Ejemplo n.º 1
0
def get_initrd_uri(prj, defs, arch):
    if arch == "default":
        arch = prj.text("buildimage/arch", default=defs, key="arch")
    suite = prj.text("suite")

    name = prj.text("name", default=defs, key="name")
    apt_sources = get_sources_list(prj, defs)
    apt_keys = get_key_list(prj)
    target_pkg = get_initrd_pkg(prj, defs)

    if virtapt_imported:
        try:
            v = virtapt.VirtApt(name, arch, suite, apt_sources, "", apt_keys)
        except Exception as e:
            return get_initrd_uri_nonvirtapt(apt_sources, target_pkg, arch)

        d = virtapt.apt_pkg.DepCache(v.cache)
        pkg = v.cache[target_pkg]

        c = d.get_candidate_ver(pkg)
        x = v.source.find_index(c.file_list[0][0])

        r = virtapt.apt_pkg.PackageRecords(v.cache)
        r.lookup(c.file_list[0])
        uri = x.archive_uri(r.filename)

        if not x.is_trusted:
            return "", uri

        return r.sha1_hash, uri
    else:
        return get_initrd_uri_nonvirtapt(apt_sources, target_pkg, arch)

    return "", ""
Ejemplo n.º 2
0
def get_initrd_uri(prj, defs, arch):
    if arch == "default":
        arch = prj.text("buildimage/arch", default=defs, key="arch")
    suite = prj.text("suite")

    name = prj.text("name", default=defs, key="name")
    apt_sources = get_sources_list(prj, defs)
    apt_keys = get_key_list(prj)

    target_pkg = get_initrd_pkg(prj, defs)

    if virtapt_imported:
        v = virtapt.VirtApt(name, arch, suite, apt_sources, "", apt_keys)
        d = virtapt.apt_pkg.DepCache(v.cache)

        pkg = v.cache[target_pkg]

        c = d.get_candidate_ver(pkg)
        x = v.source.find_index(c.file_list[0][0])

        r = virtapt.apt_pkg.PackageRecords(v.cache)
        r.lookup(c.file_list[0])
        uri = x.archive_uri(r.filename)

        if not x.is_trusted:
            return "", uri

        return r.sha1_hash, uri
    else:
        url = "%s://%s/%s" % (prj.text("mirror/primary_proto"),
                              prj.text("mirror/primary_host"),
                              prj.text("mirror/primary_path"))
        pkg = get_url(arch, suite, target_pkg, url)

        if pkg:
            return "", pkg

        for n in prj.node("mirror/url-list"):
            url = n.text("binary")
            urla = url.split()
            pkg = get_url(arch, suite, target_pkg,
                          urla[0].replace("BUILDHOST", "localhost"))

            if pkg:
                return "", pkg

    return "", ""
Ejemplo n.º 3
0
def get_initrd_uri(xml, defs):

    arch = xml.text("project/buildimage/arch", default=defs, key="arch")
    suite = xml.text("project/suite")

    name = xml.text("project/name")
    apt_sources = get_sources_list(xml)

    target_pkg = get_initrd_pkg(xml)

    try:
        v = virtapt.VirtApt(name, arch, suite, apt_sources, "")
        d = virtapt.apt_pkg.DepCache(v.cache)

        pkg = v.cache[target_pkg]

        c = d.get_candidate_ver(pkg)
        x = v.source.find_index(c.file_list[0][0])

        r = virtapt.apt_pkg.PackageRecords(v.cache)
        r.lookup(c.file_list[0])
        uri = x.archive_uri(r.filename)
        return uri
    except:
        url = "%s://%s/%s" % (xml.text("project/mirror/primary_proto"),
                              xml.text("project/mirror/primary_host"),
                              xml.text("project/mirror/primary_path"))
        pkg = get_url(xml, arch, suite, target_pkg, url)

        if pkg:
            return pkg

        for n in xml.node("project/mirror/url-list"):
            url = n.text("binary")
            urla = url.split()
            pkg = get_url(xml, arch, suite, target_pkg,
                          urla[0].replace("BUILDHOST", "localhost"))

            if pkg:
                return pkg

    return ""
Ejemplo n.º 4
0
def run_command(argv):

    oparser = OptionParser(
        usage="usage: %prog check_updates [options] <source-xmlfile>")
    oparser.add_option(
        "-s",
        "--script",
        dest="script",
        help="filename of script to run when an update is required")
    oparser.add_option("--skip-validation",
                       action="store_true",
                       dest="skip_validation",
                       default=False,
                       help="Skip xml schema validation")
    (opt, args) = oparser.parse_args(argv)

    if len(args) != 1:
        print "Wrong number of arguments"
        oparser.print_help()
        sys.exit(20)

    if not opt.skip_validation:
        validation = validate_xml(args[0])
        if len(validation) != 0:
            print "xml validation failed. Bailing out"
            for i in validation:
                print i
            sys.exit(20)

    print "checking %s" % args[0]

    xml = etree(args[0])

    if xml.has("project/buildtype"):
        buildtype = xml.text("/project/buildtype")
    else:
        buildtype = "nodefaults"

    defs = ElbeDefaults(buildtype)

    arch = xml.text("project/buildimage/arch", default=defs, key="arch")
    suite = xml.text("project/suite")

    name = xml.text("project/name", default=defs, key="name")

    apt_sources = xml.text("sources_list").replace("10.0.2.2", "localhost")
    apt_prefs = xml.text("apt_prefs")

    fullp = xml.node("fullpkgs")

    v = virtapt.VirtApt(name, arch, suite, apt_sources, apt_prefs)

    d = virtapt.apt_pkg.DepCache(v.cache)
    d.read_pinfile(v.projectpath + "/etc/apt/preferences")

    for p in fullp:
        pname = p.et.text
        pver = p.et.get('version')
        pauto = p.et.get('auto')

        if pauto != "true":
            d.mark_install(v.cache[pname])

    errors = 0
    required_updates = 0

    for p in fullp:
        pname = p.et.text
        pver = p.et.get('version')
        pauto = p.et.get('auto')

        if not pname in v.cache:
            if pauto == 'false':
                print pname, "does not exist in cache but is specified in pkg-list"
                errors += 1
            else:
                print pname, "is no more required"
                required_updates += 1

            continue

        centry = v.cache[pname]

        if d.marked_install(centry):
            cver = d.get_candidate_ver(v.cache[pname]).ver_str
            if pver != cver:
                print pname, "%s != %s" % (pver, cver)
                required_updates += 1

    sys.stdout.flush()
    sys.stderr.flush()
    if errors > 0:
        print errors, "Errors occured, xml files needs fixing"
        if opt.script:
            os.system("%s ERRORS %s" % (opt.script, args[0]))
    elif required_updates > 0:
        print required_updates, "updates required"
        if opt.script:
            os.system("%s UPDATE %s" % (opt.script, args[0]))
    else:
        print "No Updates available"
Ejemplo n.º 5
0
def run_command(argv):

    # pylint: disable=too-many-locals
    # pylint: disable=too-many-statements
    # pylint: disable=too-many-branches

    oparser = OptionParser(
        usage="usage: %prog check_updates [options] <source-xmlfile>")
    oparser.add_option(
        "-s",
        "--script",
        dest="script",
        help="filename of script to run when an update is required")
    oparser.add_option("--skip-validation",
                       action="store_true",
                       dest="skip_validation",
                       default=False,
                       help="Skip xml schema validation")
    oparser.add_option("-c",
                       "--changelogs",
                       dest="changelogs",
                       help="filename of changelog xml file")
    (opt, args) = oparser.parse_args(argv)

    if len(args) != 1:
        print("Wrong number of arguments")
        oparser.print_help()
        sys.exit(20)

    if not opt.skip_validation:
        validation = validate_xml(args[0])
        if validation:
            print("xml validation failed. Bailing out")
            for i in validation:
                print(i)
            sys.exit(20)

    print("checking %s" % args[0])

    xml = ElbeXML(args[0])

    fullp = xml.node("fullpkgs")

    arch = xml.text("project/buildimage/arch", key="arch")

    v = virtapt.VirtApt(xml)

    for p in fullp:
        pname = p.et.text
        pauto = p.et.get('auto')

        if pauto != "true":
            v.mark_install(pname)

    errors = 0
    required_updates = 0

    update_packages = []

    for p in fullp:
        xp = XMLPackage(p, arch)
        pname = p.et.text
        pauto = p.et.get('auto')

        if not v.has_pkg(xp.name):
            if not xp.is_auto_installed:
                print(
                    "%s does not exist in cache but is specified in pkg-list" %
                    xp.name)
                errors += 1
            else:
                print("%s is no more required" % xp.name)
                required_updates += 1

            continue

        if v.marked_install(xp.name):
            cver = v.get_candidate_ver(xp.name)
            if xp.installed_version != cver:
                print("%s: %s != %s" % (xp.name, xp.installed_version, cver))
                required_updates += 1

                if opt.changelogs:
                    v.mark_pkg_download(xp.name)
                    xp.candidate_version = cver
                    update_packages.append(xp)

    sys.stdout.flush()
    sys.stderr.flush()
    if errors > 0:
        print("%d Errors occured, xml files needs fixing" % errors)
        if opt.script:
            system("%s ERRORS %s" % (opt.script, args[0]), allow_fail=True)
    elif required_updates > 0:
        print("%d updates required" % required_updates)

        if opt.changelogs:
            build_changelog_xml(v, opt, update_packages)

        if opt.script:
            system("%s UPDATE %s" % (opt.script, args[0]), allow_fail=True)
    else:
        print("No Updates available")