Better Windows support: Finding the user profile directory even on Win32 (#144)
* Better Windows support: Finding the user profile directory even on Win32 * Better Windows support: Finding the user profile directory even on Win32
This commit is contained in:
parent
a1c1092987
commit
3297499fe4
@ -236,7 +236,8 @@ SYMBOLS:
|
||||
- The database file is stored in:
|
||||
- **$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
|
||||
- **$PWD**
|
||||
- **%USERPROFILE%\buku\bookmarks.db**, if you are on Windows or
|
||||
- **$PWD** on both Windows and non-Windows systems.
|
||||
- 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 bold `(L)` after the URL.
|
||||
|
3
buku.1
3
buku.1
@ -27,7 +27,8 @@ is a command-line utility to store, tag, search and organize bookmarks.
|
||||
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$PWD\fR
|
||||
- \fI%USERPROFILE%\buku\bookmarks.db\fR, if you are on Windows or
|
||||
- \fI$PWD\fR on both Windows and non-Windows systems.
|
||||
.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 ('/").
|
||||
|
20
buku.py
20
buku.py
@ -352,20 +352,26 @@ class BukuDb:
|
||||
@staticmethod
|
||||
def get_default_dbdir():
|
||||
'''Determine the directory path where dbfile will be stored:
|
||||
if $XDG_DATA_HOME is defined, use it
|
||||
if the platform is Windows, use %USERPROFILE%
|
||||
else if $XDG_DATA_HOME is defined, use it
|
||||
else if $HOME exists, use it
|
||||
else use the current directory
|
||||
|
||||
:return: path to database file
|
||||
'''
|
||||
|
||||
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('USERPROFILE')
|
||||
if data_home is None:
|
||||
return os.path.abspath('.')
|
||||
else:
|
||||
data_home = os.path.join(os.environ.get('HOME'),
|
||||
'.local', 'share')
|
||||
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('.')
|
||||
else:
|
||||
data_home = os.path.join(os.environ.get('HOME'),
|
||||
'.local', 'share')
|
||||
|
||||
return os.path.join(data_home, 'buku')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user