Directory layout object for testing and documentation
Project description
dirlay
Directory layout object for testing and documentation
Features
- Create and remove directory tree with files
- Chdir to layout subdirectories
- Display as rich tree for docs
- Uses pathlib2 for Python 2
Installation
$ pip install dirlay[rich]
Usage
>>> from dirlay import DirectoryLayout, to_tree
Create directory layout tree
>>> layout = DirLayout({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> layout.basedir is None
True
>>> layout.mktree()
>>> layout.basedir
PosixPath('/tmp/...')
And remove when not needed anymore:
>>> layout.rmtree()
Chdir to subdirectory
>>> import os
>>> os.chdir('/tmp')
When layout is instantiated, current directory remains unchanged:
>>> layout = DirLayout({'a': {'b/c.txt': 'ccc'}})
>>> layout.mktree()
>>> layout.getcwd()
PosixPath('/tmp')
On first chdir, initial working directory is stored internally, and will be
restored on rmtree. Without argument, chdir sets current directory to
layout.basedir.
>>> layout.basedir
PosixPath('/tmp/...')
>>> layout.chdir()
>>> layout.getcwd()
PosixPath('/tmp/...')
If chdir has argument, it must be a path relative to basedir.
>>> layout.chdir('a/b')
>>> layout.getcwd()
PosixPath('/tmp/.../a/b')
When directory is removed, current directory is restored:
>>> layout.rmtree()
>>> layout.getcwd()
PosixPath('/tmp')
Print as tree
>>> layout = DirLayout({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> layout.print_tree()
๐ .
โโโ ๐ a
โโโ ๐ b
โ โโโ ๐ c.txt
โโโ ๐ d.txt
Display basedir path and file contents:
>>> layout.mktree()
>>> layout.print_tree(real_basedir=True, show_content=True)
๐ /tmp/...
โโโ ๐ a
โโโ ๐ b
โ โโโ ๐ c.txt
โ โญโโโโโโฎ
โ โ ccc โ
โ โฐโโโโโโฏ
โโโ ๐ d.txt
โญโโโโโโฎ
โ ddd โ
โฐโโโโโโฏ
Extra keyword aguments will be passed through to rich.tree.Tree:
>>> layout.print_tree(real_basedir=True, show_content=True, hide_root=True)
๐ a
โโโ ๐ b
โ โโโ ๐ c.txt
โ โญโโโโโโฎ
โ โ ccc โ
โ โฐโโโโโโฏ
โโโ ๐ d.txt
โญโโโโโโฎ
โ ddd โ
โฐโโโโโโฏ
See also
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dirlay-0.2.0.tar.gz.
File metadata
- Download URL: dirlay-0.2.0.tar.gz
- Upload date:
- Size: 93.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7310e81538a0a9c2fcf734056bcbe47ab302cc1945926039853d6bc2d3e99972
|
|
| MD5 |
e3f4812985783fa928927c40d274bcdd
|
|
| BLAKE2b-256 |
71d91fb630a732e691107cca48ea29e0d3433a21bc7ceb3a0b64d97149571e44
|
File details
Details for the file dirlay-0.2.0-py2.py3-none-any.whl.
File metadata
- Download URL: dirlay-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb8a25b95778b235b41a2a23b1a730f01c15ec11d5e7323a09cd3b9922dd0c2d
|
|
| MD5 |
af09723e1cc3dc15513a66b98b3ccc3e
|
|
| BLAKE2b-256 |
b67b6b4b237f2565f5f72e337540401e13e32284ef9b533b5d24c03fae23f74f
|