Пример #1
0
    def __init__(
            self,
            fname,
            buildtype=None,
            skip_validate=False,
            url_validation=ValidationMode.NO_CHECK):
        if not skip_validate:
            validation = validate_xml(fname)
            if validation:
                raise ValidationError(validation)

        self.xml = etree(fname)
        self.prj = self.xml.node("/project")
        self.tgt = self.xml.node("/target")

        if buildtype:
            pass
        elif self.xml.has("project/buildtype"):
            buildtype = self.xml.text("/project/buildtype")
        else:
            buildtype = "nodefaults"
        self.defs = ElbeDefaults(buildtype)

        if not skip_validate and url_validation != ValidationMode.NO_CHECK:
            self.validate_apt_sources(url_validation, buildtype)
Пример #2
0
def run_command(argv):
    oparser = OptionParser(usage="usage: %prog validate <xmlfile>")
    oparser.add_option("--validate-urls", dest="validate_urls",
                       help="try to access specified repositories",
                       default=False, action="store_true")

    (opt, args) = oparser.parse_args(argv)

    if len(args) < 1:
        oparser.print_help()
        sys.exit(20)

    if not os.path.exists(args[0]):
        print("%s - file not found" % args[0])
        oparser.print_help()
        sys.exit(20)

    validation = validate_xml(args[0])
    if validation:
        print("validation failed")
        for i in validation:
            print(i)
        sys.exit(20)

    if opt.validate_urls:
        try:
            ElbeXML(args[0], url_validation=ValidationMode.CHECK_ALL)
        except ValidationError as e:
            print(e)
            sys.exit(20)

    sys.exit(0)
Пример #3
0
    def __init__(
            self,
            fname,
            buildtype=None,
            skip_validate=False,
            url_validation=ValidationMode.NO_CHECK):
        if not skip_validate:
            validation = validate_xml(fname)
            if validation:
                raise ValidationError(validation)

        self.xml = etree(fname)
        self.prj = self.xml.node("/project")
        self.tgt = self.xml.node("/target")

        if buildtype:
            pass
        elif self.xml.has("project/buildtype"):
            buildtype = self.xml.text("/project/buildtype")
        else:
            buildtype = "nodefaults"
        self.defs = ElbeDefaults(buildtype)

        if not skip_validate and url_validation != ValidationMode.NO_CHECK:
            self.validate_apt_sources(url_validation, buildtype)
def run_command(argv):
    oparser = OptionParser(usage="usage: %prog validate <xmlfile>")
    oparser.add_option("--validate-urls",
                       dest="validate_urls",
                       help="try to access specified repositories",
                       default=False,
                       action="store_true")

    (opt, args) = oparser.parse_args(argv)

    if len(args) < 1:
        oparser.print_help()
        sys.exit(20)

    if not os.path.exists(args[0]):
        print("%s - file not found" % args[0])
        oparser.print_help()
        sys.exit(20)

    validation = validate_xml(args[0])
    if validation:
        print("validation failed")
        for i in validation:
            print(i)
        sys.exit(20)

    if opt.validate_urls:
        try:
            ElbeXML(args[0], url_validation=ValidationMode.CHECK_ALL)
        except ValidationError as e:
            print(e)
            sys.exit(20)

    sys.exit(0)
Пример #5
0
def run_command(argv):

    oparser = OptionParser(
        usage="usage: %prog pin_versions [options] <xmlfile>")
    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 validation:
            print("xml validation failed. Bailing out")
            for i in validation:
                print(i)
            sys.exit(20)

    try:
        xml = etree(args[0])
    except BaseException:
        print("Error reading xml file!")
        sys.exit(20)

    if not xml.has("fullpkgs"):
        print("xml file does not have fullpkgs node")
        sys.exit(20)

    plist = xml.ensure_child("/target/pkg-list")
    plist.clear()

    fullp = xml.node("fullpkgs")

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

        pak = plist.append('pkg')
        pak.set_text(pname)
        pak.et.tail = '\n'
        pak.et.set('version', pver)

    try:
        xml.write(args[0])
    except BaseException:
        print("Unable to write new xml file")
        sys.exit(20)
Пример #6
0
def run_command(argv):

    oparser = OptionParser(
        usage="usage: %prog pin_versions [options] <xmlfile>")
    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 validation:
            print("xml validation failed. Bailing out")
            for i in validation:
                print(i)
            sys.exit(20)

    try:
        xml = etree(args[0])
    except BaseException:
        print("Error reading xml file!")
        sys.exit(20)

    if not xml.has("fullpkgs"):
        print("xml file does not have fullpkgs node")
        sys.exit(20)

    plist = xml.ensure_child("/target/pkg-list")
    plist.clear()

    fullp = xml.node("fullpkgs")

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

        pak = plist.append('pkg')
        pak.set_text(pname)
        pak.et.tail = '\n'
        pak.et.set('version', pver)

    try:
        xml.write(args[0])
    except BaseException:
        print("Unable to write new xml file")
        sys.exit(20)
Пример #7
0
def run_command( argv ):
    oparser = OptionParser( usage="usage: %prog validate <xmlfile>")
    (opt,args) = oparser.parse_args(argv)

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

    validation = validate_xml (args[0])
    if len (validation) == 0:
        sys.exit (0)
    else:
        print "validation failed"
        for i in validation:
            print i
        sys.exit(20)
Пример #8
0
    def __init__(self, fname, buildtype=None, skip_validate=False, skip_urlcheck=False):
        if not skip_validate:
            validation = validate_xml (fname)
            if len (validation) != 0:
                raise ValidationError (validation)

        self.xml = etree( fname )
        self.prj = self.xml.node("/project")
        self.tgt = self.xml.node("/target")

        if buildtype:
            pass
        elif self.xml.has( "project/buildtype" ):
            buildtype = self.xml.text( "/project/buildtype" )
        else:
            buildtype = "nodefaults"
        self.defs = ElbeDefaults(buildtype)

        if not skip_validate and not skip_urlcheck:
                self.validate_apt_sources ()
Пример #9
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:
        if not validate_xml(args[0]):
            print "xml validation failed. Bailing out"
            sys.exit(20)

    print "checking %s" % args[0]

    xml = etree(args[0])

    arch = xml.text("project/buildimage/arch")
    suite = xml.text("project/suite")

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

    apt_sources = xml.text("sources_list")
    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

    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"
