-
Notifications
You must be signed in to change notification settings - Fork 427
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
Fixing DOCUMENTS key and raised exception #539
Open
Nibodhika
wants to merge
3
commits into
kivy:master
Choose a base branch
from
Nibodhika:linux_storagepath
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
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 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 |
---|---|---|
|
@@ -30,7 +30,7 @@ def _get_from_user_dirs(self, name): | |
if v.startswith("XDG_" + name)][0] | ||
return lines[index].split('"')[1] | ||
except KeyError: | ||
return PATHS[name] | ||
return self._get_home_dir() + PATHS[name] | ||
except Exception as e: | ||
raise e | ||
|
||
|
@@ -44,7 +44,7 @@ def _get_root_dir(self): | |
return "/" | ||
|
||
def _get_documents_dir(self): | ||
directory = self._get_from_user_dirs("DOCUMENT") | ||
directory = self._get_from_user_dirs("DOCUMENTS") | ||
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. This is right, according to https://cgit.freedesktop.org/xdg/xdg-user-dirs/tree/user-dirs.defaults. |
||
return directory.replace("$HOME", self._get_home_dir()) | ||
|
||
def _get_downloads_dir(self): | ||
|
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.
Although this change will return the desired path, I don't agree with having default paths and catching the
FIleNotFoundError
here.PATHS
is assuming that by default all those folders are called like that, which is not always correct. I think the developer is the one who should catch theFileNotFoundError
exception, and notplyer
. For example: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.
In that case I think other changes should be made, the code is already returning a default value if the key is not present in the file, which is prone to the same sort of errors, and that would raise a KeyError exception.
Also while I agree with you that there are good reasons to let the exception propagate, I would like to suggest a few changes:
We should create a unified exception for both cases so that the user should not need to catch multiple exceptions.
If the default folder exists it should be returned instead of raising the exception.
There should be a parameter or a flag to create the default folder if it doesn't exist instead of raising an exception, and this should be the default.
IMO we need to think that this is just one platform of a multi-platform app and users shouldn't be expected to know that a specific platform can fail due to a quirk of how the platform manages folders, nor should they have to create platform specific code outside of plyer.
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.
It's a good idea! For that, I think another pull request should be opened, leaving this one for the
DOCUMENTS
fix.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.
Out of curiosity, why do you think two pull requests should be made for this instead of just making the changes in this PR?
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.
This is not a rule, but...
I think the
DOCUMENTS
fix is ok, so it can be merged instantly. The other part of your pull request is not complete and might change. Although it is not explicit, in here says:Ideally there should not be a pull request to solve this and that, but one for each bugfix. Here you are presenting at least two different fixes in one plyer facade. Having them in different pull requests is helpful, because as I said, the
DOCUMENTS
fix is mergeable, and the other changes can be discussed without interfering the first fix.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.
Just created a new commit to revert the other exception handling (I think they should be merged though, but I didn't wanted to do it to keep the history until this is ready to merge), I'll be working on the way I think linux systems that don't have
/.config/user-dirs.dirs
should be handled and we can discuss the details in that PR. But I think it should return a default folder instead of failing, especially to keep consistency with other systems where a failure in this method is not expected.