Example #1
0
    def __init__(self, env=None, workspace=None, name='.env', python=None, args=None):
        Workspace.__init__(self, workspace)
        self.virtualenv = self.workspace / name
        self.args = args or []
        if sys.platform == 'win32':
            # In virtualenv on windows "Scripts" folder is used instead of "bin".
            self.python = self.virtualenv / 'Scripts' / 'python.exe'
            self.easy_install = self.virtualenv / 'Scripts' / 'easy_install.exe'
            self.coverage = self.virtualenv / 'Scripts' / 'coverage.exe'
        else:
            self.python = self.virtualenv / 'bin' / 'python'
            self.easy_install = self.virtualenv / "bin" / "easy_install"
            self.coverage = self.virtualenv / 'bin' / 'coverage'

        if env is None:
            self.env = dict(os.environ)
        else:
            self.env = dict(env)  # ensure we take a copy just in case there's some modification

        self.env['VIRTUAL_ENV'] = str(self.virtualenv)

        self.env['PATH'] = str(self.python.dirname()) + ((os.path.pathsep + self.env["PATH"])
                                                         if "PATH" in self.env else "")
        if 'PYTHONPATH' in self.env:
            del(self.env['PYTHONPATH'])

        self.virtualenv_cmd = CONFIG.virtualenv_executable
        if isinstance(self.virtualenv_cmd, str):
            cmd = [self.virtualenv_cmd]
        else:
            cmd = list(self.virtualenv_cmd)
        cmd.extend(['-p', python or cmdline.get_real_python_executable()])
        cmd.extend(self.args)
        cmd.append(str(self.virtualenv))
        self.run(cmd)
    def __init__(self, env=None, workspace=None, name='.env', python=None):
        Workspace.__init__(self, workspace)
        self.virtualenv = self.workspace / name
        if sys.platform == 'win32':
            # In virtualenv on windows "Scripts" folder is used instead of "bin".
            self.python = self.virtualenv / 'Scripts' / 'python.exe'
            self.easy_install = self.virtualenv / 'Scripts' / 'easy_install.exe'
            self.coverage = self.virtualenv / 'Scripts' / 'coverage.exe'
        else:
            self.python = self.virtualenv / 'bin' / 'python'
            self.easy_install = self.virtualenv / "bin" / "easy_install"
            self.coverage = self.virtualenv / 'bin' / 'coverage'

        if env is None:
            self.env = dict(os.environ)
        else:
            self.env = dict(env)  # ensure we take a copy just in case there's some modification

        self.env['VIRTUAL_ENV'] = str(self.virtualenv)

        self.env['PATH'] = str(self.python.dirname()) + ((os.path.pathsep + self.env["PATH"])
                                                         if "PATH" in self.env else "")
        if 'PYTHONPATH' in self.env:
            del(self.env['PYTHONPATH'])

        self.virtualenv_cmd = CONFIG.virtualenv_executable
        self.run([self.virtualenv_cmd,
                 '-p', python or cmdline.get_real_python_executable(),
                 str(self.virtualenv)])
    def __init__(self, env=None, workspace=None, name='.env', python=None):
        Workspace.__init__(self, workspace)
        self.virtualenv = self.workspace / name
        self.python = self.virtualenv / 'bin' / 'python'
        self.easy_install = self.virtualenv / "bin" / "easy_install"

        if env is None:
            self.env = dict(os.environ)
        else:
            self.env = dict(env)  # ensure we take a copy just in case there's some modification

        self.env['VIRTUAL_ENV'] = self.virtualenv
        self.env['PATH'] = os.path.dirname(self.python) + ((os.path.pathsep + self.env["PATH"])
                                                           if "PATH" in self.env else "")
        if 'PYTHONPATH' in self.env:
            del(self.env['PYTHONPATH'])

        self.virtualenv_cmd = CONFIG.virtualenv_executable
        self.run('%s -p %s %s --distribute' % (self.virtualenv_cmd,
                                               python or cmdline.get_real_python_executable(),
                                               self.virtualenv))
    def __init__(self, env=None, workspace=None, name='.env', python=None):
        Workspace.__init__(self, workspace)
        self.virtualenv = self.workspace / name
        self.python = self.virtualenv / 'bin' / 'python'
        self.easy_install = self.virtualenv / "bin" / "easy_install"

        if env is None:
            self.env = dict(os.environ)
        else:
            self.env = dict(
                env
            )  # ensure we take a copy just in case there's some modification

        self.env['VIRTUAL_ENV'] = self.virtualenv
        self.env['PATH'] = os.path.dirname(self.python) + (
            (os.path.pathsep + self.env["PATH"]) if "PATH" in self.env else "")
        if 'PYTHONPATH' in self.env:
            del (self.env['PYTHONPATH'])

        self.virtualenv_cmd = CONFIG.virtualenv_executable
        self.run('%s -p %s %s --distribute' %
                 (self.virtualenv_cmd, python
                  or cmdline.get_real_python_executable(), self.virtualenv))
