Skip to main content

Quickly make files and directory structures.

Project description

-*- rst -*-
===========
treeshape
===========

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


.. _python-fixtures: http://pypi.python.org/pypi/fixtures
.. _testtools: http://pypi.python.org/pypi/testtools

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

treeshape-0.2.0.tar.gz (9.4 kB view details)

Uploaded Source

File details

Details for the file treeshape-0.2.0.tar.gz.

File metadata

  • Download URL: treeshape-0.2.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for treeshape-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8b34a36230d86f5c7043b52a9d258662b82d8df00c52abea07b923d3e999191e
MD5 3b5d6778e147c411376815264ffa073c
BLAKE2b-256 5e0afc928da8b3ad0475c611abc02612660a58671dcd660416698b88b4e7d51b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page