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, PiSi 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 patterns.items(): if name in keeplist: continue if 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))
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, PiSi 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 patterns.items(): if name in keeplist: continue if 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))
def exclude_special_files(filepath, fileinfo, install_dir, ag): keeplist = [] if not ag.has_key('KeepSpecial') else ag['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, # PiSi 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 pattern in patterns.keys(): if not pattern in keeplist and re.match(patterns[pattern], fileinfo): ctx.ui.debug("Removing special %s file: %s" % (pattern, filepath)) os.unlink(filepath)
def exclude_special_files(filepath, fileinfo, ag): keeplist = [] if not ag.has_key('KeepSpecial') else ag['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, # PiSi 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 pattern in patterns.keys(): if not pattern in keeplist and re.match(patterns[pattern], fileinfo): ctx.ui.debug("Removing special %s file: %s" % (pattern, filepath)) os.unlink(filepath)
def wrapper(*__args, **__kw): try: lock = file( pisi.util.join_path(pisi.context.config.lock_dir(), 'pisi'), 'w') except IOError: raise pisi.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 pisi.errors.AnotherInstanceError( _("Another instance of io is running. Only one instance is allowed." )) try: pisi.db.invalidate_caches() ret = func(*__args, **__kw) pisi.db.update_caches() return ret finally: ctx.locked = False lock.close()
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.check_dir(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) # check packages' DistributionReleases and Architecture if not ctx.get_option("ignore_check"): self.check_distribution_and_architecture(doc) 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)
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 pisi.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: 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
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 pisi.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: 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
def wrapper(*__args,**__kw): try: lock = file(pisi.util.join_path(pisi.context.config.lock_dir(), 'pisi'), 'w') except IOError: raise pisi.errors.PrivilegeError(_("You have to be root for this operation.")) try: fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: raise pisi.errors.AnotherInstanceError(_("Another instance of PiSi is running. Only one instance is allowed.")) try: return func(*__args,**__kw) finally: lock.close()
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 pisi.build.Error will be raised.""" # we'll need our working directory after actionscript # finished its work in the archive source directory. curDir = os.getcwd() os.chdir(self.srcDir) if func in self.actionLocals: if ctx.get_option("ignore_sandbox") or not ctx.config.values.build.enablesandbox: 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("%s/.ccache" % os.environ["HOME"]) ret = catbox.run(self.actionLocals[func], valid_paths, logger=self.log_sandbox_violation) if ret.code == 1 or ret.violations != []: raise Error(_("Sandbox violations!")) else: if mandatory: raise Error(_("unable to call function from actions: %s") % func) os.chdir(curDir) return True
def wrapper(*__args,**__kw): try: lock = file(pisi.util.join_path(pisi.context.config.lock_dir(), 'pisi'), 'w') except IOError: raise pisi.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 pisi.errors.AnotherInstanceError(_("Another instance of eopkg is running. Only one instance is allowed.")) try: pisi.db.invalidate_caches() ret = func(*__args,**__kw) pisi.db.update_caches() return ret finally: ctx.locked = False lock.close()
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.check_dir(tmpdir) # write uri urlfile = file(pisi.util.join_path(tmpdir, "uri"), "w") urlfile.write(uri) # uri urlfile.close() 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)
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.check_dir(tmpdir) # write uri urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w') urlfile.write(uri) # uri urlfile.close() 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)