Beispiel #1
0
    def add_package(self, path, repo_uri):
        package = Package(path, 'r')
        # extract control files
        util.clean_dir(ctx.config.install_dir())
        package.extract_PISI_files(ctx.config.install_dir())

        md = metadata.MetaData()
        md.read(os.path.join(ctx.config.install_dir(), ctx.const.metadata_xml))
        md.package.packageSize = os.path.getsize(path)
        if ctx.config.options and ctx.config.options.absolute_uris:
            # FIXME: the name "absolute_uris" does not seem to fit below :/
            md.package.packageURI = os.path.realpath(path)
        else:  # create relative path by default
            # TODO: in the future well do all of this with purl/pfile/&helpers
            # really? heheh -- future exa
            md.package.packageURI = util.removepathprefix(repo_uri, path)
        # check package semantics
        errs = md.errors()
        if md.errors():
            ctx.ui.error(
                _('Package %s: metadata corrupt, skipping...') %
                md.package.name)
            ctx.ui.error(unicode(Error(*errs)))
        else:
            self.packages.append(md.package)
Beispiel #2
0
 def locate_old_package(old_package_fn):
     if util.is_package_name(os.path.basename(old_package_fn),
                             package_name):
         try:
             old_pkg = Package(old_package_fn, 'r')
             old_pkg.read(util.join_path(ctx.config.tmp_dir(),
                                         'oldpkg'))
             ctx.ui.info(_('(found old version %s)') % old_package_fn)
             if str(old_pkg.metadata.package.name) != package_name:
                 ctx.ui.warning(
                     _('Skipping %s with wrong pkg name ') %
                     old_package_fn)
                 return
             old_build = old_pkg.metadata.package.build
             found.append((old_package_fn, old_build))
         except Exception, e:
             print e
             ctx.ui.warning(
                 'Package file %s may be corrupt. Skipping.' %
                 old_package_fn)
