def __pipe(self, git_cmd, *cmd_args, **kw): kw.setdefault('stdin', PIPE) kw.setdefault('stdout', PIPE) kw.setdefault('stderr', PIPE) return Popen(self.__build_git_cmd(git_cmd, *cmd_args), close_fds=close_fds, **kw)
def _spawn_git(self, *args, **kwargs): args = map(to_utf8, (self.git_bin,) + args) kwargs.setdefault('stdin', PIPE) kwargs.setdefault('stdout', PIPE) kwargs.setdefault('stderr', PIPE) kwargs.setdefault('cwd', self.repos_path) return Popen(args, close_fds=close_fds, **kwargs)
def test_python_with_optimizations_returns_error(self): """Error is returned when a command is executed in interpreter with optimizations enabled. """ with Popen((sys.executable, '-O', '-m', 'trac.admin.console', 'help'), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds) as proc: stdout, stderr = proc.communicate(input='') self.assertEqual(2, proc.returncode) self.assertEqual("Python with optimizations is not supported.", stderr.strip())
def test_python_with_optimizations_raises_environment_error(self): """EnvironmentError exception is raised when dispatching request with optimizations enabled. """ with Popen((sys.executable, '-O', '-c', 'from trac.web.main import dispatch_request; ' 'dispatch_request({}, None)'), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds) as proc: stdout, stderr = proc.communicate() self.assertEqual(1, proc.returncode) self.assertIn("EnvironmentError: Python with optimizations is not " "supported.", stderr)
def _create_env(self, env_path, dburi): parser = RawConfigParser() parser.read(self.env.config_file_path) options = dict(((section, name), value) for section in parser.sections() for name, value in parser.items(section)) options[('trac', 'database')] = dburi options = sorted((section, name, value) for (section, name), value in options.iteritems()) class MigrateEnvironment(Environment): abstract = True required = False def is_component_enabled(self, cls): name = self._component_name(cls) if not any( name.startswith(mod) for mod in ('trac.', 'tracopt.')): return False return Environment.is_component_enabled(self, cls) # create an environment without plugins env = MigrateEnvironment(env_path, create=True, options=options) env.shutdown() # copy plugins directory os.rmdir(env.plugins_dir) shutil.copytree(self.env.plugins_dir, env.plugins_dir) # create tables for plugins to upgrade in other process with Popen( (sys.executable, '-m', 'trac.admin.console', env_path, 'upgrade'), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds) as proc: stdout, stderr = proc.communicate(input='') if proc.returncode != 0: raise TracError("upgrade command failed (stdout %r, stderr %r)" % (stdout, stderr)) return Environment(env_path)