generated from aboutmydreams/quick-pylib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add get_directory_file_list and get_directory_folder_list
- Loading branch information
1 parent
6ccc3a9
commit 8cc80bc
Showing
5 changed files
with
138 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="way3", | ||
version="0.0.24", | ||
version="0.0.25", | ||
author="aboutmydreams", | ||
author_email="[email protected]", | ||
description="Simplified file path management for Python developers", | ||
|
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,48 @@ | ||
import os | ||
import fnmatch | ||
|
||
|
||
def parse_gitignore( | ||
gitignore_path=".gitignore", ignored_files=[".git/", ".venv/", ".github/"] | ||
): | ||
""" | ||
解析 .gitignore 文件,返回忽略规则列表 | ||
""" | ||
|
||
if os.path.exists(gitignore_path): | ||
with open(gitignore_path, "r") as gitignore_file: | ||
for line in gitignore_file: | ||
line = line.strip() | ||
if line and not line.startswith("#"): | ||
ignored_files.append(line) | ||
return ignored_files | ||
|
||
|
||
def is_gitignored(file_path, gitignore_rules): | ||
""" | ||
Check if a file path is ignored according to the given gitignore rules. | ||
Args: | ||
file_path (str): The absolute path to the file. | ||
gitignore_rules (list): List of gitignore rules. | ||
Returns: | ||
bool: True if the file is ignored, False otherwise. | ||
""" | ||
for rule in gitignore_rules: | ||
# Handle comments and empty lines | ||
if not rule or rule.startswith("#"): | ||
continue | ||
# Handle negated rules | ||
negated = False | ||
if rule.startswith("!"): | ||
negated = True | ||
rule = rule[1:] | ||
|
||
# Check if the file matches the rule | ||
if fnmatch.fnmatch(file_path, rule): | ||
return not negated | ||
if rule in str(file_path): | ||
return not negated | ||
|
||
return False |