Skip to main content

A simple folder compiler

A simple python util to 'compile' a folder, e.g. for static webpages.

The primary thing this tool does is to walk through a directory, applying provided processors until the first one accepts it, some basic utils to read/write/check files, and keeping track of which file has been created by which.

For example go through the input directory, compile all markdown files from the input directory to html in the output directory, and copy all images.

Or compress all flac files in the input directory to ogg in the ouput directory. Skipping if the output is newer than the input and deleting orphaned files in the output.

Install

pip or simply clone it and copy the folder. That way you can easily adapt it to your own needs (you are free to steal this code as long as you don't make me responsible for anything).

Example: Compiling a static webpage

This has been my primary motivation to develop this util. The existing static webpage compiler have been simply too powerful and complicated for my simple use case in which I just wanted to compile the markdown files to html and add a navigation bar. This can be achieved by simple using a markdown compiler and the Jinja template engine. Compiling bibtex files to a publications page and stuff like that can also be easily integrated.

The corresponding modules are part of a separate repository.

Example: Compressing Music

This util can also be used to compress your flac music library to ogg for your phone. It skips already compressed files and deletes files that are no longer in the library.

import os
import subprocess
import shlex
import folder_compiler
from folder_compiler.processors import Processor, ProcessorUtils, FileCopyProcessor


class FlacToOggProcessor(Processor):
    """
    This processor compresses flac files to ogg.
    """

    def process_file(self, source: str, utils: ProcessorUtils):
        target = os.path.splitext(source)[0] + ".ogg"  # change file extension of target
        utils.add_file(target)  # do not delete this file!
        if utils.is_target_outdated(source=source, target=target):  # only if source is newer
            source_file = utils.get_full_source_path(source)  # get full path
            target_file = utils.get_full_target_path(target)  # get full path
            # oggenc command
            cmd = " ".join(
                ["oggenc", "-q", "8", shlex.quote(source_file), "-o",
                 shlex.quote(target_file)])
            # execute
            print(cmd)
            subprocess.run(cmd, check=True, shell=True)
        return True  # The file has been processed


processors = [
    FlacToOggProcessor().add_include(".*\.flac"),  # compress flacs
    FileCopyProcessor().add_include(".*\.jpg").add_include(".*\.png")  # copy cover images
]

# Paths: From where should the music compiled to where
uncompressed_music_source = "/home/krupke/Music"
compressed_music_target = "/path/to/my/phones/sd"
compiler = folder_compiler.FolderCompiler(input=uncompressed_music_source,
                               output=compressed_music_target)

compiler.compile(processors)  # performs the compression
compiler.remove_orphaned_files()  # remove files that are not owned by any processor

Metadata

Release files for folder-compiler 0.1.3

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

Built distribution (wheel)

Table of built distributions (wheels) for folder-compiler 0.1.3
File Interpreter ABI Platform
folder_compiler-0.1.3-py3-none-any.whl Python 3 none any Details

Release files / folder_compiler-0.1.3-py3-none-any.whl

Download URL folder_compiler-0.1.3-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f16252335118d7483c5a1dbf751a4f50b66195e36484e7ac7a78d8f54a2dda7c
BLAKE2b-256 checksum
How to use checksums
9259983ef1b2332f54e530ca8a40dcdcb8de6efeb9233ce8a83f2eea87b69aba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Security for folder-compiler 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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