Пример #10
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"
Пример #11
0
def run_command(argv):
    oparser = OptionParser(usage="usage: %prog show [options] <filename>")

    oparser.add_option("--verbose",
                       action="store_true",
                       dest="verbose",
                       default=False,
                       help="show detailed project informations")

    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) == 0:
        print "No Filename specified"
        oparser.print_help()
        sys.exit(20)

    if len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

    try:
        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)

        xml = etree(args[0])
    except:
        print "Unable to open xml File. Bailing out"
        sys.exit(20)

    if not xml.has("./project"):
        print "no project description available"
        sys.exit(20)

    print '== %s ==' % (args[0])
    print 'Debian suite: %s' % (xml.text("./project/suite"))
    for s in xml.text("./project/description").splitlines():
        print '%s' % s.strip()
    if opt.verbose:
        print 'root password: %s' % xml.text("./target/passwd")
        print 'primary_mirror: %s://%s%s' % (
            xml.text("./project/mirror/primary_proto"),
            xml.text("./project/mirror/primary_host"),
            xml.text("./project/mirror/primary_path"))
        if xml.has("./project/mirror/url-list"):
            print 'additional mirrors:'
            for url in xml.node("./project/mirror/url-list"):
                if url.has("binary"):
                    print '    deb %s' % url.text("binary").strip()
                if url.has("source"):
                    print '    deb-src %s' % url.text("source").strip()
        print 'packages:'
        for pkg in xml.node("./target/pkg-list"):
            print '    %s' % pkg.et.text
        print 'skip package validation: %s' % xml.has("./project/noauth")
        print 'archive embedded?        %s' % xml.has("./archive")
Пример #12
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 init [options] <filename>")

    oparser.add_option("--skip-validation",
                       action="store_true",
                       dest="skip_validation",
                       default=False,
                       help="Skip xml schema validation")

    oparser.add_option("--directory",
                       dest="directory",
                       default="./build",
                       help="Working directory (default is build)",
                       metavar="FILE")

    oparser.add_option(
        "--cdrom",
        dest="cdrom",
        help="Use FILE as cdrom iso, and use that to build the initvm",
        metavar="FILE")

    oparser.add_option("--proxy", dest="proxy", help="Override the http Proxy")

    oparser.add_option("--buildtype",
                       dest="buildtype",
                       help="Override the buildtype")

    oparser.add_option(
        "--debug",
        dest="debug",
        action="store_true",
        default=False,
        help="start qemu in graphical mode to enable console switch")

    oparser.add_option(
        "--devel",
        dest="devel",
        action="store_true",
        default=False,
        help="use devel mode, and install current builddir inside initvm")

    oparser.add_option(
        "--nesting",
        dest="nesting",
        action="store_true",
        default=False,
        help="allow initvm to support nested kvm. "
        "This makes /proc/cpuinfo inside initvm differ per host.")

    oparser.add_option(
        "--skip-build-bin",
        action="store_false",
        dest="build_bin",
        default=True,
        help="Skip building Binary Repository CDROM, for exact Reproduction")

    oparser.add_option("--skip-build-sources",
                       action="store_false",
                       dest="build_sources",
                       default=True,
                       help="Skip building Source CDROM")

    (opt, args) = oparser.parse_args(argv)

    if not args:
        print("no filename specified")
        oparser.print_help()
        sys.exit(20)
    elif len(args) > 1:
        print("too many filenames specified")
        oparser.print_help()
        sys.exit(20)

    if opt.devel:
        if not os.path.isdir(os.path.join(elbe_dir, "elbepack")):
            print("Devel Mode only valid, when running from elbe checkout")
            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)

    xml = etree(args[0])

    if not xml.has("initvm"):
        print("fatal error: xml missing mandatory section 'initvm'")
        sys.exit(20)

    if opt.buildtype:
        buildtype = opt.buildtype
    elif xml.has("initvm/buildtype"):
        buildtype = xml.text("/initvm/buildtype")
    else:
        buildtype = "nodefaults"

    defs = ElbeDefaults(buildtype)

    http_proxy = ""
    if os.getenv("http_proxy"):
        http_proxy = os.getenv("http_proxy")
    elif opt.proxy:
        http_proxy = opt.proxy
    elif xml.has("initvm/mirror/primary_proxy"):
        http_proxy = xml.text("initvm/mirror/primary_proxy")
        http_proxy = http_proxy.strip().replace("LOCALMACHINE", "localhost")

    if opt.cdrom:
        mirror = xml.node("initvm/mirror")
        mirror.clear()
        cdrom = mirror.ensure_child("cdrom")
        cdrom.set_text(os.path.abspath(opt.cdrom))

    # this is a workaround for
    # http://lists.linutronix.de/pipermail/elbe-devel/2017-July/000541.html
    _, virt = command_out(
        'test -x /usr/bin/systemd-detect-virt && /usr/bin/systemd-detect-virt')
    _, dist = command_out('lsb_release -cs')

    if 'vmware' in virt and 'stretch' in dist:
        machine_type = 'pc-i440fx-2.6'
    else:
        machine_type = 'pc'

    try:
        os.makedirs(opt.directory)
    except OSError as e:
        print("unable to create project directory: %s (%s)" %
              (opt.directory, e.strerror))
        sys.exit(30)

    out_path = os.path.join(opt.directory, ".elbe-in")
    try:
        os.makedirs(out_path)
    except OSError as e:
        print("unable to create subdirectory: %s (%s)" %
              (out_path, e.strerror))
        sys.exit(30)

    d = {
        "elbe_version": elbe_version,
        "defs": defs,
        "opt": opt,
        "xml": xml,
        "prj": xml.node("/initvm"),
        "http_proxy": http_proxy,
        "pkgs": xml.node("/initvm/pkg-list") or [],
        "preseed": get_initvm_preseed(xml),
        "machine_type": machine_type,
        "cfg": cfg
    }

    if http_proxy != "":
        os.putenv("http_proxy", http_proxy)
        os.putenv("https_proxy", http_proxy)
        os.putenv("no_proxy", "localhost,127.0.0.1")

    try:
        copy_kinitrd(xml.node("/initvm"), out_path)
    except NoKinitrdException as e:
        print("Failure to download kernel/initrd debian Package:")
        print("")
        print(e.message)
        print("")
        print("Check Mirror configuration")
        if 'SHA256SUMS' in e.message:
            print(
                "If you use debmirror please read https://github.com/Linutronix/elbe/issues/188 "
                "on how to work around the issue")
        sys.exit(20)

    templates = os.listdir(init_template_dir)

    make_executable = ["init-elbe.sh.mako", "preseed.cfg.mako"]

    for t in templates:
        o = t.replace(".mako", "")

        if t == "Makefile.mako" or t == "libvirt.xml.mako":
            write_template(os.path.join(opt.directory, o),
                           os.path.join(init_template_dir, t),
                           d,
                           linebreak=True)
        else:
            write_template(os.path.join(out_path, o),
                           os.path.join(init_template_dir, t),
                           d,
                           linebreak=False)

        if t in make_executable:
            os.chmod(os.path.join(out_path, o), 0o755)

    shutil.copyfile(args[0], os.path.join(out_path, "source.xml"))

    if opt.cdrom:
        os.system('7z x -o%s "%s" elbe-keyring.gpg' % (out_path, opt.cdrom))

    if opt.devel:
        out_real = os.path.realpath(out_path)
        ignore = ''
        if out_real.startswith(elbe_dir + os.sep):
            ignore = '--exclude "%s"' % os.path.relpath(out_path,
                                                        start=elbe_dir)

        os.system(
            'tar cfj "%s" %s -C "%s" .' %
            (os.path.join(out_path, "elbe-devel.tar.bz2"), ignore, elbe_dir))
