Skip to content
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

Respect XDG standards and don't put .pyfa in ~ by default #237

Open
Iiridayn opened this issue Dec 27, 2014 · 7 comments
Open

Respect XDG standards and don't put .pyfa in ~ by default #237

Iiridayn opened this issue Dec 27, 2014 · 7 comments

Comments

@Iiridayn
Copy link

By default, line 54 of config.py is run, setting savePath to "~/.pyfa". Instead of forcing the use of ~ to store .pyfa, instead check the relevant XDG environment variable and store the data there instead. The location of .pyfa - though the . wouldn't be needed - would probably be $XDG_DATA_HOME - which defaults to "$HOME/.local/share" if undefined.

For more information please view http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html.

@blitzmann
Copy link
Collaborator

I'll take of look at this, but I'll be honest - if we were to adhere to this standard, it will probably be done with the next rewrite of pyfa. Might be too much of a hassle to ensure that user files are moved to the new location.

Can you quickly explain how this is better than simply ~ (besides the fact that it's a standard, which I'm always for)? Take into consideration that, afaik, python does not have a way to access these variable, whereas it can automatically resolve ~. And I'm not sure where this would point in Windows / OS X (I haven't had time to actually look through the standard).

@Iiridayn
Copy link
Author

I'm not sure if python is resolving the ~ or if the OS is. Either way, Python can access $XDG_DATA_HOME with os.getenv('XDG_DATA_HOME'). You could implement the default as savePath = (os.getenv('XDG_DATA_HOME') or os.getenv('HOME')+'/.local/share')+'/pyfa'.

This standard is better because I can (eventually) backup/link a single directory full of per-user program data and configuration instead of having it mixed into ~ and manually separating out user data from program data. Essentially, it's the same concept as C:/Users/<username>/AppData/ in Windows.

Edit: you can see my inexperience in the above example - should be: savePath = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share")))+'/pyfa' instead. (cribbed from the library referenced by narthollis).

@narthollis
Copy link

When i was writing a program recently I pondered about how to handle this problem of where to save the users data, and I cam across a python module called appdirs https://github.com/ActiveState/appdirs

This gives you a single clean way of determining the standard save location for user data on all platforms. I do agree that it doesn't solve the problem of ensuring that the existing data is copied/moved across however.

@DarkFenX
Copy link
Member

We will respect them in pyfa rewrite. Messing with existing user files might be risky. I do not want to spend any time on writing migration scripts for all platforms; however, i wholeheartedly agree it's a good thing and if someone implements it - it's going to be merged quickly.

@spencels
Copy link

I'm interested in contributing, this looks like it'd be a good introductory task. Unfortunately I don't know much about the "base directory" spec and how prevalent it is. How commonly is the standard followed across different distros? Is adopting it an anti-pattern in some distros? @Iiridayn if you could contribute anything that'd be great.

What would the behavior of the migration scripts look like? You could change the default config directory to $XDG_DATA_HOME and have Pyfa check there first, then check ~ if a file isn't found. Another option is to automatically move the existing config from ~ to $XDG_DATA_HOME when Pyfa starts up.

I think the former solution of accepting both locations is ideal for the short-term. When the big "rewrite" release comes along that can bean excuse to permanently migrate any remaining ~ configs.

@DarkFenX
Copy link
Member

I don't know either, thus i'd just check this variable and use it, unless it's empty (in which case pyfa should fall back to current home dir).

On windows it should work reliably with CSIDL/KNOWNFOLDERID stuff. However when using knownfolderid one should double-check on older windows NT-based systems (XP) because they were introduced with Vista, iirc.

On mac i have no idea.

Like another ticket suggests, might use this for autodetection, just have to verify how it behaves under different conditions: https://github.com/ActiveState/appdirs

@zuntrax
Copy link

zuntrax commented Jul 28, 2015

I'd check if ~/.pyfa exists, and use it then. If not, use the contents of the XDG variables or (if empty) use the fallback paths (like ~/.config, ~/.local/share and ~/.cache).
This would preserve backwards compatibility, but new installations would adhere to the standard. The only issue would be when launching an older version after using XDG-compliant directories, but this should be rare, at least with productive installations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants