Example #1
0
def exclude_special_files(filepath, fileinfo, ag):
    keeplist = ag.get("KeepSpecial", [])
    patterns = {"libtool": "libtool library file", "python": "python.*byte-compiled", "perl": "Perl POD document text"}

    if "libtool" in keeplist:
        # Some upstream sources have buggy libtool and ltmain.sh with them,
        # which causes wrong path entries in *.la files. And these wrong path
        # entries sometimes triggers compile-time errors or linkage problems.
        # Instead of patching all these buggy sources and maintain these
        # patches, pisilinux removes wrong paths...
        if re.match(patterns["libtool"], fileinfo) and not os.path.islink(filepath):
            ladata = file(filepath).read()
            new_ladata = re.sub("-L%s/\S*" % ctx.config.tmp_dir(), "", ladata)
            new_ladata = re.sub("%s/\S*/install/" % ctx.config.tmp_dir(), "/", new_ladata)
            if new_ladata != ladata:
                file(filepath, "w").write(new_ladata)

    for name, pattern in list(patterns.items()):
        if name in keeplist:
            continue

        if fileinfo == None:
            ctx.ui.warning(_("Removing special file skipped for: %s") % filepath)
            return
        elif re.match(pattern, fileinfo):
            ctx.ui.debug("Removing special %s file: %s" % (name, filepath))
            os.unlink(filepath)
            # Remove dir if it becomes empty (Bug #11588)
            util.rmdirs(os.path.dirname(filepath))
Example #2
0
    def run_action_function(self, func, mandatory=False):
        """Calls the corresponding function in actions.py.

        If mandatory parameter is True, and function is not present in
        actionLocals pisilinux.build.Error will be raised."""
        # we'll need our working directory after actionscript
        # finished its work in the archive source directory.
        curDir = os.getcwd()
        src_dir = self.pkg_src_dir()
        if os.path.exists(src_dir):
            os.chdir(src_dir)
        else:
            raise Error(_("ERROR: WorkDir (%s) does not exist\n") % src_dir)

        if func in self.actionLocals:
            if (
                ctx.get_option("ignore_sandbox")
                or not ctx.config.values.build.enablesandbox
                or "emul32" in self.build_type
            ):
                self.actionLocals[func]()
            else:
                import catbox

                ctx.ui.info(_("Sandbox enabled build..."))

                # Configure allowed paths from sandbox.conf
                valid_paths = [self.pkg_dir()]
                conf_file = ctx.const.sandbox_conf
                if os.path.exists(conf_file):
                    for line in file(conf_file):
                        line = line.strip()
                        if len(line) > 0 and not line.startswith("#"):
                            if line.startswith("~"):
                                line = os.environ["HOME"] + line[1:]
                            valid_paths.append(line)

                # Extra path for ccache when needed
                if ctx.config.values.build.buildhelper == "ccache":
                    valid_paths.append(os.environ.get("CCACHE_DIR", "/root/.ccache"))

                ret = catbox.run(self.actionLocals[func], valid_paths, logger=self.log_sandbox_violation)
                # Retcode can be 0 while there is a sanbox violation, so only
                # look for violations to correctly handle it
                if ret.violations != []:
                    ctx.ui.error(_("Sandbox violation result:"))
                    for result in ret.violations:
                        ctx.ui.error("%s (%s -> %s)" % (result[0], result[1], result[2]))
                    raise Error(_("Sandbox violations!"))

                if ret.code == 1:
                    raise ActionScriptException
        else:
            if mandatory:
                raise Error(_("unable to call function from actions: %s") % func)

        os.chdir(curDir)
        return True
Example #3
0
    def wrapper(*__args,**__kw):
        try:
            lock = file(pisilinux.util.join_path(pisilinux.context.config.lock_dir(), 'pisilinux'), 'w')
        except IOError:
            raise pisilinux.errors.PrivilegeError(_("You have to be root for this operation."))

        try:
            fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
            ctx.locked = True
        except IOError:
            if not ctx.locked:
                raise pisilinux.errors.AnotherInstanceError(_("Another instance of pisilinux is running. Only one instance is allowed."))

        try:
            pisilinux.db.invalidate_caches()
            ret = func(*__args,**__kw)
            pisilinux.db.update_caches()
            return ret
        finally:
            ctx.locked = False
            lock.close()
Example #4
0
    def read_uri_of_repo(self, uri, repo = None, force = False):
        """Read PSPEC file"""
        if repo:
            tmpdir = os.path.join(ctx.config.index_dir(), repo)
        else:
            tmpdir = os.path.join(ctx.config.tmp_dir(), 'index')
            pisi.util.clean_dir(tmpdir)

        pisi.util.ensure_dirs(tmpdir)

        # write uri
        urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w')
        urlfile.write(uri) # uri
        urlfile.close()

        doc = self.read_uri(uri, tmpdir, force)

        if not repo:
            repo = self.distribution.name()
            # and what do we do with it? move it to index dir properly
            newtmpdir = os.path.join(ctx.config.index_dir(), repo)
            pisi.util.clean_dir(newtmpdir) # replace newtmpdir
            shutil.move(tmpdir, newtmpdir)