Пример #13
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")
    (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 = 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")

    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(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 pname not in v.cache:
            if pauto == 'false':
                print(
                    "%s does not exist in cache but is specified in pkg-list" %
                    pname)
                errors += 1
            else:
                print("%s is no more required" % pname)
                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("%s: %s != %s" % (pname, pver, cver))
                required_updates += 1

    sys.stdout.flush()
    sys.stderr.flush()
    if errors > 0:
        print("%d Errors occured, xml files needs fixing" % errors)
        if opt.script:
            os.system("%s ERRORS %s" % (opt.script, args[0]))
    elif required_updates > 0:
        print("%d updates required" % required_updates)
        if opt.script:
            os.system("%s UPDATE %s" % (opt.script, args[0]))
    else:
        print("No Updates available")
Пример #14
0
def run_command(argv):
    pack_dir = elbepack.__path__[0]
    template_dir = os.path.join(pack_dir, "mako")

    oparser = OptionParser(usage="usage: %prog create [options] <filename>")

    oparser.add_option("--oldkvm",
                       action="store_true",
                       dest="oldkvm",
                       default=False,
                       help="We are building for an old kvm version")

    oparser.add_option("--debug",
                       action="store_true",
                       dest="debug",
                       default=False,
                       help="Enable various features to debug the build")

    oparser.add_option("--skip-validation",
                       action="store_true",
                       dest="skip_validation",
                       default=False,
                       help="Skip xml schema validation")

    oparser.add_option("--skip-cds",
                       action="store_true",
                       dest="skip_cds",
                       default=False,
                       help="Skip cd generation")

    oparser.add_option("--directory",
                       dest="dir",
                       help="Write Makefile into specified directory",
                       metavar="FILE")

    oparser.add_option("--buildtype",
                       dest="buildtype",
                       help="Override the buildtype")

    oparser.add_option("--build-source",
                       action="store_true",
                       dest="buildsources",
                       default=False,
                       help="Build source cdrom")

    oparser.add_option("--proxy", dest="proxy", help="Override the http Proxy")

    (opt, args) = oparser.parse_args(argv)

    if len(args) == 0:
        print "No Filename specified"
        oparser.print_help()
        sys.exit(20)

    if len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

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

        xml = etree(args[0])
    except:
        print "Unable to open xml File. Bailing out"
        sys.exit(20)

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

    if opt.proxy:
        http_proxy = opt.proxy
    elif xml.has("project/mirror/primary_proxy"):
        http_proxy = xml.text("project/mirror/primary_proxy")
    else:
        http_proxy = ""

    defs = ElbeDefaults(buildtype)

    if xml.node("/project/mirror/url-list"):
        for n in xml.node("/project/mirror/url-list"):
            if n.has("binary"):
                if n.text("binary").find("localhost") != -1:
                    print "localhost is not allowed as url - use LOCALMACHINE to refer to your system."
                    sys.exit(40)
            if n.has("source"):
                if n.text("source").find("localhost") != -1:
                    print "localhost is not allowed as url - use LOCALMACHINE to refer to your system."
                    sys.exit(40)

    if not opt.dir:
        path = "./build"
    else:
        path = opt.dir

    try:
        os.makedirs(path)
    except:
        print 'unable to create project directory: %s' % path
        sys.exit(30)

    out_path = os.path.join(path, ".elbe-in")
    try:
        os.makedirs(out_path)
    except:
        print 'unable to create subdirectory: %s' % out_path
        sys.exit(30)

    d = {
        "elbe_version": elbe_version,
        "opt": opt,
        "xml": xml,
        "prj": xml.node("/project"),
        "tgt": xml.node("/target"),
        "pkgs": xml.node("/target/pkg-list"),
        "fine": xml.node("/finetuning"),
        "defs": defs,
        "http_proxy": http_proxy,
        "buildchroot": False,
        "preseed": get_preseed(xml)
    }

    try:
        copy_kinitrd(xml, out_path, defs)
    except:
        print "Failure to download kernel/initrd debian Package"
        print "Check your source URLs"
        sys.exit(20)

    if xml.has("archive"):
        unbase(xml.text("/archive"), os.path.join(out_path, "archive.tar.bz2"))

    templates = os.listdir(template_dir)

    make_executable = [
        "02pinning.mako", "finetuning.sh.mako",
        "changeroot-into-buildenv.sh.mako", "cp-scipts-into-buildenv.sh.mako",
        "create-target-rfs.sh.mako", "part-target.sh.mako",
        "post-inst.sh.mako", "print_licence.sh.mako", "mkcdrom.sh.mako"
    ]

    for t in templates:
        print t
        o = t.replace(".mako", "")
        if t == "Makefile.mako":
            write_template(os.path.join(path, o),
                           os.path.join(template_dir, t), d)
        else:
            write_template(os.path.join(out_path, o),
                           os.path.join(template_dir, t), d)

        if t in make_executable:
            os.chmod(os.path.join(out_path, o), 0755)

    shutil.copyfile(args[0], os.path.join(out_path, "source.xml"))

    shutil.copyfile(os.path.join(pack_dir, "treeutils.py"),
                    os.path.join(out_path, "treeutils.py"))

    shutil.copyfile(os.path.join(pack_dir, "version.py"),
                    os.path.join(out_path, "version.py"))

    shutil.copyfile(os.path.join(pack_dir, "dump.py"),
                    os.path.join(out_path, "dump.py"))

    shutil.copyfile(os.path.join(pack_dir, "hdimg.py"),
                    os.path.join(out_path, "hdimg.py"))

    shutil.copyfile(os.path.join(pack_dir, "fstab.py"),
                    os.path.join(out_path, "fstab.py"))
Пример #15
0
def run_command( argv ):
    oparser = OptionParser( usage="usage: %prog init [options] <filename>" )

    oparser.add_option( "--skip-validation", action="store_true",
                        dest="skip_validation", default=False,
                        help="Skip xml schema validation" )

    oparser.add_option( "--directory", dest="directory",
                        help="Working directory (default is build)",
                        metavar="FILE" )

    oparser.add_option( "--cdrom", dest="cdrom",
                        help="Use FILE as cdrom iso, and use that to build the initvm",
                        metavar="FILE" )

    oparser.add_option( "--proxy", dest="proxy",
                        help="Override the http Proxy" )

    oparser.add_option( "--buildtype", dest="buildtype",
                        help="Override the buildtype" )

    oparser.add_option( "--debug", dest="debug",
                        action="store_true", default=False,
           help="start qemu in graphical mode to enable console switch" )

    oparser.add_option( "--devel", dest="devel",
                        action="store_true", default=False,
           help="use devel mode, and install current builddir inside initvm" )

    (opt,args) = oparser.parse_args(argv)

    print opt.directory

    if len(args) == 0:
        print "no filename specified"
        oparser.print_help()
        sys.exit(20)
    elif len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

    if opt.devel:
        if not os.path.isdir( os.path.join (elbe_dir, "elbepack")):
            print "Devel Mode only valid, when running from elbe checkout"
            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)

    xml = etree( args[0] )

    if not xml.has( "initvm" ):
        print "fatal error: xml missing mandatory section 'initvm'"
        sys.exit(20)

    if opt.buildtype:
        buildtype = opt.buildtype
    elif xml.has( "initvm/buildtype" ):
        buildtype = xml.text( "/initvm/buildtype" )
    else:
        buildtype = "nodefaults"

    defs = ElbeDefaults( buildtype )

    http_proxy = ""
    if os.getenv ("http_proxy"):
        http_proxy = os.getenv ("http_proxy")
    elif opt.proxy:
        http_proxy = opt.proxy
    elif xml.has("initvm/mirror/primary_proxy"):
        http_proxy = xml.text("initvm/mirror/primary_proxy")

    if opt.cdrom:
        mirror = xml.node ("initvm/mirror")
        mirror.clear ()
        cdrom = mirror.ensure_child ("cdrom")
        cdrom.set_text (os.path.abspath (opt.cdrom))

    if not opt.directory:
        path = "./build"
    else:
        path = opt.directory

    try:
        os.makedirs(path)
    except OSError, e:
        print 'unable to create project directory: %s (%s)' % (path, e.strerror)
        sys.exit(30)
Пример #16
0
def run_command( argv ):
    pack_dir = elbepack.__path__[0]

    oparser = OptionParser( usage="usage: %prog show [options] <filename>" )

    oparser.add_option( "--verbose", action="store_true", dest="verbose",
                        default=False,
                        help="show detailed project informations" )

    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) == 0:
        print "No Filename specified"
        oparser.print_help()
        sys.exit(20)

    if len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

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

        xml = etree( args[0] )
    except:
        print "Unable to open xml File. Bailing out"
        sys.exit(20)

    print '== %s: %s - version %s ==' %(
        args[0],
        xml.text("/project/name"),
        xml.text("/project/version"))
    print 'Debian suite: %s/%s' % (
        xml.text("/project/suite"),
        xml.text("/buildimage/arch"))
    for s in xml.text("/project/description").splitlines():
        print '%s' % s.strip()
    if opt.verbose:
        print 'root password: %s' % xml.text("/target/passwd")
        print 'primary_mirror: %s://%s%s' %(
              xml.text("/project/mirror/primary_proto"),
              xml.text("/project/mirror/primary_host"),
              xml.text("/project/mirror/primary_path"))
        print 'additional mirrors:'
        for url in xml.node("/project/mirror/url-list"):
              if url.has("binary"):
                        print '    deb %s' % url.text("binary").strip()
              if url.has("source"):
                        print '    deb-src %s' % url.text("source").strip()
        print 'packages:'
        for pkg in xml.node("/target/pkg-list"):
              print '    %s' % pkg.et.text
        print 'skip package validation: %s' % xml.has("project/noauth")
        print 'archive embedded?        %s' % xml.has("archive")
