forked from varia/distribusi
descriptions added
This commit is contained in:
parent
5934122c6e
commit
3eefd6e5ca
@ -17,13 +17,21 @@ def build_argparser():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d", "--directory", help="Select which directory to distribute", default="."
|
"-d",
|
||||||
|
"--directory",
|
||||||
|
help="Select which directory to distribute",
|
||||||
|
default=".",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument("-s", "--style", help="Select a CSS style sheet to include")
|
parser.add_argument(
|
||||||
|
"-s", "--style", help="Select a CSS style sheet to include"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--verbose", help="Print verbose debug output", action="store_true"
|
"-v",
|
||||||
|
"--verbose",
|
||||||
|
help="Print verbose debug output",
|
||||||
|
action="store_true",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import magic
|
import magic
|
||||||
@ -12,16 +11,35 @@ MIME_TYPE = magic.Magic(mime=True)
|
|||||||
def add_alttext(full_path_image):
|
def add_alttext(full_path_image):
|
||||||
try:
|
try:
|
||||||
image_filename_no_ext = os.path.splitext(full_path_image)[0]
|
image_filename_no_ext = os.path.splitext(full_path_image)[0]
|
||||||
alttext_filename = f'{image_filename_no_ext}_alttext.txt'
|
alttext_filename = f"{image_filename_no_ext}_alttext.txt"
|
||||||
if os.path.isfile(alttext_filename):
|
return _read_matching_text_file(
|
||||||
print(f"{image_filename_no_ext} has {alttext_filename}")
|
image_filename_no_ext, alttext_filename
|
||||||
with open(alttext_filename, 'r') as alttext_file:
|
)
|
||||||
return alttext_file.read()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"exception {e} raised while making alttext")
|
print(f"exception {e} raised while making alttext")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def add_description(full_path_image):
|
||||||
|
try:
|
||||||
|
image_filename_no_ext = os.path.splitext(full_path_image)[0]
|
||||||
|
description_filename = f"{image_filename_no_ext}_dv_description.txt"
|
||||||
|
return _read_matching_text_file(
|
||||||
|
image_filename_no_ext, description_filename
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"exception {e} raised while adding description")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def _read_matching_text_file(image_filename_no_ext, filename):
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
return
|
||||||
|
print(f"{image_filename_no_ext} has {filename}")
|
||||||
|
with open(filename, "r") as text_file:
|
||||||
|
return text_file.read()
|
||||||
|
|
||||||
|
|
||||||
def thumbnail(full_path_image, name, args):
|
def thumbnail(full_path_image, name, args):
|
||||||
if full_path_image.endswith("_thumbnail.jpg"):
|
if full_path_image.endswith("_thumbnail.jpg"):
|
||||||
return
|
return
|
||||||
@ -94,7 +112,7 @@ def write_index(args, index, html, html_head, html_footer):
|
|||||||
index_file.write(html_footer)
|
index_file.write(html_footer)
|
||||||
|
|
||||||
|
|
||||||
def handle_text_files(name, full_path):
|
def handle_text_files(name, full_path, subtype):
|
||||||
if name.endswith(".html") or subtype == "html":
|
if name.endswith(".html") or subtype == "html":
|
||||||
subtype = "html"
|
subtype = "html"
|
||||||
# what types of text files to expand
|
# what types of text files to expand
|
||||||
@ -119,9 +137,15 @@ def handle_image_files(name, full_path, args):
|
|||||||
return
|
return
|
||||||
if args.alttexts:
|
if args.alttexts:
|
||||||
image_alttext = add_alttext(full_path)
|
image_alttext = add_alttext(full_path)
|
||||||
|
if args.alttexts:
|
||||||
|
image_description = add_description(full_path)
|
||||||
if image_alttext is None:
|
if image_alttext is None:
|
||||||
return f'<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{name}"></a>'
|
if image_description is None:
|
||||||
return f'<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a>'
|
return f'<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{name}"></a>'
|
||||||
|
return f'<figure><a href="{name}"><img class="thumbnail" src="{thumbnail_filename}"></a><figcaption>{image_description}</figcaption></figure>'
|
||||||
|
if image_description is None:
|
||||||
|
return f'<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a>'
|
||||||
|
return f'<figure><a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a><figcaption>{image_description}</figcaption></figure>'
|
||||||
return FILE_TYPES[type_].format(name, image_alttext)
|
return FILE_TYPES[type_].format(name, image_alttext)
|
||||||
|
|
||||||
|
|
||||||
@ -150,7 +174,9 @@ def distribusify(args, directory): # noqa
|
|||||||
|
|
||||||
if args.exclude_directory:
|
if args.exclude_directory:
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("Excluding directory:", ", ".join(args.exclude_directory))
|
print(
|
||||||
|
"Excluding directory:", ", ".join(args.exclude_directory)
|
||||||
|
)
|
||||||
dirs[:] = [d for d in dirs if d not in args.exclude_directory]
|
dirs[:] = [d for d in dirs if d not in args.exclude_directory]
|
||||||
|
|
||||||
if args.no_hidden:
|
if args.no_hidden:
|
||||||
@ -172,6 +198,9 @@ def distribusify(args, directory): # noqa
|
|||||||
if name.endswith("_alttext.txt"):
|
if name.endswith("_alttext.txt"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if name.endswith("_dv_description.txt"):
|
||||||
|
continue
|
||||||
|
|
||||||
full_path = os.path.join(root, name)
|
full_path = os.path.join(root, name)
|
||||||
mime = MIME_TYPE.from_file(full_path)
|
mime = MIME_TYPE.from_file(full_path)
|
||||||
type_, subtype = mime.split("/")
|
type_, subtype = mime.split("/")
|
||||||
@ -182,7 +211,7 @@ def distribusify(args, directory): # noqa
|
|||||||
if type_ in FILE_TYPES:
|
if type_ in FILE_TYPES:
|
||||||
match type_:
|
match type_:
|
||||||
case "text":
|
case "text":
|
||||||
subtype, tag = handle_text_files(name, full_path)
|
subtype, tag = handle_text_files(name, full_path, subtype)
|
||||||
case "image":
|
case "image":
|
||||||
tag = handle_image_files(name, full_path, args)
|
tag = handle_image_files(name, full_path, args)
|
||||||
if tag is None:
|
if tag is None:
|
||||||
@ -197,7 +226,9 @@ def distribusify(args, directory): # noqa
|
|||||||
# catch exceptions not yet defined in FILE_TYPES or SUB_TYPES
|
# catch exceptions not yet defined in FILE_TYPES or SUB_TYPES
|
||||||
tag = "<a href='{}'>{}</a>"
|
tag = "<a href='{}'>{}</a>"
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
message = "not in list of file types, adding as plain href: \n"
|
message = (
|
||||||
|
"not in list of file types, adding as plain href: \n"
|
||||||
|
)
|
||||||
print(type_, subtype, message, name)
|
print(type_, subtype, message, name)
|
||||||
subtype = subtype + " unkown-file"
|
subtype = subtype + " unkown-file"
|
||||||
|
|
||||||
|
@ -7,3 +7,53 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
skip-string-normalization = true
|
skip-string-normalization = true
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
line-length = 79
|
||||||
|
target-version = "py311"
|
||||||
|
#include = '\.pyi?$'
|
||||||
|
exclude = [
|
||||||
|
".bzr",
|
||||||
|
".direnv",
|
||||||
|
".eggs",
|
||||||
|
".git",
|
||||||
|
".git-rewrite",
|
||||||
|
".hg",
|
||||||
|
".ipynb_checkpoints",
|
||||||
|
".mypy_cache",
|
||||||
|
".nox",
|
||||||
|
".pants.d",
|
||||||
|
".pyenv",
|
||||||
|
".pytest_cache",
|
||||||
|
".pytype",
|
||||||
|
".ruff_cache",
|
||||||
|
".svn",
|
||||||
|
".tox",
|
||||||
|
".venv",
|
||||||
|
".vscode",
|
||||||
|
"__pypackages__",
|
||||||
|
"_build",
|
||||||
|
"buck-out",
|
||||||
|
"build",
|
||||||
|
"dist",
|
||||||
|
"node_modules",
|
||||||
|
"site-packages",
|
||||||
|
"venv",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||||
|
select = ["E4", "E7", "E9", "F"]
|
||||||
|
ignore = []
|
||||||
|
# Allow fix for all enabled rules (when `--fix`) is provided.
|
||||||
|
fixable = ["ALL"]
|
||||||
|
unfixable = []
|
||||||
|
# Allow unused variables when underscore-prefixed.
|
||||||
|
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
quote-style = "double"
|
||||||
|
indent-style = "space"
|
||||||
|
docstring-code-format = true
|
||||||
|
line-ending = "auto"
|
||||||
|
skip-magic-trailing-comma = false
|
||||||
|
14
setup.py
14
setup.py
@ -1,6 +1,9 @@
|
|||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
dependencies = ["pillow >= 10.3.0", "python-magic >= 0.4.15, < 1.0", "exif >= 1.6.0"]
|
dependencies = [
|
||||||
|
"pillow >= 10.3.0",
|
||||||
|
"python-magic >= 0.4.15, < 1.0",
|
||||||
|
]
|
||||||
|
|
||||||
with open("README.md", "r") as handle:
|
with open("README.md", "r") as handle:
|
||||||
long_description = handle.read()
|
long_description = handle.read()
|
||||||
@ -23,6 +26,11 @@ setup(
|
|||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
platforms="any",
|
platforms="any",
|
||||||
install_requires=dependencies,
|
install_requires=dependencies,
|
||||||
entry_points={"console_scripts": ["distribusi = distribusi.cli:cli_entrypoint"]},
|
entry_points={
|
||||||
classifiers=["Programming Language :: Python :: 3", "Environment :: Console"],
|
"console_scripts": ["distribusi = distribusi.cli:cli_entrypoint"]
|
||||||
|
},
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Environment :: Console",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user