Example #1
0
    def calf(self, spec):
        """
        Typical safe usage is this, which sets everything that could be
        problematic up.

        Requires the filename which everything will be produced to.
        """

        if not isinstance(spec, Spec):
            raise TypeError('spec must be of type Spec')

        if not spec.get('build_dir'):
            tempdir = realpath(mkdtemp())
            spec.add_callback('cleanup', shutil.rmtree, tempdir)
            build_dir = join(tempdir, 'build')
            mkdir(build_dir)
            spec['build_dir'] = build_dir
        else:
            if not exists(spec['build_dir']):
                raise_os_error(errno.ENOTDIR)
            check = realpath(spec['build_dir'])
            if check != spec['build_dir']:
                spec['build_dir'] = check
                logger.warning(
                    "realpath of build_dir resolved to '%s', spec is updated",
                    check
                )

        try:
            self._calf(spec)
        finally:
            spec.do_callbacks('cleanup')
Example #2
0
    def test_raise_os_error_not_dir_with_path(self):
        e = OSError if sys.version_info < (
            3, 3) else NotADirectoryError  # noqa: F821
        with self.assertRaises(e) as exc:
            raise_os_error(errno.ENOTDIR, 'some_path')

        self.assertIn("Not a directory: 'some_path'", str(exc.exception))
Example #3
0
    def test_raise_os_error_not_dir(self):
        e = OSError if sys.version_info < (
            3, 3) else NotADirectoryError  # noqa: F821
        with self.assertRaises(e) as exc:
            raise_os_error(errno.ENOTDIR)

        self.assertIn('Not a directory', str(exc.exception))
Example #4
0
def _get_exec_binary(binary, kw):
    """
    On win32, the subprocess module can only reliably resolve the
    target binary if it's actually a binary; as for a Node.js script
    it seems to only work iff shell=True was specified, presenting
    a security risk.  Resolve the target manually through which will
    account for that.

    The kw argument is the keyword arguments that will be passed into
    whatever respective subprocess.Popen family of methods.  The PATH
    environment variable will be used if available.
    """

    binary = which(binary, path=kw.get('env', {}).get('PATH'))
    if binary is None:
        raise_os_error(errno.ENOENT)
    return binary
Example #5
0
 def test_raise_os_error_not_dir(self):
     e = OSError if sys.version_info < (
         3, 0) else NotADirectoryError  # noqa: F821
     with self.assertRaises(e):
         raise_os_error(errno.ENOTDIR)
Example #6
0
 def test_raise_os_error_file_not_found(self):
     e = OSError if sys.version_info < (
         3, 0) else FileNotFoundError  # noqa: F821
     with self.assertRaises(e):
         raise_os_error(errno.ENOENT)
Example #7
0
 def test_raise_os_error_file_not_found(self):
     e = OSError if sys.version_info < (
         3, 3) else FileNotFoundError  # noqa: F821
     with self.assertRaises(e):
         raise_os_error(errno.ENOENT)