Пример #17
0
def run_command( argv ):
    pack_dir = elbepack.__path__[0]
    template_dir = os.path.join( pack_dir, "mako" )

    oparser = OptionParser( usage="usage: %prog create [options] <filename>" )

    oparser.add_option( "--oldkvm", action="store_true", dest="oldkvm",
                        default=False,
                        help="We are building for an old kvm version" )

    oparser.add_option( "--debug", action="store_true", dest="debug",
                        default=False,
                        help="Enable various features to debug the build" )

    oparser.add_option( "--skip-validation", action="store_true",
                        dest="skip_validation", default=False,
                        help="Skip xml schema validation" )

    oparser.add_option( "--skip-cds", action="store_true", dest="skip_cds",
                        default=False,
                        help="Skip cd generation" )

    oparser.add_option( "--directory", dest="dir",
                        help="Write Makefile into specified directory",
                        metavar="FILE" )

    oparser.add_option( "--build-source", action="store_true",
                        dest="buildsources", default=False,
                        help="Build source cdrom" )

    (opt,args) = oparser.parse_args(argv)

    if len(args) == 0:
        print "No Filename specified"
        oparser.print_help()
        sys.exit(20)

    if len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

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

        xml = etree( args[0] )
    except:
        print "Unable to open xml File. Bailing out"
        sys.exit(20)

    if not opt.dir:
        path = "./build"
    else:
        path = opt.dir

    try:
        os.makedirs(path)
    except:
        print 'unable to create project directory: %s' % path
        sys.exit(30)

    d = {"opt": opt,
         "xml": xml,
         "prj": xml.node("/project"),
         "tgt": xml.node("/target"),
         "pkgs": xml.node("/target/pkg-list"),
         "fine": xml.node("/finetuning"),
         "preseed": get_preseed(xml) }

    try:
        copy_kinitrd(xml, path)
    except:
        print "Failure to download kernel/initrd debian Package"
        print "Check your source URLs"
        sys.exit(20)

    if xml.has("archive"):
        unbase( xml.text("/archive"), os.path.join(path,"archive.tar.bz2") )

    templates = os.listdir( template_dir )

    make_executable = [ "02pinning.mako",
                        "finetuning.sh.mako",
                        "changeroot-into-buildenv.sh.mako",
                        "cp-scipts-into-buildenv.sh.mako",
                        "create-target-rfs.sh.mako",
                        "part-target.sh.mako",
                        "post-inst.sh.mako",
                        "print_licence.sh.mako",
                        "purge.sh.mako",
                        "mkcdrom.sh.mako" ]

    for t in templates:
        print t
        o = t.replace( ".mako", "" )
        write_template(os.path.join(path,o), os.path.join(template_dir, t), d )

        if t in make_executable:
            os.chmod( os.path.join(path,o), 0755 )

    shutil.copyfile( args[0],
       os.path.join(path, "source.xml" ) )

    shutil.copyfile( os.path.join( pack_dir, "treeutils.py" ),
       os.path.join(path, "treeutils.py" ) )

    shutil.copyfile( os.path.join( pack_dir, "dump.py" ),
       os.path.join(path, "dump.py" ) )
