Skip to content

Commit

Permalink
fixed .ignore with wcmatch package instead of fnmatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Barakudum committed Feb 4, 2024
1 parent 1bfc28e commit 1e3e891
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config-library = {extras = ["yaml"], version = "*"}
flask-compress = "*"
waitress = "*"
schedule = "*"
wcmatch = "*"

[dev-packages]
better-exceptions = "*"
Expand Down
24 changes: 20 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/jarklin/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def find_generators(self) -> t.List[CacheGenerator]:

if is_gallery(source):
generators.append(GalleryCacheGenerator(source=source, dest=dest, config=self._config))

# videos
for filename in filenames[:]:
source = Path(root, filename)
Expand Down
15 changes: 7 additions & 8 deletions src/jarklin/common/dot_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
r"""
"""
import logging
import re
import os
import os.path as p
import typing as t
import fnmatch
import os.path as p
import wcmatch.glob as wcglob


PathResource: t.TypeAlias = t.Union[str, os.PathLike]
Expand All @@ -21,20 +20,20 @@ def __init__(self, *rules: str, root: PathResource = "."):

root = p.abspath(root)
for rule in rules:
rule = rule.strip()
negated = rule.startswith("!")
if negated:
rule = rule[1:]

if rule.startswith("/"):
rule = f"{root}{rule}"
else:
rule = f"*/{rule}"
rule = f"**/{rule}"

if rule.endswith("/"): # currently directory-detection not supported
rule = rule[:-1]
if rule.endswith("/"): # currently directory-detection not supported
rule = rule[:-1]

self._rules.append((negated, re.compile(fnmatch.translate(rule).replace(".*", "[^/]*"))))
(pattern, *_), _ = wcglob.translate(rule, flags=wcglob.IGNORECASE | wcglob.GLOBSTAR)
self._rules.append((negated, re.compile(pattern)))

def ignored(self, path: PathResource) -> bool:
path = p.abspath(path)
Expand Down

0 comments on commit 1e3e891

Please sign in to comment.