forked from Backblaze/b2-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 9
Extract folder scanning module #212
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
agoncharov-reef
wants to merge
17
commits into
master
Choose a base branch
from
scan-module
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
Show all changes
17 commits
Select commit
Hold shift + click to select a range
43dfd5f
Move chunks to `scan` module
agoncharov-reef ba50848
Fix file headers
agoncharov-reef d1ca3ce
UnSyncableFilename -> UnsupportedFilename
agoncharov-reef 11cb325
Refactor super()
agoncharov-reef bc38109
SyncPath -> ScanPath
agoncharov-reef eddc479
Separate Report from SyncReport
agoncharov-reef 48dcf4c
Reformat imports
agoncharov-reef bf42cb7
Don't create redundant `keep_days` variable
agoncharov-reef 8d0023f
Move `zip_folders` to `scan/scan.py`
agoncharov-reef 266aa6c
Fix imports
agoncharov-reef 95c39b8
Fix tests
agoncharov-reef 19fb2b5
Lint fix
agoncharov-reef cdba814
Update changelog
agoncharov-reef 8ac1500
Update CHANGELOG.md
agoncharov-reef df25245
Avoid calling time.time()
agoncharov-reef 60b0641
Minor fixes
agoncharov-reef d8a4c45
Extract scan tests from sync unit tests
agoncharov-reef 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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| ###################################################################### | ||
| # | ||
| # File: b2sdk/scan/exception.py | ||
agoncharov-reef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # Copyright 2022 Backblaze Inc. All Rights Reserved. | ||
| # | ||
| # License https://www.backblaze.com/using_b2_code.html | ||
| # | ||
| ###################################################################### | ||
|
|
||
| from contextlib import contextmanager | ||
| from typing import Iterator, Type | ||
|
|
||
| from ..exception import B2Error, B2SimpleError | ||
|
|
||
|
|
||
| class EnvironmentEncodingError(B2Error): | ||
| """ | ||
| Raised when a file name can not be decoded with system encoding. | ||
| """ | ||
|
|
||
| def __init__(self, filename, encoding): | ||
| """ | ||
| :param filename: an encoded file name | ||
| :type filename: str, bytes | ||
| :param str encoding: file name encoding | ||
| """ | ||
| super().__init__() | ||
| self.filename = filename | ||
| self.encoding = encoding | ||
|
|
||
| def __str__(self): | ||
| return """file name %s cannot be decoded with system encoding (%s). | ||
| We think this is an environment error which you should workaround by | ||
| setting your system encoding properly, for example like this: | ||
| export LANG=en_US.UTF-8""" % ( | ||
| self.filename, | ||
| self.encoding, | ||
| ) | ||
|
|
||
|
|
||
| class InvalidArgument(B2Error): | ||
| """ | ||
| Raised when one or more arguments are invalid | ||
| """ | ||
|
|
||
| def __init__(self, parameter_name, message): | ||
| """ | ||
| :param parameter_name: name of the function argument | ||
| :param message: brief explanation of misconfiguration | ||
| """ | ||
| super().__init__() | ||
| self.parameter_name = parameter_name | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return "%s %s" % (self.parameter_name, self.message) | ||
|
|
||
|
|
||
| class UnsupportedFilename(B2Error): | ||
| """ | ||
| Raised when a filename is not supported by the scan operation | ||
| """ | ||
|
|
||
| def __init__(self, message, filename): | ||
| """ | ||
| :param message: brief explanation of why the filename was not supported | ||
| :param filename: name of the file which is not supported | ||
| """ | ||
| super().__init__() | ||
| self.filename = filename | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return "%s: %s" % (self.message, self.filename) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def check_invalid_argument(parameter_name: str, message: str, | ||
| *exceptions: Type[Exception]) -> Iterator[None]: | ||
| """Raise `InvalidArgument` in case of one of given exception was thrown.""" | ||
| try: | ||
| yield | ||
| except exceptions as exc: | ||
| if not message: | ||
| message = str(exc) | ||
| raise InvalidArgument(parameter_name, message) from exc | ||
|
|
||
|
|
||
| class BaseDirectoryError(B2SimpleError): | ||
| def __init__(self, path): | ||
| self.path = path | ||
| super().__init__(path) | ||
|
|
||
|
|
||
| class EmptyDirectory(BaseDirectoryError): | ||
| pass | ||
|
|
||
|
|
||
| class UnableToCreateDirectory(BaseDirectoryError): | ||
| pass | ||
|
|
||
|
|
||
| class NotADirectory(BaseDirectoryError): | ||
| pass | ||
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
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.
I think in v2 both
parse_sync_folderandparse_foldershould be available and there should be a test that makes sure we have it