Beispiel #3
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""

        self.fetch_component()  # bug 856

        # Strip install directory before building .pisi packages.
        self.strip_install_dir()

        if ctx.get_option('create_static'):
            obj = self.generate_static_package_object()
            if obj:
                self.spec.packages.append(obj)

        if ctx.config.values.build.generatedebug:
            obj = self.generate_debug_package_object()
            if obj:
                self.spec.packages.append(obj)

        new_packages = []
        old_package_names = []

        for package in self.spec.packages:
            old_package_name = None
            # store additional files
            c = os.getcwd()
            os.chdir(self.specdir)
            install_dir = self.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                src = os.path.join(ctx.const.files_dir, afile.filename)
                dest = os.path.join(
                    install_dir + os.path.dirname(afile.target),
                    os.path.basename(afile.target))
                util.copy_file(src, dest)
                if afile.permission:
                    # mode is octal!
                    os.chmod(dest, int(afile.permission, 8))
            os.chdir(c)

            ctx.ui.action(_("** Building package %s") % package.name)

            ctx.ui.info(_("Generating %s,") % ctx.const.files_xml)
            self.gen_files_xml(package)

            # build number
            if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno:
                build_no = old_build_no = None
                ctx.ui.warning(
                    _('Build number is not available. For repo builds you must enable buildno in pisi.conf.'
                      ))
            else:
                build_no, old_build_no = self.calc_build_no(package.name)

            ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
            self.gen_metadata_xml(package, build_no)

            # Calculate new and oldpackage names for buildfarm
            name = util.package_name(package.name, self.spec.source.version,
                                     self.spec.source.release,
                                     self.metadata.package.build)

            if old_build_no:
                old_package_name = util.package_name(package.name,
                                                     self.spec.source.version,
                                                     self.spec.source.release,
                                                     old_build_no)
            old_package_names.append(old_package_name)

            outdir = ctx.get_option('output_dir')
            if outdir:
                name = pisi.util.join_path(outdir, name)
            new_packages.append(name)

            ctx.ui.info(_("Creating PISI package %s.") % name)

            pkg = Package(name, 'w')

            # add comar files to package
            os.chdir(self.specdir)
            for pcomar in package.providesComar:
                fname = util.join_path(ctx.const.comar_dir, pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.pkg_dir())

            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)

            if ctx.get_option('package_format') == "1.0":
                for finfo in files.list:
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    pkg.add_to_package(orgname, arcname)
                pkg.close()
            else:  # default package format is 1.1, so make it fallback.
                ctx.build_leftover = join(self.pkg_dir(),
                                          ctx.const.install_tar_lzma)
                tar = archive.ArchiveTar(ctx.const.install_tar_lzma, "tarlzma")
                for finfo in files.list:
                    #print finfo.path
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    tar.add_to_archive(orgname, arcname.lstrip("install"))
                tar.close()
                pkg.add_to_package(ctx.const.install_tar_lzma)
                pkg.close()
                os.unlink(ctx.const.install_tar_lzma)
                ctx.build_leftover = None

            os.chdir(c)
            self.set_state("buildpackages")
            ctx.ui.info(_("Done."))

        #show the files those are not collected from the install dir
        if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'):
            abandoned_files = self.get_abandoned_files()
            if abandoned_files:
                ctx.ui.warning(
                    _('Abandoned files under the install dir (%s):') %
                    (install_dir))
                for f in abandoned_files:
                    ctx.ui.info('    - %s' % (f))
            else:
                ctx.ui.warning(
                    _('All of the files under the install dir (%s) has been collected by package(s)'
                      ) % (install_dir))

        if ctx.config.values.general.autoclean is True:
            ctx.ui.info(_("Cleaning Build Directory..."))
            util.clean_dir(self.pkg_dir())
        else:
            ctx.ui.info(_("Keeping Build Directory"))

        # reset environment variables after build.  this one is for
        # buildfarm actually. buildfarm re-inits pisi for each build
        # and left environment variables go directly into initial dict
        # making actionsapi.variables.exportFlags() useless...
        os.environ = {}
        os.environ = deepcopy(ctx.config.environ)

        return new_packages, old_package_names
Beispiel #4
0
        if not found:
            return (1, None)
            ctx.ui.warning(
                _('(no previous build found, setting build no to 1.)'))
        else:
            a = filter(lambda (x, y): y != None, found)
            ctx.ui.debug(str(a))
            if a:
                # sort in order of increasing build number
                a.sort(lambda x, y: cmp(x[1], y[1]))
                old_package_fn = a[-1][0]  # get the last one
                old_build = a[-1][1]

                # compare old files.xml with the new one..
                old_pkg = Package(old_package_fn, 'r')
                old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))

                # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
                changed = False
                fnew = self.files.list
                fold = old_pkg.files.list
                fold.sort(lambda x, y: cmp(x.path, y.path))
                fnew.sort(lambda x, y: cmp(x.path, y.path))

                if len(fnew) != len(fold):
                    changed = True
                else:
                    for i in range(len(fold)):
                        fo = fold.pop(0)
                        fn = fnew.pop(0)
Beispiel #5
0
import pisi.config
import pisi.specfile as specfile
import pisi.context as ctx
import pisi.util as util
from pisi.package import Package

locale.setlocale(locale.LC_ALL, '')
options = pisi.config.Options()
if len(sys.argv) > 2:
    options.destdir = sys.argv[2]
else:
    options.destdir = '/'
pisi.api.init(database=True, comar=False, options=options)

filename = sys.argv[1]
package = Package(filename)
package.read()
util.clean_dir('/tmp/install')
package.extract_dir_flat('install', '/tmp/install')
deps = set()
needed = set()
for file in package.files.list:
    #print file.path, file.type
    if file.type == 'executable':
        (ret, lines) = util.run_batch(
            'objdump -p %s' % util.join_path('/tmp/install', file.path))
        for x in lines:
            if x.startswith('  NEEDED'):
                needed.add(x[8:].strip())

#print 'needed guys', needed