Example #5
0
    def __init__(self):
        tmpdir = mkdtemp(prefix='XvfbServer.',
                         dir=Workspace.get_base_tempdir())
        for servernum in range(os.getpid(), 65536):
            if os.path.exists('/tmp/.X{0}-lock'.format(servernum)):
                continue
            self.display = ':' + str(servernum)
            self.authfile = os.path.join(tmpdir, 'Xauthority.' + self.display)
            mcookie = codecs.encode(os.urandom(16), "hex_codec")
            subprocess.check_call([
                'xauth', '-f', self.authfile, 'add', self.display, '.', mcookie
            ])
            errfile = os.path.join(tmpdir, 'Xvfb.' + self.display + '.err')
            with open(
                    errfile, 'w'
            ) as f:  # use a file instead of a pipe to simplify polling
                p = subprocess.Popen(
                    [self.xvfb_command, self.display, '-fbdir', tmpdir] +
                    self.xvfb_args,
                    stderr=f,
                    env=dict(os.environ, XAUTHORITY=self.authfile))
                self.fbmem = os.path.join(tmpdir, 'Xvfb_screen0')
                while not os.path.exists(self.fbmem):
                    if p.poll() is not None:
                        break
                    time.sleep(0.1)
                else:
                    p.poll()
                if p.returncode is not None:
                    with open(errfile) as f:
                        err = f.read()
                    if 'Server is already active for display' in err:
                        continue
                    else:
                        raise RuntimeError('Failed to start Xvfb',
                                           p.returncode, err)
            print('Xvfb started in ' + tmpdir)  # for debugging
            self.process = p
            # If we terminate abnormally, ensure the Xvfb server is cleaned up after us.
            self._cleanup_script = subprocess.Popen("""
while kill -0 {0} 2>/dev/null; do sleep 1; done
kill -INT {1}
while kill -0 {1} 2>/dev/null; do sleep 1; done
""".format(os.getpid(), p.pid),
                                                    shell=True)
            break
        else:
            raise RuntimeError(
                'Unable to find a free server number to start Xvfb')
Example #6
0
    def __init__(self):
        tmpdir = mkdtemp(prefix='XvfbServer.', dir=Workspace.get_base_tempdir())
        for servernum in range(os.getpid(), 65536):
            if os.path.exists('/tmp/.X{0}-lock'.format(servernum)):
                continue
            self.display = ':' + str(servernum)
            self.authfile = os.path.join(tmpdir, 'Xauthority.' + self.display)
            mcookie = codecs.encode(os.urandom(16), "hex_codec")
            subprocess.check_call(['xauth', '-f', self.authfile, 'add', self.display, '.', mcookie])
            errfile = os.path.join(tmpdir, 'Xvfb.' + self.display + '.err')
            with open(errfile, 'w') as f:  # use a file instead of a pipe to simplify polling
                p = subprocess.Popen([self.xvfb_command, self.display, '-fbdir', tmpdir] + self.xvfb_args,
                                     stderr=f, env=dict(os.environ, XAUTHORITY=self.authfile))
                self.fbmem = os.path.join(tmpdir, 'Xvfb_screen0')
                while not os.path.exists(self.fbmem):
                    if p.poll() is not None:
                        break
                    time.sleep(0.1)
                else:
                    p.poll()
                if p.returncode is not None:
                    with open(errfile) as f:
                        err = f.read()
                    if 'Server is already active for display' in err:
                        continue
                    else:
                        raise RuntimeError('Failed to start Xvfb', p.returncode, err)
            print('Xvfb started in ' + tmpdir)  # for debugging
            self.process = p
            # If we terminate abnormally, ensure the Xvfb server is cleaned up after us.
            self._cleanup_script = subprocess.Popen("""
while kill -0 {0} 2>/dev/null; do sleep 1; done
kill -INT {1}
while kill -0 {1} 2>/dev/null; do sleep 1; done
""".format(os.getpid(), p.pid), shell=True)
            break
        else:
            raise RuntimeError('Unable to find a free server number to start Xvfb')
def svn_workdir(svn_repo):
  workdir = Workspace()
  workdir.run("svn co {}".format(svn_repo.uri))
  yield (workdir, svn_repo)
  workdir.teardown()
Example #8
0
def workdir():
  workdir = Workspace()
  yield workdir
  workdir.teardown()