Support XDG_DATA_HOME, HOME to store DB file on all platforms

This commit is contained in:
Arun Prakash Jana 2017-05-28 19:51:19 +05:30
parent 7b31c2c423
commit 6abfea2e33
No known key found for this signature in database
GPG Key ID: A75979F35C080412
3 changed files with 13 additions and 13 deletions

View File

@ -241,7 +241,7 @@ SYMBOLS:
- **$XDG_DATA_HOME/buku/bookmarks.db**, if XDG_DATA_HOME is defined (first preference) or
- **$HOME/.local/share/buku/bookmarks.db**, if HOME is defined (second preference) or
- **%APPDATA%\buku\bookmarks.db**, if you are on Windows or
- **$PWD** on both Windows and non-Windows systems.
- **the current directory**.
- If the URL contains characters like `;`, `&` or brackets they may be interpreted specially by the shell. To avoid it, add the URL within single or double quotes (`'`/`"`).
- URLs are unique in DB. The same URL cannot be added twice.
- Bookmarks with immutable titles are listed with `(L)` after the title.

2
buku.1
View File

@ -29,7 +29,7 @@ The database file is stored in:
- \fI$XDG_DATA_HOME/buku/bookmarks.db\fR, if XDG_DATA_HOME is defined (first preference) or
- \fI$HOME/.local/share/buku/bookmarks.db\fR, if HOME is defined (second preference) or
- \fI%APPDATA%\buku\bookmarks.db\fR, if you are on Windows or
- \fI$PWD\fR on both Windows and non-Windows systems.
- \fIthe current directory\fR.
.PP
.IP 2. 4
If the URL contains characters like ';', '&' or brackets they may be interpreted specially by the shell. To avoid it, add the URL within single or double quotes ('/").

22
buku.py
View File

@ -360,18 +360,18 @@ class BukuDb:
:return: path to database file
'''
if sys.platform == 'win32':
data_home = os.environ.get('APPDATA')
if data_home is None:
return os.path.abspath('.')
else:
data_home = os.environ.get('XDG_DATA_HOME')
if data_home is None:
if os.environ.get('HOME') is None:
return os.path.abspath('.')
data_home = os.environ.get('XDG_DATA_HOME')
if data_home is None:
if os.environ.get('HOME') is None:
if sys.platform == 'win32':
data_home = os.environ.get('APPDATA')
if data_home is None:
return os.path.abspath('.')
else:
data_home = os.path.join(os.environ.get('HOME'),
'.local', 'share')
return os.path.abspath('.')
else:
data_home = os.path.join(os.environ.get('HOME'),
'.local', 'share')
return os.path.join(data_home, 'buku')