Beispiel #1
0
def gen_update_pkg (project, xml_filename, upd_filename,
        override_buildtype = None, skip_validate = False, debug = False,
        cmd_dir = None, cfg_dir=None):

    if xml_filename:
        xml = ElbeXML( xml_filename, buildtype=override_buildtype,
                skip_validate=skip_validate )

        if not xml.has("fullpkgs"):
            raise MissingData("Xml does not have fullpkgs list")

        if not project.xml.has("fullpkgs"):
            raise MissingData("Source Xml does not have fullpkgs list")

        if not project.buildenv.rfs:
            raise MissingData("Target does not have a build environment")

        cache = project.get_rpcaptcache()

        instpkgs  = cache.get_installed_pkgs()
        instindex = {}

        for p in instpkgs:
            instindex[p.name] = p

        xmlpkgs = xml.node("/fullpkgs")
        xmlindex = {}

        fnamelist = []

        for p in xmlpkgs:
            name = p.et.text
            ver  = p.et.get('version')
            md5  = p.et.get('md5')

            xmlindex[name] = p

            if not name in instindex:
                print "package removed: " + name
                continue

            ipkg = instindex[name]
            comp = cache.compare_versions(ipkg.installed_version, ver)

            pfname = ipkg.installed_deb

            if comp == 0:
                print "package ok: " + name + "-" + ipkg.installed_version
                if debug:
                    fnamelist.append( pfname )
                continue

            if comp > 0:
                print "package upgrade: " + pfname
                fnamelist.append( pfname )
            else:
                print "package downgrade: " + name + "-" + ipkg.installed_version

        for p in instpkgs:
            if p.name in xmlindex:
                continue

            print "package new installed " + p.name
            pfname = p.installed_deb
            fnamelist.append( pfname )


    update = os.path.join(project.builddir, "update")

    if os.path.exists( update ):
        rmtree( update )

    os.system( 'mkdir -p %s' % update )

    if xml_filename:
        repodir = os.path.join(update, "repo" )

        repo = UpdateRepo( xml, repodir, project.log )

        for fname in fnamelist:
            path = os.path.join( project.chrootpath, "var/cache/apt/archives", fname )
            repo.includedeb( path )

        repo.finalize ()

        dump_fullpkgs(project.xml, project.buildenv.rfs, cache)

        project.xml.xml.write( os.path.join( update, "new.xml" ) )
        os.system( "cp %s %s" % (xml_filename, os.path.join( update, "base.xml" )) )
    else:
        os.system( "cp source.xml update/new.xml")

    if project.presh_file:
        copyfile (project.presh_file, update + '/pre.sh')
        os.chmod (update + '/pre.sh', 0755)

    if project.postsh_file:
        copyfile (project.postsh_file, update + '/post.sh')
        os.chmod (update + '/post.sh', 0755)

    if cmd_dir:
        inlucdedir (update, 'cmd', cmd_dir, mode=0755)

    if cfg_dir:
        inlucdedir (update, 'conf', cfg_dir)

    create_zip_archive( upd_filename, update, "." )

    if project.postbuild_file:
        project.log.h2 ("postbuild script")
        project.log.do (project.postbuild_file+' "%s %s %s"'%(
            upd_filename,
            project.xml.text ("project/version"),
            project.xml.text ("project/name")),
          allow_fail=True)
Beispiel #2
0
def gen_update_pkg(project, xml_filename, upd_filename,
                   override_buildtype=None, skip_validate=False, debug=False,
                   cmd_dir=None, cfg_dir=None):

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

    if xml_filename:
        xml = ElbeXML(xml_filename, buildtype=override_buildtype,
                      skip_validate=skip_validate)

        if not xml.has("fullpkgs"):
            raise MissingData("Xml does not have fullpkgs list")

        if not project.xml.has("fullpkgs"):
            raise MissingData("Source Xml does not have fullpkgs list")

        if not project.buildenv.rfs:
            raise MissingData("Target does not have a build environment")

        cache = project.get_rpcaptcache()

        instpkgs = cache.get_installed_pkgs()
        instindex = {}

        for p in instpkgs:
            instindex[p.name] = p

        xmlpkgs = xml.node("/fullpkgs")
        xmlindex = {}

        fnamelist = []

        for p in xmlpkgs:
            name = p.et.text
            ver = p.et.get('version')
            md5 = p.et.get('md5')

            xmlindex[name] = p

            if name not in instindex:
                print("package removed: %s" % name)
                continue

            ipkg = instindex[name]
            comp = cache.compare_versions(ipkg.installed_version, ver)

            pfname = ipkg.installed_deb

            if comp == 0:
                print("package ok: %s-%s" % (name, ipkg.installed_version))
                if debug:
                    fnamelist.append(pfname)
                continue

            if comp > 0:
                print("package upgrade: %s" % pfname)
                fnamelist.append(pfname)
            else:
                print(
                    "package downgrade: %s-%s" %
                    (name, ipkg.installed_version))

        for p in instpkgs:
            if p.name in xmlindex:
                continue

            print("package %s newly installed" % p.name)
            pfname = p.installed_deb
            fnamelist.append(pfname)

    update = os.path.join(project.builddir, "update")

    if os.path.exists(update):
        rmtree(update)

    os.system('mkdir -p %s' % update)

    if xml_filename:
        repodir = os.path.join(update, "repo")

        repo = UpdateRepo(xml, repodir, project.log)

        for fname in fnamelist:
            path = os.path.join(
                project.chrootpath,
                "var/cache/apt/archives",
                fname)
            repo.includedeb(path)

        repo.finalize()

        dump_fullpkgs(project.xml, project.buildenv.rfs, cache)

        project.xml.xml.write(os.path.join(update, "new.xml"))
        os.system(
            "cp %s %s" %
            (xml_filename,
             os.path.join(
                 update,
                 "base.xml")))
    else:
        os.system("cp source.xml update/new.xml")

    if project.presh_file:
        copyfile(project.presh_file, update + '/pre.sh')
        os.chmod(update + '/pre.sh', 0o755)

    if project.postsh_file:
        copyfile(project.postsh_file, update + '/post.sh')
        os.chmod(update + '/post.sh', 0o755)

    if cmd_dir:
        inlucdedir(update, 'cmd', cmd_dir, mode=0o755)

    if cfg_dir:
        inlucdedir(update, 'conf', cfg_dir)

    create_zip_archive(upd_filename, update, ".")

    if project.postbuild_file:
        project.log.h2("postbuild script")
        project.log.do(project.postbuild_file + ' "%s %s %s"' % (
            upd_filename,
            project.xml.text("project/version"),
            project.xml.text("project/name")),
            allow_fail=True)