skip to navigation
skip to content

Not Logged In

treeshape 0.2.1

Quickly make files and directory structures.

treeshape allows you to quickly make file and directory structures on disk.

For example:

from treeshape import (
    CONTENT,
    make_tree,
    PERMISSIONS,
    )

make_tree('.', {
    'logs/': None,
    'README': {CONTENT: "A simple directory layout\n"},
    'data/input': {CONTENT: "All of our input data\n"},
    'bin/script': {CONTENT: "#!/bin/sh\necho 'Hello'\n", PERMISSIONS: 0755},
    })

Will create a directory structure that looks like this:

$ find .
.
./logs
./data
./data/input
./README
$ cat README
A simple directory layout
$ cat data/input
All of our input data

This is particularly useful for tests that touch the disk.

If being explicit isn't really your thing, you can also create the same directory structure from a rough specification:

from treeshape import (
    from_rough_spec,
    make_tree,
    )

make_tree('.', from_rough_spec([
    'logs/',
    ('README', "A simple directory layout\n"),
    ('data/input', "All of our input data\n"),
    ('bin/script', "#!/bin/sh\necho 'Hello'\n", 0755),
    ]))

This is also provided as a Fixture (see python-fixtures). Thus, if you are using testtools, then you can also do this during your tests:

def test_a_thing(self):
    self.useFixture(FileTree(from_rough_spec([
        'logs/',
        ('README', "A simple directory layout\n"),
        ('data/input', "All of our input data\n"),
        ])))
    # your test here
 
File Type Py Version Uploaded on Size
treeshape-0.2.1.tar.gz (md5) Source 2012-09-03 9KB
  • Downloads (All Versions):
  • 8 downloads in the last day
  • 53 downloads in the last week
  • 292 downloads in the last month