On 8/19/19 1:53 PM, Barry Scott wrote:
On 19 Aug 2019, at 13:43, Dave via Python-list <python-list@python.org> wrote:
The plan for an app that I'm doing was to use SQLite for data and to hold the
preference settings as some apps do. The plan was changed last week to allow
the user to select the location of the data files (SQLite) rather than putting
it where the OS would dictate. Ok with that, but it brings up some questions.
First, I will need to have a file that points to the location of the data file
since that can't be hard coded. Second, if I have to have a file that is likely
part of the application group of files, would it make more sense to use a more
traditional preferences file? How have other Python app developers done in
this case?
There are expected locations for config files and data files on each OS.
On macOS you would use ~/Library/Preferences/ and put a file or a folder of
files in there.
The convention is use your website name as the base name of the file or folder.
For example for scm-workbench I use: org.barrys-emacs.scm-workbench as the
folder name for
all the scm-workbench files.
On Windows you can use a file or folder in %APPDATA% that is named after your
app. You should
find the folder by doing a win32 API call to get the value. See
getPreferencesDir() in
https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_platform_win32_specific.py
<https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_platform_win32_specific.py>
for how to get the value.
On Linux the XDG spec says that you should put config files in
~/.config/<app-name> and data files
in ~/.local/share/<app-name>. Doing XDG to the spec is a little involved. I
have some experimental
code that implements the logic for config the XdgConfigPath class in:
https://github.com/barry-scott/CLI-tools/blob/master/Source/smart_find/__init__.py
<https://github.com/barry-scott/CLI-tools/blob/master/Source/smart_find/__init__.py>
Putting a file directly in the $HOME folder is no longer recommended.
The format of the config data you are free to choose.
I have been using JSON files recently as it allow for structured data.
Barry
Barry, and all,
I agree that various OS's have a favorite place to put things. Python
has a library that will help. However, there are valid reasons to let
the customer choose. Perhaps the drive/folder is a journaling one, or
one that is backed up multiple times per day. My take is to start with
the OS solution, but let the customer decide.
How did this thread show up in the SQLite mailing list anyway? Really
has nothing to do with SQLite that I can see.
Dave,
--
https://mail.python.org/mailman/listinfo/python-list