-
Notifications
You must be signed in to change notification settings - Fork 0
Proposed changeset for "Update delete the whole solution to install it again" #3
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
peauc
wants to merge
3
commits into
master
Choose a base branch
from
continuous_improvement_quail_ignore
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import shutil | ||
| import os | ||
| import glob | ||
| from quail.helper.file_ignore import FileIgnore | ||
| from quail.constants import Constants | ||
|
|
||
|
|
||
| class Solutioner: | ||
|
|
@@ -35,10 +38,39 @@ def install(self): | |
| def installed(self): | ||
| return os.path.exists(self.dest()) | ||
|
|
||
| """ | ||
| This function makes sure that all the files defined in the file with path=Constants.UPDATE_IGNORE_FILE | ||
| are not deleted when the software is updating | ||
|
|
||
| First parameter is the root path for the solution. We could have used self.dest() but is not | ||
| an acceptable solution for tests. | ||
| TODO: Make sure that we set up the solution properly during the test, this problem should'nt happen | ||
| """ | ||
| def _clear_non_ignored_files(self, path): | ||
| fi = FileIgnore(os.path.join(path, Constants.UPDATE_IGNORE_FILE)) | ||
| result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(path) for f in filenames] | ||
| files_to_remove = [item for item in result if fi.accept(item) and not item.endswith(Constants.UPDATE_IGNORE_FILE)] | ||
| for file in files_to_remove: | ||
| if os.path.exists(file): | ||
| os.remove(file) | ||
|
|
||
| def __update_solution_files(self): | ||
| self._solution.open() | ||
| try: | ||
| if not os.path.exists(self.dest()): | ||
| os.makedirs(self.dest(), 0o777, True) | ||
| for root, dirs, files in self._solution.walk(): | ||
| for dir in dirs: | ||
| if not os.path.exists(dir): | ||
| os.makedirs(self.dest(root, dir), 0o777, True) | ||
| for file in files: | ||
|
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. ignore ici |
||
| self._retrieve_file(os.path.join(root, file)) | ||
| finally: | ||
| self._solution.close() | ||
|
|
||
| def update(self): | ||
| # TODO: uninstall will be a waste of time on future solution types | ||
| self.uninstall() | ||
| self.install() | ||
| self._clear_non_ignored_files(self.dest()) | ||
| self.__update_solution_files() | ||
|
|
||
| def uninstall(self): | ||
| if self.installed(): | ||
|
|
||
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,27 @@ | ||
| import os | ||
| from .base_test_case import BaseTestCase | ||
| from quail.constants import Constants | ||
| from quail.solution.solutioner import Solutioner | ||
|
|
||
|
|
||
| class TestUpdateFileIgnore(BaseTestCase): | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.solutioner = Solutioner(None, os.path.curdir) | ||
|
|
||
| def test_basic_ignore(self): | ||
| os.mkdir(self.tmp("test")) | ||
| with open(self.tmp("test", "1.txt"), "a+"): | ||
| pass | ||
| with open(self.tmp("test", "2.txt"), "a+"): | ||
| pass | ||
| with open(self.tmp("test", Constants.UPDATE_IGNORE_FILE), "a+") as f: | ||
| f.write("*1.txt") | ||
| self.solutioner._clear_non_ignored_files(self.tmp("test")) | ||
|
|
||
| assert os.path.exists(self.tmp("test", Constants.UPDATE_IGNORE_FILE)) | ||
| assert not os.path.exists(self.tmp("test", "2.txt")) | ||
|
|
||
|
|
||
| #TODO: Add multiple test with edge case |
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.
get
.quailignore