Пример #18
0
def run_command( argv ):
    pack_dir = elbepack.__path__[0]
    template_dir = os.path.join( pack_dir, "mako" )

    oparser = OptionParser( usage="usage: %prog create [options] <filename>" )

    oparser.add_option( "--oldkvm", action="store_true", dest="oldkvm",
                        default=False,
                        help="We are building for an old kvm version" )

    oparser.add_option( "--debug", action="store_true", dest="debug",
                        default=False,
                        help="Enable various features to debug the build" )

    oparser.add_option( "--skip-validation", action="store_true",
                        dest="skip_validation", default=False,
                        help="Skip xml schema validation" )

    oparser.add_option( "--skip-cds", action="store_true", dest="skip_cds",
                        default=False,
                        help="Skip cd generation" )

    oparser.add_option( "--directory", dest="dir",
                        help="Write Makefile into specified directory",
                        metavar="FILE" )

    oparser.add_option( "--buildtype", dest="buildtype",
                        help="Override the buildtype" )

    oparser.add_option( "--build-source", action="store_true",
                        dest="buildsources", default=False,
                        help="Build source cdrom" )

    oparser.add_option( "--proxy", dest="proxy",
                        help="Override the http Proxy" )

    (opt,args) = oparser.parse_args(argv)

    if len(args) == 0:
        print "No Filename specified"
        oparser.print_help()
        sys.exit(20)

    if len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

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

        xml = etree( args[0] )
    except:
        print "Unable to open xml File. Bailing out"
        sys.exit(20)

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

    if opt.proxy:
        http_proxy = opt.proxy
    elif xml.has("project/mirror/primary_proxy"):
        http_proxy = xml.text("project/mirror/primary_proxy")
    else:
        http_proxy = ""

    defs = ElbeDefaults( buildtype )

    if xml.node("/project/mirror/url-list"):
        for n in xml.node("/project/mirror/url-list"):
           if n.has("binary"):
             if n.text("binary").find("localhost") != -1:
               print "localhost is not allowed as url - use LOCALMACHINE to refer to your system."
               sys.exit(40)
           if n.has("source"):
             if n.text("source").find("localhost") != -1:
               print "localhost is not allowed as url - use LOCALMACHINE to refer to your system."
               sys.exit(40)

    if not opt.dir:
        path = "./build"
    else:
        path = opt.dir

    try:
        os.makedirs(path)
    except:
        print 'unable to create project directory: %s' % path
        sys.exit(30)

    out_path = os.path.join(path,".elbe-in")
    try:
        os.makedirs(out_path)
    except:
        print 'unable to create subdirectory: %s' % out_path
        sys.exit(30)

    d = {"elbe_version": elbe_version,
         "opt": opt,
         "xml": xml,
         "prj": xml.node("/project"),
         "tgt": xml.node("/target"),
         "pkgs": xml.node("/target/pkg-list"),
         "fine": xml.node("/finetuning"),
         "defs": defs,
         "http_proxy": http_proxy,
         "buildchroot": False,
         "preseed": get_preseed(xml) }

    try:
        copy_kinitrd(xml, out_path, defs)
    except:
        print "Failure to download kernel/initrd debian Package"
        print "Check your source URLs"
        sys.exit(20)

    if xml.has("archive"):
        unbase( xml.text("/archive"), os.path.join(out_path,"archive.tar.bz2") )

    templates = os.listdir( template_dir )

    make_executable = [ "02pinning.mako",
                        "finetuning.sh.mako",
                        "changeroot-into-buildenv.sh.mako",
                        "cp-scipts-into-buildenv.sh.mako",
                        "create-target-rfs.sh.mako",
                        "part-target.sh.mako",
                        "post-inst.sh.mako",
                        "print_licence.sh.mako",
                        "mkcdrom.sh.mako" ]

    for t in templates:
        print t
        o = t.replace( ".mako", "" )
        if t == "Makefile.mako":
            write_template(os.path.join(path,o), os.path.join(template_dir, t), d )
        else:
            write_template(os.path.join(out_path,o), os.path.join(template_dir, t), d )

        if t in make_executable:
            os.chmod( os.path.join(out_path,o), 0755 )

    shutil.copyfile( args[0],
       os.path.join(out_path, "source.xml" ) )

    shutil.copyfile( os.path.join( pack_dir, "treeutils.py" ),
       os.path.join(out_path, "treeutils.py" ) )

    shutil.copyfile( os.path.join( pack_dir, "version.py" ),
       os.path.join(out_path, "version.py" ) )

    shutil.copyfile( os.path.join( pack_dir, "dump.py" ),
       os.path.join(out_path, "dump.py" ) )

    shutil.copyfile( os.path.join( pack_dir, "hdimg.py" ),
       os.path.join(out_path, "hdimg.py" ) )

    shutil.copyfile( os.path.join( pack_dir, "fstab.py" ),
       os.path.join(out_path, "fstab.py" ) )
