From 6abfea2e33c961026843692bcc92b485e7e6975e Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 28 May 2017 19:51:19 +0530 Subject: [PATCH] Support XDG_DATA_HOME, HOME to store DB file on all platforms --- README.md | 2 +- buku.1 | 2 +- buku.py | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3917cf3..50e9053 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/buku.1 b/buku.1 index c138a80..0584127 100644 --- a/buku.1 +++ b/buku.1 @@ -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 ('/"). diff --git a/buku.py b/buku.py index ee8eb93..2c00bd7 100755 --- a/buku.py +++ b/buku.py @@ -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')