-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.chkbitignore support for subdirectories #8
- Loading branch information
Showing
11 changed files
with
183 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from __future__ import annotations | ||
import fnmatch | ||
import os | ||
import sys | ||
import chkbit | ||
from enum import Enum | ||
from typing import Optional | ||
|
||
|
||
class Ignore: | ||
def __init__( | ||
self, | ||
context: chkbit.Context, | ||
path: str, | ||
*, | ||
parent_ignore: Optional[chkbit.Ignore], | ||
): | ||
self.parent_ignore = parent_ignore | ||
self.context = context | ||
self.path = path | ||
self.name = os.path.basename(path) + "/" | ||
self.ignore = [] | ||
self.load_ignore() | ||
|
||
@property | ||
def ignore_filepath(self): | ||
return os.path.join(self.path, self.context.ignore_filename) | ||
|
||
def load_ignore(self): | ||
if not os.path.exists(self.ignore_filepath): | ||
return | ||
with open(self.ignore_filepath, "r", encoding="utf-8") as f: | ||
text = f.read() | ||
|
||
self.ignore = list( | ||
filter( | ||
lambda x: x and x[0] != "#" and len(x.strip()) > 0, text.splitlines() | ||
) | ||
) | ||
|
||
def should_ignore(self, name: str, *, fullname: str = None): | ||
for ignore in self.ignore: | ||
if ignore.startswith("/"): | ||
if fullname: | ||
continue | ||
else: | ||
ignore = ignore[1:] | ||
if fnmatch.fnmatch(name, ignore): | ||
return True | ||
if fullname and fnmatch.fnmatch(fullname, ignore): | ||
return True | ||
if self.parent_ignore: | ||
return self.parent_ignore.should_ignore( | ||
fullname or name, fullname=self.name + (fullname or name) | ||
) | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from __future__ import annotations | ||
from typing import Optional | ||
import chkbit | ||
|
||
|
||
class InputItem: | ||
def __init__(self, path: str, *, ignore: Optional[chkbit.Ignore] = None): | ||
self.path = path | ||
self.ignore = ignore |
Oops, something went wrong.