-
Notifications
You must be signed in to change notification settings - Fork 23
SP-3354_delta-scan-setup #155
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e5c958e
Added delta command with copy subcommand
Alex-1089 7ed6040
Linter
Alex-1089 196439a
Added subcommand validation. Added error handling to delta file copier
Alex-1089 5fafc3a
Linter
Alex-1089 b158a6e
Added documentation. Normalised source to prevent copying files to ou…
Alex-1089 6f5117e
added debug and extra error checks
eeisegn 0070f09
Linter
Alex-1089 30d5abf
cleanup path validation
eeisegn e8de7a4
nitpick cleanup
eeisegn a2cb500
fix typo
eeisegn e3cfeb4
add root path to folder creation
eeisegn c22bf5b
reduce returned temp folder path
eeisegn 154e6ff
remove created temp folder prefix
eeisegn 8427495
relpath cleanup
eeisegn 7f3f8ac
change to isfile validation
eeisegn c7c1e50
Updated Changelog
Alex-1089 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """ | ||
| SPDX-License-Identifier: MIT | ||
|
|
||
| Copyright (c) 2025, SCANOSS | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| """ | ||
| import os | ||
| import shutil | ||
| import tempfile | ||
|
|
||
| from .scanossbase import ScanossBase | ||
|
|
||
|
|
||
| class Delta(ScanossBase): | ||
| """ | ||
|
|
||
| """ | ||
| def __init__( | ||
| self, | ||
| debug: bool = False, | ||
| trace: bool = False, | ||
| quiet: bool = False, | ||
| filepath: str = None, | ||
| folder: str = None, | ||
| output: str = None, | ||
| ): | ||
| """ | ||
|
|
||
| """ | ||
| super().__init__(debug, trace, quiet) | ||
| self.filepath = filepath | ||
| self.folder = folder | ||
| self.output = output | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def copy(self): | ||
| """ | ||
| Copy files listed in the input file to the delta directory. | ||
|
|
||
| Reads the input file line by line, where each line contains a file path. | ||
| Creates the delta directory if it doesn't exist, then copies each file | ||
| while preserving its directory structure. | ||
|
|
||
| :return: Tuple of (status_code, folder_path) where status_code is 0 for success, | ||
| 1 for error, and folder_path is the delta directory path | ||
| """ | ||
| # Validate that input file exists | ||
| if not os.path.exists(self.filepath): | ||
| self.print_stderr(f'ERROR: Input file {self.filepath} does not exist') | ||
| return 1, '' | ||
|
|
||
| # Create delta dir (folder) | ||
| folder = self.delta_dir(self.folder) | ||
| if not folder: | ||
| self.print_stderr(f'ERROR: Input folder {self.folder} already exists') | ||
| return 1, '' | ||
| self.print_to_file_or_stdout(folder, self.output) | ||
| # Read files from filepath | ||
| with open(self.filepath, 'r') as f: | ||
| for line in f: | ||
| source_file = line.rstrip('\n') | ||
| # Skip empty lines | ||
| if not source_file: | ||
| continue | ||
| # Check if source file exists | ||
| if not os.path.exists(source_file): | ||
| self.print_stderr(f'WARNING: File {source_file} does not exist, skipping') | ||
| continue | ||
| # Copy files into delta dir | ||
| dest_path = os.path.join(folder, source_file) | ||
| os.makedirs(os.path.dirname(dest_path), exist_ok=True) | ||
| shutil.copy(source_file, dest_path) | ||
| return 0, folder | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def delta_dir(self, folder): | ||
| """ | ||
| Create or validate the delta directory. | ||
|
|
||
| If no folder is specified, creates a unique temporary directory with | ||
| a 'delta-' prefix in the current directory. If a folder is specified, | ||
| validates that it doesn't already exist before creating it. | ||
|
|
||
| :param folder: Optional target directory path | ||
| :return: Path to the delta directory, or empty string if folder already exists | ||
| """ | ||
| if folder and os.path.exists(folder): | ||
| self.print_stderr(f'Folder {folder} already exists') | ||
| return '' | ||
| elif folder: | ||
| os.makedirs(folder, exist_ok=True) | ||
| else: | ||
| folder = tempfile.mkdtemp(prefix="delta-", dir='.') | ||
| return folder | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.