-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
wxgui: startup GUI automatic detection of grassdata: make case independent #644 #664
wxgui: startup GUI automatic detection of grassdata: make case independent #644 #664
Conversation
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.
We talked about more options there, but some are easy to add in the future to this code and some would require much more work, so I'm fine with this as it is once the style is fixed.
gui/wxpython/startup/utils.py
Outdated
| break # get the first match | ||
| return path | ||
|
|
||
| options = ["grassdata","GRASSDATA","Grassdata","GrassData"] |
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.
Please use PEP8 for formatting. In general, you can run Flake8 (flake8 startup/utils.py) to get some errors, but some are unfortunately still ignored/disabled including this one. Here, just remember space after comma and use: ..."grassdata", "GRASSDATA"....
|
Wouldn't it be easier to just check whether the string transformed to all minor case is equal to 'grassdata' ? |
I thought about it too, but the problem is that I don't have any string that I can transform. I have no idea what combination of lowercase and uppercase letters in the "grassdata" a user could have on his computer. |
Maybe just convert all to lowercase? https://grass.osgeo.org/programming7/strings_8c.html |
I understand. You would have to approach it differently, i.e. get the list of all directories and then identify those that contain 'grassdata'. Something like this: Obviously something else than print() is needed... |
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.
The new functionality needs to be a new function. They are related, but the new directory should be created only if none of the paths is found. So, two functions total.
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.
Sorry, I should have been more clear before: There are independent enough not only to be two functions, but also two different PRs. I think both can be just branched out from master. Two PRs make it easier to review and would also correspond with the two separate issues with distinct goals this is addressing.
…for the directory named grassdata in usual locations.
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 don't think the behavior should be platform-dependent. The point is to find an existing directory. Please, implement this according to #644 as we originally discussed, i.e., make it case independent one way or the other and that's it. Don't mix it with #682 which is about what happens after no directory is found.
The platform-specific code just makes this more complicated than needed and you would anyway have to handle cases such as Linux user has grassdata in Documents or Windows user has it in "home".
The goal of this code is to find the directory wherever it is. Just make this same for all platforms. The only cases where this will give sub-optimal result is when user has multiple grassdata directories, but there is no right answer for that anyway and it is not really the use case this is trying to address.
With that said, we can reconsider how this code should behave in light of #682, but that's again not really relevant to #644.
|
See e.g. https://www.itprotoday.com/cloud-computing/what-environment-variables-are-available-windows There is a environment variable in MS Windows to get the user's home in an easy way. |
|
@hellik What's wrong with os.path.expanduser?
|
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.
Please also clean up extra whitespace.
gui/wxpython/startup/utils.py
Outdated
| try: | ||
| # here goes everything which has potential unicode issues | ||
| candidates.append(os.path.join(home, _("Documents"), "grassdata")) | ||
| candidates.append(os.path.join(home, _("My Documents"), "grassdata")) | ||
| candidates.append(os.path.join(home, _("Documents"))) |
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 adds Documents into the list of candidates twice in case _("Documents") == "Documents". So you could do:
tr_documents = os.path.join(home, _("Documents"))
if tr_documents not in candidates:
candidates.append(tr_documents)
gui/wxpython/startup/utils.py
Outdated
| for subdir in next(os.walk(candidate))[1]: | ||
| if 'grassdata' in subdir.lower(): | ||
| path = os.path.join(candidate, subdir) | ||
| break |
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.
break breaks only the inner loop, you need to return the path right away:
for candidate in candidates:
if os.path.exists(candidate):
for subdir in next(os.walk(candidate))[1]:
if 'grassdata' in subdir.lower():
return os.path.join(candidate, subdir)
return None
then you don't need to define path variable at all.
AFAIK my documents and all other variants, at least in more recent MS Windows versions, are just some kind of an alias for documents. Thus, you should be safe to use documents. |
Yes, that is the case here as well. What makes it far more worse however, is that - at least in my organisation - Windows home directories are linked to a Microsoft Sharepoint/OneDrive site (kind of google drive, dropbox, ...). There users will most likely experience more or less significant performance penalties because of syncing with online storage... |
|
Could you be a bit more explicit in your commit messages ? 'Improvements' and 'Improvements according to Vaclav' are just not very easy to interpret to get a quick info about the contents of the commit. ;-) |
Yes Moritz, I will be. Those commits are set up from several very small changes so I was not sure how to describe it. I will try to be more explicit next time. |
OK, let's than ignore any old or strange Windows and ignore also some Linux distros which had/has only the translated versions (based on my initial research). If we decide we need something like this in the future, we will probably need something more sophisticated anyway (there are Python packages and command line tools to deal with this properly). @lindakladivova Please, remove all the |
@ninsbl Are you talking about using grassdata placed there or even just searching through that directory (one level only, two directories)? I don't know what GRASS could do here. If you have a slow system or a bad setup, GRASS will be slow. |
gui/wxpython/startup/utils.py
Outdated
| try: | ||
| # here goes everything which has potential unicode issues | ||
| candidates.append(tr_document) | ||
| except UnicodeDecodeError: |
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.
append function does not generate UnicodeDecodeError, that was there for os.path.join in case of some issues with translatable strings. Anyway, you don't need to fix it, we decided to completely remove the translatable versions (Vashek will comment on that).
gui/wxpython/startup/utils.py
Outdated
|
|
||
| Returns the path as a string or None if nothing was found, so the | ||
| return value can be used to test if the directory was found. | ||
| """Finds the directory for possible GRASS Database. |
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.
The description is awkward. I suggest:
"""Looks for directory 'grassdata' (case-insensitive)
in standard locations to detect existing GRASS Database.
Returns the path as a string or None if nothing was found."""
…get_possible_database_path()
After starting GRASS GIS with GUI, the GUI now searches for existing grassdata (e.g., dac6d4a and #644 with #664).
This platfrom-dependent directory would be:
This function does not address temporary directory. No platform specific code.