-
-
Notifications
You must be signed in to change notification settings - Fork 836
patterns: clean up TODOs, move is_include_cmd to IECommand property, fixes #9442 #9542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mr-raj12
wants to merge
2
commits into
borgbackup:master
Choose a base branch
from
mr-raj12:cleanup-patterns-todos-master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,11 +4,15 @@ | |
| import sys | ||
| import unicodedata | ||
| from collections import namedtuple | ||
| import os | ||
| from enum import Enum | ||
|
|
||
| from .helpers import clean_lines, shellpattern | ||
| from .helpers.argparsing import Action, ArgumentTypeError | ||
| from .helpers.errors import Error | ||
| from .logger import create_logger | ||
|
|
||
| logger = create_logger() | ||
|
|
||
|
|
||
| def parse_patternfile_line(line, roots, ie_commands, fallback): | ||
|
|
@@ -89,15 +93,13 @@ def __init__(self, fallback=None): | |
| # False when calling match(). | ||
| self.recurse_dir = None | ||
|
|
||
| # whether to recurse into directories when no match is found | ||
| # TODO: allow modification as a config option? | ||
| # Whether to recurse into directories when no match is found. | ||
| # This must be True so that include patterns inside excluded directories | ||
| # work correctly (e.g. "+ /excluded_dir/important" inside "- /excluded_dir"). | ||
| self.recurse_dir_default = True | ||
|
|
||
| self.include_patterns = [] | ||
|
|
||
| # TODO: move this info to parse_inclexcl_command and store in PatternBase subclass? | ||
| self.is_include_cmd = {IECommand.Exclude: False, IECommand.ExcludeNoRecurse: False, IECommand.Include: True} | ||
|
|
||
| def empty(self): | ||
| return not len(self._items) and not len(self._path_full_patterns) | ||
|
|
||
|
|
@@ -150,13 +152,13 @@ def match(self, path): | |
| if value is not non_existent: | ||
| # we have a full path match! | ||
| self.recurse_dir = command_recurses_dir(value) | ||
| return self.is_include_cmd[value] | ||
| return value.is_include | ||
|
|
||
| # this is the slow way, if we have many patterns in self._items: | ||
| for pattern, cmd in self._items: | ||
| if pattern.match(path, normalize=False): | ||
| self.recurse_dir = pattern.recurse_dir | ||
| return self.is_include_cmd[cmd] | ||
| return cmd.is_include | ||
|
|
||
| # by default we will recurse if there is no match | ||
| self.recurse_dir = self.recurse_dir_default | ||
|
|
@@ -314,10 +316,17 @@ class IECommand(Enum): | |
| Exclude = 4 | ||
| ExcludeNoRecurse = 5 | ||
|
|
||
| @property | ||
| def is_include(self): | ||
| return self is IECommand.Include | ||
|
|
||
|
|
||
| def command_recurses_dir(cmd): | ||
| # TODO?: raise error or return None if *cmd* is RootPath or PatternStyle | ||
| return cmd not in [IECommand.ExcludeNoRecurse] | ||
| if cmd is IECommand.ExcludeNoRecurse: | ||
| return False | ||
| if cmd is IECommand.Include or cmd is IECommand.Exclude: | ||
| return True | ||
| raise ValueError(f"command_recurses_dir: unexpected command: {cmd!r}") | ||
|
|
||
|
|
||
| def get_pattern_class(prefix): | ||
|
|
@@ -368,7 +377,18 @@ def parse_inclexcl_command(cmd_line_str, fallback=ShellPattern): | |
| raise ArgumentTypeError("A pattern/command must have a value part.") | ||
|
|
||
| if cmd is IECommand.RootPath: | ||
| # TODO: validate string? | ||
| # Check if path is absolute | ||
| is_absolute = remainder_str.startswith("/") | ||
| # Check if path exists | ||
| path_exists = os.path.exists(remainder_str) | ||
|
|
||
| # Warn about relative paths | ||
| if not is_absolute: | ||
| logger.warning("Root path %r is relative, recommended to use absolute path", remainder_str) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..., it is recommended to use an ... |
||
| # Warn about non-existent paths | ||
| if not path_exists: | ||
| logger.warning("Root path %r does not exist", remainder_str) | ||
|
|
||
| val = remainder_str | ||
| elif cmd is IECommand.PatternStyle: | ||
| # then remainder_str is something like 're' or 'sh' | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that does not work on win32.
Path(p).is_absolute()or so.