Пример #19
0
def run_command( argv ):
    oparser = OptionParser(usage="usage: %prog buildchroot [options] <xmlfile>")
    oparser.add_option( "-t", "--target", dest="target",
                        help="directoryname of target" )
    oparser.add_option( "-o", "--output", dest="output",
                        help="name of logfile" )
    oparser.add_option( "-n", "--name", dest="name",
                        help="name of the project (included in the report)" )
    oparser.add_option( "--skip-validation", action="store_true",
                        dest="skip_validation", default=False,
                        help="Skip xml schema validation" )
    oparser.add_option( "--skip-debootstrap", action="store_true",
                        dest="skip_debootstrap", default=False,
                        help="Skip debootstrap" )
    oparser.add_option( "--skip-cdrom", action="store_true",
                        dest="skip_cdrom", default=False,
                        help="Skip cdrom iso generation" )
    oparser.add_option( "--build-sources", action="store_true",
                        dest="buildsources", default=False,
                        help="Build Source CD" )
    oparser.add_option( "--debug", action="store_true", dest="debug",
                        default=False,
                        help="Enable various features to debug the build" )
    oparser.add_option( "--buildtype", dest="buildtype",
                        help="Override the buildtype" )
    oparser.add_option( "--proxy", dest="proxy",
                        help="Override the http proxy" )

    (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:
        if not validate_xml( args[0] ):
            print "xml validation failed. Bailing out"
            sys.exit(20)

    xml = etree( args[0] )
    prj = xml.node("/project")
    tgt = xml.node("/target")

    if not opt.output:
        return 0
    if not opt.target:
        return 0

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

    defs = ElbeDefaults( buildtype )

    chroot = os.path.join(opt.target, "chroot")
    os.system( 'mkdir -p "%s"' % chroot )

    outf = asccidoclog(opt.output)

    if opt.name:
        outf.h1( "ELBE Report for Project "+opt.name )
    else:
        outf.h1( "ELBE Report" )

    outf.printo( "report timestamp: "+datetime.datetime.now().strftime("%Y%m%d-%H%M%S") )

    suite = prj.text("suite")
    target_arch = prj.text("buildimage/arch", default=defs, key="arch")

    slist = ""
    mirror = "Error"
    if prj.has("mirror/primary_host"):
        mirror = "%s://%s/%s" % ( prj.text("mirror/primary_proto"), prj.text("mirror/primary_host"), prj.text("mirror/primary_path") )
        slist += "deb %s %s main\n" % (mirror, suite)
        slist += "deb-src %s %s main\n" % (mirror, suite)

    if prj.has("mirror/cdrom"):
        cdrompath = os.path.join( opt.target, "cdrom" )
        mirror = "file://%s/debian" % cdrompath
        os.system( 'mkdir -p "%s"' % cdrompath )
        os.system( 'mount -o loop "%s" "%s"' % (prj.text("mirror/cdrom"), cdrompath ) )

        slist += "deb copy:///mnt %s main\n" % (suite)
        #slist += "deb-src file:///mnt %s main\n" % (suite)

    if opt.proxy:
        os.environ["http_proxy"] = opt.proxy
    elif prj.has("mirror/primary_proxy"):
        os.environ["http_proxy"] = prj.text("mirror/primary_proxy")

    os.environ["LANG"] = "C"
    os.environ["LANGUAGE"] = "C"
    os.environ["LC_ALL"] = "C"
    os.environ["DEBIAN_FRONTEND"]="noninteractive"
    os.environ["DEBONF_NONINTERACTIVE_SEEN"]="true"

    try:
        if prj.node("mirror/url-list"):
            for n in prj.node("mirror/url-list"):
                slist += "deb %s\n" % n.text("binary").strip()

        serial_con, serial_baud = tgt.text( "console" ).split(',')

        if not opt.skip_debootstrap:
            debootstrap( outf, chroot, mirror, suite, target_arch, defs )
        seed_files( outf, chroot, slist, xml, args[0], opt, defs )

    finally:
        if prj.has("mirror/cdrom"):
            os.system( 'umount "%s"' % cdrompath )

    mount_stuff( outf, chroot )
    if prj.has("mirror/cdrom"):
        os.system( 'mount -o loop "%s" "%s"' % (prj.text("mirror/cdrom"), os.path.join(chroot, "mnt")) )

    pkglist = ["parted", "mtd-utils", "dpkg-dev", "dosfstools", "apt-rdepends",
               "python-apt", "rsync", "genisoimage", "reprepro", "python-parted"]

    try:
        do_chroot( outf, chroot, "apt-get update" )
        do_chroot( outf, chroot, """/bin/sh -c 'debconf-set-selections < /opt/elbe/custom-preseed.cfg'""" )
        if not opt.skip_debootstrap:
            do_chroot( outf, chroot, "apt-get install -y --force-yes " + string.join( pkglist ) )
        do_chroot( outf, chroot, "python /opt/elbe/adjustpkgs.py -o /opt/elbe/bla.log /opt/elbe/source.xml" )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "%s\\n%s\\n" | passwd'""" % (tgt.text("passwd"), tgt.text("passwd")) )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "127.0.0.1 %s %s.%s" >> /etc/hosts'""" % (tgt.text("hostname"), tgt.text("hostname"), tgt.text("domain")) )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "%s" > /etc/hostname'""" % tgt.text("hostname") )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "%s.%s" > /etc/mailname'""" % (tgt.text("hostname"), tgt.text("domain")) )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "T0:23:respawn:/sbin/getty -L %s %s vt100" >> /etc/inittab'""" % (serial_con, serial_baud) )
        do_chroot( outf, chroot, "rm /usr/sbin/policy-rc.d" )
        do_chroot( outf, chroot, "/opt/elbe/create-target-rfs.sh" )
        if not opt.skip_cdrom:
            do_chroot( outf, chroot, "/opt/elbe/mkcdrom.sh" )

    finally:
        if prj.has("mirror/cdrom"):
            os.system( 'umount "%s"' % os.path.join(chroot, "mnt") )
        umount_stuff( outf, chroot )

    extract = open( os.path.join(chroot, "opt/elbe/files-to-extract"), "r" )
    for fname in extract.readlines():
        outf.do_command( 'cp "%s" "%s"' % (chroot+fname.strip(), opt.target) ) 
    extract.close()
Пример #20
0
def run_command(argv):
    oparser = OptionParser(usage="usage: %prog init [options] <filename>")

    oparser.add_option("--skip-validation",
                       action="store_true",
                       dest="skip_validation",
                       default=False,
                       help="Skip xml schema validation")

    oparser.add_option("--directory",
                       dest="directory",
                       help="Working directory (default is build)",
                       metavar="FILE")

    oparser.add_option(
        "--cdrom",
        dest="cdrom",
        help="Use FILE as cdrom iso, and use that to build the initvm",
        metavar="FILE")

    oparser.add_option("--proxy", dest="proxy", help="Override the http Proxy")

    oparser.add_option("--buildtype",
                       dest="buildtype",
                       help="Override the buildtype")

    oparser.add_option(
        "--debug",
        dest="debug",
        action="store_true",
        default=False,
        help="start qemu in graphical mode to enable console switch")

    oparser.add_option(
        "--devel",
        dest="devel",
        action="store_true",
        default=False,
        help="use devel mode, and install current builddir inside initvm")

    (opt, args) = oparser.parse_args(argv)

    print opt.directory

    if len(args) == 0:
        print "no filename specified"
        oparser.print_help()
        sys.exit(20)
    elif len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

    if opt.devel:
        if not os.path.isdir(os.path.join(elbe_dir, "elbepack")):
            print "Devel Mode only valid, when running from elbe checkout"
            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)

    xml = etree(args[0])

    if not xml.has("initvm"):
        print "fatal error: xml missing mandatory section 'initvm'"
        sys.exit(20)

    if opt.buildtype:
        buildtype = opt.buildtype
    elif xml.has("initvm/buildtype"):
        buildtype = xml.text("/initvm/buildtype")
    else:
        buildtype = "nodefaults"

    defs = ElbeDefaults(buildtype)

    http_proxy = ""
    if os.getenv("http_proxy"):
        http_proxy = os.getenv("http_proxy")
    elif opt.proxy:
        http_proxy = opt.proxy
    elif xml.has("initvm/mirror/primary_proxy"):
        http_proxy = xml.text("initvm/mirror/primary_proxy")

    if opt.cdrom:
        mirror = xml.node("initvm/mirror")
        mirror.clear()
        cdrom = mirror.ensure_child("cdrom")
        cdrom.set_text(os.path.abspath(opt.cdrom))

    if not opt.directory:
        path = "./build"
    else:
        path = opt.directory

    try:
        os.makedirs(path)
    except OSError, e:
        print 'unable to create project directory: %s (%s)' % (path,
                                                               e.strerror)
        sys.exit(30)
Пример #21
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 init [options] <filename>")

    oparser.add_option("--skip-validation", action="store_true",
                       dest="skip_validation", default=False,
                       help="Skip xml schema validation")

    oparser.add_option("--directory", dest="directory", default="./build",
                       help="Working directory (default is build)",
                       metavar="FILE")

    oparser.add_option(
        "--cdrom",
        dest="cdrom",
        help="Use FILE as cdrom iso, and use that to build the initvm",
        metavar="FILE")

    oparser.add_option("--buildtype", dest="buildtype",
                       help="Override the buildtype")

    oparser.add_option(
        "--debug",
        dest="debug",
        action="store_true",
        default=False,
        help="start qemu in graphical mode to enable console switch")

    oparser.add_option(
        "--devel",
        dest="devel",
        action="store_true",
        default=False,
        help="use devel mode, and install current builddir inside initvm")

    oparser.add_option(
        "--nesting",
        dest="nesting",
        action="store_true",
        default=False,
        help="allow initvm to support nested kvm. "
             "This makes /proc/cpuinfo inside initvm differ per host.")

    oparser.add_option(
        "--skip-build-bin",
        action="store_false",
        dest="build_bin",
        default=True,
        help="Skip building Binary Repository CDROM, for exact Reproduction")

    oparser.add_option(
        "--skip-build-sources",
        action="store_false",
        dest="build_sources",
        default=True,
        help="Skip building Source CDROM")

    (opt, args) = oparser.parse_args(argv)

    if not args:
        print("no filename specified")
        oparser.print_help()
        sys.exit(20)
    elif len(args) > 1:
        print("too many filenames specified")
        oparser.print_help()
        sys.exit(20)

    with elbe_logging({"files": None}):
        if opt.devel:
            if not os.path.isdir(os.path.join(elbe_dir, "elbepack")):
                logging.error("Devel Mode only valid, "
                              "when running from elbe checkout")
                sys.exit(20)

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

        xml = etree(args[0])

        if not xml.has("initvm"):
            logging.error("fatal error: "
                          "xml missing mandatory section 'initvm'")
            sys.exit(20)

        if opt.buildtype:
            buildtype = opt.buildtype
        elif xml.has("initvm/buildtype"):
            buildtype = xml.text("/initvm/buildtype")
        else:
            buildtype = "nodefaults"

        defs = ElbeDefaults(buildtype)

        http_proxy = xml.text("/initvm/mirror/primary_proxy", default="")
        http_proxy = http_proxy.strip().replace("LOCALMACHINE", "localhost")

        if opt.cdrom:
            mirror = xml.node("initvm/mirror")
            mirror.clear()
            cdrom = mirror.ensure_child("cdrom")
            cdrom.set_text(os.path.abspath(opt.cdrom))

        # this is a workaround for
        # http://lists.linutronix.de/pipermail/elbe-devel/2017-July/000541.html
        _, virt = command_out('test -x /usr/bin/systemd-detect-virt && '
                              '/usr/bin/systemd-detect-virt')
        _, dist = command_out('lsb_release -cs')

        if 'vmware' in virt and 'stretch' in dist:
            machine_type = 'pc-i440fx-2.6'
        else:
            machine_type = 'pc'

        try:
            os.makedirs(opt.directory)
        except OSError as e:
            logging.error("unable to create project directory: %s (%s)",
                          opt.directory,
                          e.strerror)
            sys.exit(30)

        out_path = os.path.join(opt.directory, ".elbe-in")
        try:
            os.makedirs(out_path)
        except OSError as e:
            logging.error("unable to create subdirectory: %s (%s)",
                          out_path,
                          e.strerror)
            sys.exit(30)

        initvm_http_proxy = http_proxy.replace('http://localhost:',
                                               'http://10.0.2.2:')
        d = {"elbe_version": elbe_version,
             "defs": defs,
             "opt": opt,
             "xml": xml,
             "prj": xml.node("/initvm"),
             "http_proxy": initvm_http_proxy,
             "pkgs": xml.node("/initvm/pkg-list") or [],
             "preseed": get_initvm_preseed(xml),
             "machine_type": machine_type,
             "cfg": cfg}

        if http_proxy != "":
            os.putenv("http_proxy", http_proxy)
            os.putenv("https_proxy", http_proxy)
            os.putenv("no_proxy", "localhost,127.0.0.1")

        try:
            copy_kinitrd(xml.node("/initvm"), out_path)
        except NoKinitrdException as e:
            msg = str(e)
            logging.error("Failure to download kernel/initrd debian Package:")
            logging.error("")
            logging.error(msg)
            logging.error("")
            logging.error("Check Mirror configuration")
            if 'SHA256SUMS' in msg:
                logging.error("If you use debmirror please read "
                              "https://github.com/Linutronix/elbe/issues/188 "
                              "on how to work around the issue")
            sys.exit(20)

        templates = os.listdir(init_template_dir)

        make_executable = ["init-elbe.sh.mako",
                           "preseed.cfg.mako"]

        for t in templates:
            o = t.replace(".mako", "")

            if t in ("Makefile.mako", "libvirt.xml.mako"):
                write_template(
                    os.path.join(
                        opt.directory, o), os.path.join(
                        init_template_dir, t), d, linebreak=True)
            else:
                write_template(
                    os.path.join(
                        out_path, o), os.path.join(
                        init_template_dir, t), d, linebreak=False)

            if t in make_executable:
                os.chmod(os.path.join(out_path, o), 0o755)

        shutil.copyfile(args[0],
                        os.path.join(out_path, "source.xml"))

        if opt.cdrom:
            system('7z x -o%s "%s" elbe-keyring.gpg' % (out_path, opt.cdrom))
        else:
            keys = []
            for key in xml.all(".//initvm/mirror/url-list/url/raw-key"):
                keys.append(key.et.text)

            import_keyring = os.path.join(out_path, "elbe-keyring")

            do('gpg --no-options \
                    --no-default-keyring \
                    --keyring %s --import' % import_keyring,
               stdin="".join(keys).encode('ascii'),
               allow_fail=True,
               env_add={'GNUPGHOME': out_path})

            export_keyring = import_keyring + ".gpg"

            # No need to set GNUPGHOME because both input and output
            # keyring files are specified.

            do('gpg --no-options \
                    --no-default-keyring \
                    --keyring %s \
                    --export \
                    --output %s' % (import_keyring, export_keyring))

        if opt.devel:
            out_real = os.path.realpath(out_path)
            opts = []
            if out_real.startswith(elbe_dir + os.sep):
                opts.append('--exclude "%s"' %
                            os.path.relpath(out_path, start=elbe_dir))

            opts.append("--exclude-vcs")
            opts.append("--exclude-vcs-ignores")
            opts.append("--exclude='elbe-build*'")
            opts.append("--exclude='docs/*'")
            tar_fname = os.path.join(out_path, "elbe-devel.tar.bz2")
            system('tar cfj "%s" %s -C "%s" .' % (tar_fname,
                                                  " ".join(opts),
                                                  elbe_dir))

        to_cpy = [("apt.conf", "etc/apt"),
                  ("init-elbe.sh", ""),
                  ("source.xml", ""),
                  ("initrd-cdrom.gz", ""),
                  ("vmlinuz", ""),
                  ("preseed.cfg", "")]

        elbe_in  = Filesystem(out_path)

        if opt.devel:
            to_cpy.append(("elbe-devel.tar.bz2", ""))

        # Convert relative rfs path to absolute in the system
        to_cpy = [(elbe_in.fname(src), elbe_in.fname(os.path.join("initrd-tree", dst)))
                  for src, dst
                  in to_cpy]

        # These are already absolute path!
        keyrings = elbe_in.fname(os.path.join("initrd-tree", "usr/share/keyrings"))
        for gpg in elbe_in.glob("*.gpg"):
            to_cpy.append((gpg, keyrings))

        for src, dst in to_cpy:
            try:
                os.makedirs(dst)
            except FileExistsError:
                pass
            shutil.copy(src, dst)
Пример #22
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")
Пример #23
0
def run_command(argv):
    oparser = OptionParser(usage="usage: %prog show [options] <filename>")

    oparser.add_option(
        "--verbose", action="store_true", dest="verbose", default=False, help="show detailed project informations"
    )

    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) == 0:
        print "No Filename specified"
        oparser.print_help()
        sys.exit(20)

    if len(args) > 1:
        print "too many filenames specified"
        oparser.print_help()
        sys.exit(20)

    try:
        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)

        xml = etree(args[0])
    except:
        print "Unable to open xml File. Bailing out"
        sys.exit(20)

    if not xml.has("./project"):
        print "no project description available"
        sys.exit(20)

    print "== %s ==" % (args[0])
    print "Debian suite: %s" % (xml.text("./project/suite"))
    for s in xml.text("./project/description").splitlines():
        print "%s" % s.strip()
    if opt.verbose:
        print "root password: %s" % xml.text("./target/passwd")
        print "primary_mirror: %s://%s%s" % (
            xml.text("./project/mirror/primary_proto"),
            xml.text("./project/mirror/primary_host"),
            xml.text("./project/mirror/primary_path"),
        )
        if xml.has("./project/mirror/url-list"):
            print "additional mirrors:"
            for url in xml.node("./project/mirror/url-list"):
                if url.has("binary"):
                    print "    deb %s" % url.text("binary").strip()
                if url.has("source"):
                    print "    deb-src %s" % url.text("source").strip()
        print "packages:"
        for pkg in xml.node("./target/pkg-list"):
            print "    %s" % pkg.et.text
        print "skip package validation: %s" % xml.has("./project/noauth")
        print "archive embedded?        %s" % xml.has("./archive")
Пример #24
0
def run_command( argv ):
    oparser = OptionParser(usage="usage: %prog buildchroot [options] <xmlfile>")
    oparser.add_option( "-t", "--target", dest="target",
                        help="directoryname of target" )
    oparser.add_option( "-o", "--output", dest="output",
                        help="name of logfile" )
    oparser.add_option( "-n", "--name", dest="name",
                        help="name of the project (included in the report)" )
    oparser.add_option( "--skip-validation", action="store_true",
                        dest="skip_validation", default=False,
                        help="Skip xml schema validation" )
    oparser.add_option( "--skip-debootstrap", action="store_true",
                        dest="skip_debootstrap", default=False,
                        help="Skip debootstrap" )
    oparser.add_option( "--skip-cdrom", action="store_true",
                        dest="skip_cdrom", default=False,
                        help="Skip cdrom iso generation" )
    oparser.add_option( "--build-sources", action="store_true",
                        dest="buildsources", default=False,
                        help="Build Source CD" )
    oparser.add_option( "--debug", action="store_true", dest="debug",
                        default=False,
                        help="Enable various features to debug the build" )
    oparser.add_option( "--buildtype", dest="buildtype",
                        help="Override the buildtype" )
    oparser.add_option( "--proxy", dest="proxy",
                        help="Override the http proxy" )

    (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:
        if not validate_xml( args[0] ):
            print "xml validation failed. Bailing out"
            sys.exit(20)

    xml = etree( args[0] )
    prj = xml.node("/project")
    tgt = xml.node("/target")

    if not opt.output:
        return 0
    if not opt.target:
        return 0

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

    defs = ElbeDefaults( buildtype )

    chroot = os.path.join(opt.target, "chroot")
    os.system( 'mkdir -p "%s"' % chroot )

    outf = asccidoclog(opt.output)

    if opt.name:
        outf.h1( "ELBE Report for Project "+opt.name )
    else:
        outf.h1( "ELBE Report" )

    outf.printo( "report timestamp: "+datetime.datetime.now().strftime("%Y%m%d-%H%M%S") )

    suite = prj.text("suite")
    target_arch = prj.text("buildimage/arch", default=defs, key="arch")

    slist = ""
    mirror = "Error"
    if prj.has("mirror/primary_host"):
        mirror = "%s://%s/%s" % ( prj.text("mirror/primary_proto"), prj.text("mirror/primary_host"), prj.text("mirror/primary_path") )
        slist += "deb %s %s main\n" % (mirror, suite)
        slist += "deb-src %s %s main\n" % (mirror, suite)

    if prj.has("mirror/cdrom"):
        cdrompath = os.path.join( opt.target, "cdrom" )
        mirror = "file://%s/debian" % cdrompath
        os.system( 'mkdir -p "%s"' % cdrompath )
        os.system( 'mount -o loop "%s" "%s"' % (prj.text("mirror/cdrom"), cdrompath ) )

        slist += "deb copy:///mnt %s main\n" % (suite)
        #slist += "deb-src file:///mnt %s main\n" % (suite)

    if opt.proxy:
        os.environ["http_proxy"] = opt.proxy
    elif prj.has("mirror/primary_proxy"):
        os.environ["http_proxy"] = prj.text("mirror/primary_proxy")

    os.environ["LANG"] = "C"
    os.environ["LANGUAGE"] = "C"
    os.environ["LC_ALL"] = "C"
    os.environ["DEBIAN_FRONTEND"]="noninteractive"
    os.environ["DEBONF_NONINTERACTIVE_SEEN"]="true"

    try:
        if prj.node("mirror/url-list"):
            for n in prj.node("mirror/url-list"):
                if n.has("binary"):
                  tmp = n.text("binary").replace("LOCALMACHINE", "localhost")
                  slist += "deb %s\n" % tmp.strip()
                if n.has("source"):
                  tmp = n.text("source").replace("LOCALMACHINE", "localhost")
                  slist += "deb-src %s\n" % tmp.strip()

        serial_con, serial_baud = tgt.text( "console" ).split(',')

        if not opt.skip_debootstrap:
            debootstrap( outf, chroot, mirror, suite, target_arch, defs )
        seed_files( outf, chroot, slist, xml, args[0], opt, defs )

    finally:
        if prj.has("mirror/cdrom"):
            os.system( 'umount "%s"' % cdrompath )

    mount_stuff( outf, chroot )
    if prj.has("mirror/cdrom"):
        os.system( 'mount -o loop "%s" "%s"' % (prj.text("mirror/cdrom"), os.path.join(chroot, "mnt")) )

    pkglist = ["parted", "mtd-utils", "dpkg-dev", "dosfstools", "apt-rdepends",
               "python-apt", "rsync", "genisoimage", "reprepro", "python-parted"]

    try:
        do_chroot( outf, chroot, "apt-get update" )
        do_chroot( outf, chroot, """/bin/sh -c 'debconf-set-selections < /opt/elbe/custom-preseed.cfg'""" )
        if not opt.skip_debootstrap:
            do_chroot( outf, chroot, "apt-get install -y --force-yes " + string.join( pkglist ) )
        do_chroot( outf, chroot, "python /opt/elbe/adjustpkgs.py -o /opt/elbe/bla.log /opt/elbe/source.xml" )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "%s\\n%s\\n" | passwd'""" % (tgt.text("passwd"), tgt.text("passwd")) )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "127.0.0.1 %s %s.%s" >> /etc/hosts'""" % (tgt.text("hostname"), tgt.text("hostname"), tgt.text("domain")) )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "%s" > /etc/hostname'""" % tgt.text("hostname") )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "%s.%s" > /etc/mailname'""" % (tgt.text("hostname"), tgt.text("domain")) )
        do_chroot( outf, chroot, """/bin/sh -c 'echo "T0:23:respawn:/sbin/getty -L %s %s vt100" >> /etc/inittab'""" % (serial_con, serial_baud) )
        do_chroot( outf, chroot, "rm /usr/sbin/policy-rc.d" )
        do_chroot( outf, chroot, "/opt/elbe/create-target-rfs.sh" )
        if not opt.skip_cdrom:
            do_chroot( outf, chroot, "/opt/elbe/mkcdrom.sh" )

    finally:
        if prj.has("mirror/cdrom"):
            os.system( 'umount "%s"' % os.path.join(chroot, "mnt") )
        umount_stuff( outf, chroot )

    extract = open( os.path.join(chroot, "opt/elbe/files-to-extract"), "r" )
    for fname in extract.readlines():
        outf.do_command( 'cp "%s" "%s"' % (chroot+fname.strip(), opt.target) ) 
    extract.close()