Skip to main content

Build Status Coveralls Documentation Status Pypi status Gitter License

Description

Create a random file and directory tree/structure for testing purposes.

Installation

AnkiPandas can be installed with the python package manager:

pip3 install randomfiletree

For a local installation, you might want to use the --user switch of pip. You can also update your current installation with pip3 install --upgrade ankipandas.

For the latest development version you can also work from a cloned version of this repository:

git clone https://github.com/klieret/randomfiletree/
cd randomfiletree
pip3 install --user .

Usage

Simple command line interface:

randomfiletree <folder> -f <file creation probability> -d <directory creation probability> -r <repeat>

Type randomfiletree -h to see all supported arguments.

If the executable is not in your path after installation, you can also use python3 -m randomfiletree <arguments as above>.

import randomfiletree

randomfiletree.iterative_gaussian_tree(
    "/path/to/basedir",
    nfiles=2.0,
    nfolders=0.5,
    maxdepth=5,
    repeat=4
)

Randomfiletree will now crawl through all directories in /path/to/basedir and create new files with the probabilities given in the arguments.

It is possible to pass an optional function to generate the random filenames oneself:

import random
import string

def fname():
    length = random.randint(5, 10)
    return "".join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(length)
    ) + '.docx'

randomfiletree.core.iterative_gaussian_tree(
    "/path/to/basedir",
    nfiles=100,
    nfolders=10,
    maxdepth=2,
    filename=fname
)

The payload optional argument can be used to generate file contents together with their names. For example, it can be used to replicate some template files with randomized names:

import itertools
import pathlib
import randomfiletree

def callback(target_dir: pathlib.Path) -> pathlib.Path:
    sourcedir = pathlib.Path("/path/to/templates/")
    sources = []
    for srcfile in sourcedir.iterdir():
        with open(srcfile, 'rb') as f:
            content = f.read()
        sources.append((srcfile.suffix, content))
    for srcfile in itertools.cycle(sources):
        path = target_dir / (randomfiletree.core.random_string() + srcfile[0])
        with path.open('wb') as f:
            f.write(srcfile[1])
        yield path

randomfiletree.core.iterative_gaussian_tree(
    "/path/to/basedir",
    nfiles=10,
    nfolders=10,
    maxdepth=5,
    repeat=4,
    payload=callback
)

if both filename and payload passed, the first option is ignored.

Take a look at the documentation to find out more about the additional functionality provided.

License

This software is lienced under the MIT license.

Metadata

Release files for RandomFileTree 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for RandomFileTree 1.2.0
File Size Uploaded
RandomFileTree-1.2.0.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for RandomFileTree 1.2.0
File Interpreter ABI Platform
RandomFileTree-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / RandomFileTree-1.2.0.tar.gz

Download URL RandomFileTree-1.2.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3a92e12ecbf093dc6b3fc1405c69030ed32db3a8a4a71f28724bd347f4c49afc
BLAKE2b-256 checksum
How to use checksums
8d720ffefe0e5a4d9c9c289947f8ee9467cf66780cfd5c2346b8b1ad4ba84944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

Release files / RandomFileTree-1.2.0-py3-none-any.whl

Download URL RandomFileTree-1.2.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c22868879754231452c715b97829a6ddb1d5d59941ed05822f7a0285204c8fe
BLAKE2b-256 checksum
How to use checksums
348d436df1300452ef6991aa5013fc75356f14ccb94dfacedc58f2139e935358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page