bw_processing.filesystem

Attributes

MULTI_RE

SUBSTITUTION_RE

re_slugify

Functions

clean_datapackage_name(→ str)

Clean string name of characters not allowed in data package names.

md5(→ str)

Generate MD5 hash for file at filepath

safe_filename(→ str)

Convert arbitrary strings to make them safe for filenames. Substitutes strange characters, and uses unicode normalization.

Module Contents

bw_processing.filesystem.clean_datapackage_name(name: str) str[source]

Clean string name of characters not allowed in data package names.

Replaces with underscores, and drops multiple underscores.

bw_processing.filesystem.md5(filepath: str | pathlib.Path, blocksize: int = 65536) str[source]

Generate MD5 hash for file at filepath

bw_processing.filesystem.safe_filename(string: str | bytes, add_hash: bool = True, full: bool = False) str[source]

Convert arbitrary strings to make them safe for filenames. Substitutes strange characters, and uses unicode normalization.

if add_hash, appends hash of string to avoid name collisions.

From http://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename-in-python

bw_processing.filesystem.MULTI_RE[source]
bw_processing.filesystem.SUBSTITUTION_RE[source]
bw_processing.filesystem.re_slugify[source]