Exemplo n.º 1
0
    def dotfiles(self, paths):
        """Return a collection of dotfiles given a list of paths.

        This function takes a list of paths where each path can be a file or a
        directory.  Each directory is recursively expaned into file paths.
        Once the list is converted into only files, dotifles are constructed
        for each path in the set.  This set of dotfiles is returned to the
        caller.
        """

        paths = list(set(map(py.path.local, paths)))

        for path in paths:
            if path.check(dir=1):
                paths.extend(self._contents(path))
                paths.remove(path)

        def construct(path):
            try:
                return self._dotfile(path)
            except DotfileException as err:
                click.echo(err)
                return None

        return [d for d in map(construct, paths) if d is not None]
Exemplo n.º 2
0
def _is_doctest(config, path, parent):
    if path.ext in (".txt", ".rst") and parent.session.isinitpath(path):
        return True
    globs = config.getoption("doctestglob") or ["test*.txt"]
    for glob in globs:
        if path.check(fnmatch=glob):
            return True
    return False
Exemplo n.º 3
0
def samples_dir(request):
    """Get path of local samples dir (scope: function).

    The path is delivered as `py.path.local` path for your
    convenience.
    """
    path = py.path.local(__file__).dirpath("input")
    assert path.check()  # make sure the path exists really
    return path
Exemplo n.º 4
0
def samples_dir(request):
    """Get path of local samples dir (scope: function).

    The path is delivered as `py.path.local` path for your
    convenience.
    """
    path = py.path.local(__file__).dirpath("input")
    assert path.check()  # make sure the path exists really
    return path
Exemplo n.º 5
0
    def path_mtime(self, handle, path):
        """
        Set the mtime on the given path, writitng messages to the file handle
        given as necessary
        """
        # Ensure path is inside workdir
        if not path_contained(self.workdir, path):
            write_all(handle,
                      "%s not in the workdir; failing" % path.strpath)
            return False

        if not path.check():
            return True

        # Show the file, relative to workdir
        relpath = self.workdir.bestrelpath(path)
        write_all(handle, "%s: " % relpath)

        try:
            timestamp = self.timestamp_for(path)

        except subprocess.CalledProcessError as ex:
            # Something happened with the git command
            write_all(handle, [
                "Could not retrieve commit time from git. Exit "
                "code %d:\n" % ex.returncode,

                ex.output,
            ])
            return False

        except ValueError as ex:
            # A non-int value returned
            write_all(handle,
                      "Unexpected output from git: %s\n" % ex.args[0])
            return False

        # User output
        mtime = datetime.datetime.fromtimestamp(timestamp)
        write_all(handle, "%s... " % mtime.strftime('%Y-%m-%d %H:%M:%S'))

        # Set the time!
        extra = recursive_mtime(path, timestamp)

        extra_txt = ("(and %d more) " % extra) if extra > 0 else ""
        handle.write("{}DONE!\n".format(extra_txt).encode())
        if path.samefile(self.workdir):
            write_all(
                handle,
                "** Note: Performance benefits may be gained by adding "
                "only necessary files, rather than the whole source tree "
                "**\n",
            )

        return True
Exemplo n.º 6
0
def default_host(format_string, local_default=None):
    """
    Get a default host. If running in Docker, we get the default gateway, and
    use format string with the IP. Otherwise, returns the ``local_default``
    """
    docker_files = [py.path.local(path)
                    for path in ('/.dockerenv', '/.dockerinit')]
    if any(path.check() for path in docker_files):
        return format_string.format(ip=default_gateway())

    return local_default
Exemplo n.º 7
0
def load_yaml(filename=None):
    # Find the requested yaml in the config dir, relative to this file's location
    # (aiming for cfme_tests/config)
    this_file = os.path.abspath(__file__)
    path = py.path.local(this_file).new(basename='../conf/%s.yaml' % filename)

    if path.check():
        with path.open() as config_fh:
            return yaml.load(config_fh, Loader=OrderedYamlLoader)
    else:
        msg = 'Unable to load configuration file at %s' % path
        raise ConfigNotFoundException(msg)
Exemplo n.º 8
0
def default_docker_host(format_string, local_default=None):
    """
    Get a default value for the docker_host variable. This will work out
    if DockCI is running in Docker, and try and guess the Docker IP address
    to use for a TCP connection. Otherwise, defaults to the default
    unix socket.
    """
    docker_files = [py.path.local(path)
                    for path in ('/.dockerenv', '/.dockerinit')]
    if any(path.check() for path in docker_files):
        return format_string.format(ip=default_gateway())

    return local_default
Exemplo n.º 9
0
    def _dotfile(self, path):
        """Return a valid dotfile for the given path."""
        target = self._dotfile_target(path)

        if not path.fnmatch('%s/*' % self.homedir):
            raise NotRootedInHome(path)
        if path.fnmatch('%s/*' % self.path):
            raise InRepository(path)
        if self._ignore(target):
            raise TargetIgnored(path)
        if path.check(dir=1):
            raise IsDirectory(path)

        return Dotfile(path, target)
Exemplo n.º 10
0
    def _dotfile(self, path):
        """Return a valid dotfile for the given path."""
        target = self._dotfile_target(path)

        if not path.fnmatch('%s/*' % self.homedir):
            raise NotRootedInHome(path)
        if path.fnmatch('%s/*' % self.path):
            raise InRepository(path)
        if self._ignore(target):
            raise TargetIgnored(path)
        if path.check(dir=1):
            raise IsDirectory(path)

        return Dotfile(path, target)
Exemplo n.º 11
0
    def add_module(self, name, init=True):
        # type: (str) -> py.path.local
        """"Adds a libtbx module to the environment paths.

        Args:
            name: The module name. A path will be created.

        Returns:
            The dist path for the new module.
        """
        path = self._dist_path / name
        if not path.check():
            path.mkdir()
        if init:
            (path / "__init__.py").ensure(file=True)
        self.module_list.append(FakeLibTBXModule(name, path))
        self.module_dist_paths[name] = path
        return path
Exemplo n.º 12
0
 def job_output_details(self):
     """
     Details for job output artifacts
     """
     # pylint:disable=no-member
     output_files = (
         (name, self.job_output_path().join('%s.tar' % name))
         for name in self.job_config.job_output.keys()
     )
     return {
         name: {'size': bytes_human_readable(path.size()),
                'link': url_for('job_output_view',
                                project_slug=self.project.slug,
                                job_slug=self.slug,
                                filename='%s.tar' % name,
                                ),
                }
         for name, path in output_files
         if path.check(file=True)
     }
Exemplo n.º 13
0
    def dotfiles(self, paths):
        """Return a collection of dotfiles given a list of paths.

        This function takes a list of paths where each path can be a file or a
        directory.  Each directory is recursively expaned into file paths.
        Once the list is converted into only files, dotifles are constructed
        for each path in the set.  This set of dotfiles is returned to the
        caller.
        """
        paths = list(set(map(py.path.local, paths)))

        for path in paths:
            if path.check(dir=1):
                paths.extend(self._contents(path))
                paths.remove(path)

        def construct(path):
            try:
                return self._dotfile(path)
            except DotfileException as err:
                click.echo(err)
                return None

        return [d for d in map(construct, paths) if d is not None]
Exemplo n.º 14
0
def exists(path, ignore=EnvironmentError):
    try:
        return path.check()
    except ignore:
        return False