def call2(self, *args): for arg in args: self.assertTrue(is_fsnative(arg)) old_stdout = sys.stdout old_stderr = sys.stderr try: out = StringIO() err = StringIO() sys.stdout = out sys.stderr = err try: ret = self._main([fsnative(self.TOOL_NAME)] + list(args)) except SystemExit as e: ret = e.code ret = ret or 0 out_val = out.getvalue() err_val = err.getvalue() if os.name == "nt" and PY2: encoding = getattr(sys.stdout, "encoding", None) or "utf-8" out_val = text_type(out_val, encoding) err_val = text_type(err_val, encoding) return (ret, out_val, err_val) finally: sys.stdout = old_stdout sys.stderr = old_stderr
def get_var(tool_name, entry="main"): tool_path = os.path.join( mutagen.__path__[0], "..", "tools", fsnative(tool_name)) dont_write_bytecode = sys.dont_write_bytecode sys.dont_write_bytecode = True try: mod = imp.load_source(tool_name, tool_path) finally: sys.dont_write_bytecode = dont_write_bytecode return getattr(mod, entry)
def get_var(tool_name, entry="main"): tool_path = os.path.join( mutagen.__path__[0], "..", "tools", fsnative(tool_name)) dont_write_bytecode = sys.dont_write_bytecode sys.dont_write_bytecode = True try: with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) mod = imp.load_source(tool_name, tool_path) finally: sys.dont_write_bytecode = dont_write_bytecode return getattr(mod, entry)