Skip to main content

Generate a fake file system to create documentation examples.

Project description

Fictus

Use Fictus to create and output a fictitious file system for sharing in a text driven format.

🏡kitchen:\
└─ 📁drawer
   ├─ 📁forks
   │  ├─ 📁old
   │  │  └─ 📄pitchfork.bak
   │  ├─ 📄dinner.mp3
   │  └─ 📄salad.mov
   └─ 📁spoons
      └─ 📄ladle.psd

Use cases include creating output for a wiki page, communicating a folder structure to a colleague over chat, or mocking a file/folder structure layout before committing to actual creation on disk. Since Fictus mimics a File System, calling code can create complex loops to build up as little or as much as required to get an idea across.

If needed the virtual file system can be used to create a physical representation on the physical disk.


FictusFileSystem

A Fictus File System starts with instantiating a FictusFileSystem object and, optionally, providing a root drive name. If one is not provided, a single slash ('/') will be used.

from fictus import FictusFileSystem

# Create a FictusFileSystem.
ffs = FictusFileSystem("c:")

The object can then be built up using creation methods, such as mdir and mkfile and folder traversal can occur using cd.

# create some directories
ffs.mkdir("/files/docs")
ffs.mkdir("/files/music/folk")

# Create some files in the current working directory (happens to be root).
ffs.mkfile("README.md", "LICENSE.md", ".ignore")

# Change directory to the `docs` and make more files. Start with `/` to traver from root.
ffs.cd("/files/docs")
ffs.mkfile("resume.txt", "recipe.wrd")

# Change directory to `music/folk`.  Note the relative cd from the `docs` folder. 
ffs.cd("../music/folk")
ffs.mkfile("bing.mp3", "bang.mp3", "bop.wav")

A FictusFileSystem can also be generated based on a real world drive setup. If needed, additional edits can be made after to add or rename data.

from pathlib import Path  # this class method requires a Path object

from fictus import FictusFileSystem

local_path = Path(r"c:\temp")
ffs = FictusFileSystem.init_from_path(local_path)

FictusDisplay

A FictusDisplay outputs the FFS.

from fictus import FictusDisplay

ffs.cd("/")  # for this example, ensure the cwd is the root of the file system

# Generate a ffs structure to be printed to stdout as text.
display = FictusDisplay(ffs)
display.pprint()

Produces:

c:\
├─ files\
│  ├─ docs\
│  │  ├─ recipe.wrd
│  │  └─ resume.txt
│  └─ music\
│     └─ folk\
│        ├─ bang.mp3
│        ├─ bing.mp3
│        └─ bop.wav
├─ .ignore
├─ LICENSE.md
└─ README.md

The display can also be generated in place:

FictusDisplay(ffs).pprint()

The tree displayed starts at current working directory. The same example above with the current directory set to c:/files/music produces:

music\
└─ folk\
   ├─ bang.mp3
   ├─ bing.mp3
   └─ bop.wav

The display can also be used to generate a physical representation of the Fictus File System.

from pathlib import Path
path = Path("c:\\fictus")
FictusDisplay(ffs).reforestation(path)

This will create all folders and files represented in the FFS under the path provided. File internals will be
an empty utf-8 string.


Renderer

A FictusDisplay allows customization of the DOC, ROOT, FOLDER, and FILE types. The Renderer can be permanently reassigned using the renderer property. Here is an example that takes advantage of the built-in emojiRenderer.

from fictus.renderer import emojiRenderer
...
# FictusDisplay the ffs structure after a relative change of directory to files/music
ffs.cd("files/music")

# assign a new Renderer to the display - already instantiated in a previous example.
display.renderer = emojiRenderer

# ouptut with the new Renderer applied
display.pprint()

This produces:

📁music
└─ 📁folk
   ├─ 📄bang.mp3
   ├─ 📄bing.mp3
   └─ 📄bop.wav

Previously, the renderer was updated so that each call to pprint will use the emojiRenderer. If the main renderer is not required to be updated permanently, use the pprint optional argument - renderer.

from fictus.renderer import defaultRenderer
# current renderer is the emojiRenderer

# uses defaultRenderer just this one time
display.pprint(renderer=defaultRenderer)  

# use the emojiRenderer that was setup in the previous example set.
display.pprint() 

RenderTag Customization

Customization may be useful for creating HTML, Markdown, or other custom tags that are not already provided. A Renderer can register valid RenderTagEnum types with RenderTag objects. By default, all RenderTags contain empty strings. The user can choose to override any number of tags as required.

You can create a new Renderer from scratch and customize the RenderTags that are appropriate. For example:

from fictus.renderer import RenderTagEnum, RenderTag

# A customRenderer is created: adds special characters before a File or Folder.
customRenderer = Renderer()
customRenderer.register(RenderTagEnum.FILE, RenderTag("· ", ""))
customRenderer.register(RenderTagEnum.FOLDER, RenderTag("+ ", "\\"))

# Update display_model to the customRenderer
display.renderer = customRenderer
display.pprint()

Produces:

+ music\
└─ + folk\
   ├─ · bang.mp3
   ├─ · bing.mp3
   └─ · bop.wav

One can also create a new Renderer object starting with an already applied object and updating only the Enum value of interest.

new_renderer = (
    display.renderer
)  # from previous examples -- this will return customRenderer
new_renderer.register(RenderTagEnum.FOLDER, RenderTag("✓ ", ""))
display.pprint(renderer=new_renderer)

And this will, as expected, generate the following:

✓ music
└─ ✓ folk
   ├─ · bang.mp3
   ├─ · bing.mp3
   └─ · bop.wav

Install Using Pip

pip install fictus

Building/installing the Wheel locally:

To build the package requires setuptools and build.

python3 -m build

Once built:

pip install dist/fictus-*.whl --force-reinstall

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

fictus-0.4.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fictus-0.4.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file fictus-0.4.1.tar.gz.

File metadata

  • Download URL: fictus-0.4.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for fictus-0.4.1.tar.gz
Algorithm Hash digest
SHA256 0fd83e7a7b9358e987ab62258c140b68458f36c9407ab2a217e03fa456f66162
MD5 b9287105d0407b3ab48512659625e071
BLAKE2b-256 05cdea1ba535f46521bebb77483bb833b04bdae8e959ae656943eace71513e8a

See more details on using hashes here.

File details

Details for the file fictus-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: fictus-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for fictus-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62d833e2eb9e29a6feb2eb27f8a8d1777938632ab375ae139a4afe24f4fdb1e8
MD5 3e45e26220ed39df39c1539f59f1d0a2
BLAKE2b-256 4593d8098f16218ca94c4484434ba449f44d404d8154177b3192acf2960c1a7b

See more details on using hashes here.

Supported by

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