Exemplo n.º 1
0
def test_more_walk():
    """
    Ensure s'more basics in walking a directory, with an extention
    filter.
    """
    with tmpdir() as t:
        with cd(t):
            mkdir("foo")
            mkdir("bar")
            mkdir("baz")

            valid_targets = ["./foo/bar.target", "./bar/foo.target", "./kruft.target"]

            invalid_targets = ["./foo/bar", "./baz/foo", "./kruft"]
            invalid_cmp = list(invalid_targets)

            for target in valid_targets + invalid_targets:
                touch(target)

            for entry in dir_walk("./", xtn="target"):
                if entry in valid_targets:
                    valid_targets.remove(entry)
                if entry in invalid_targets:
                    invalid_targets.remove(entry)

        assert valid_targets == []
        assert invalid_targets == invalid_cmp
Exemplo n.º 2
0
def test_basic_walk():
    """
    Test to make sure we can walk a directory.
    """
    with tmpdir() as t:
        with cd(t):
            mkdir("foo")
            mkdir("bar")
            mkdir("baz")

            targets = ["./foo/bar.target", "./foo/bar", "./bar/foo.target", "./baz/foo"]

            for target in targets:
                touch(target)

            for entry in dir_walk("./"):
                assert entry in targets
                targets.remove(entry)

        assert targets == []
Exemplo n.º 3
0
    def render(self, dest):
        """
        `dest' is a path (abs or rel) to the output directory, or where to
        write the model files to. Be extra-sure to call setContext on this
        particular class, it's important to render out the Jinja context
        correctly.
        """
        dest = abspath(dest)

        if self.context is None:
            raise ValueError("No context set for this JinjaTemplate")

        with tmpdir() as tmp:
            PlainTemplate.render(self, tmp)
            for template in dir_walk(tmp, xtn=".tpl"):
                with open(template, 'r') as fd:
                    tobj = Template(fd.read())
                    with open(template.rsplit(".", 1)[0], 'w') as obj:
                        obj.write(tobj.render(**self.context))
                rm(template)
            rsync(tmp, dest)