Permalink
Browse files

Use XDG Base Directory Specification for data/config/cache

  • Loading branch information...
thp committed Jan 18, 2014
1 parent d337944 commit 320f79a6bc62bca8f2a8977232554d5a26ef0f25
Showing with 41 additions and 17 deletions.
  1. +14 −6 README
  2. +27 −11 src/gpodder/core.py
View
20 README
@@ -110,6 +110,12 @@
export GPODDER_HOME=/media/usbdisk/gpodder-data/
+ By default, gPodder 4 uses the XDG Base Directory Specification
+ for determining the location of data files ($XDG_DATA_HOME) and
+ configuration files ($XDG_CONFIG_HOME):
+
+ http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+
[ CHANGING THE DOWNLOAD DIRECTORY ]
@@ -124,17 +130,19 @@
Another example would be to set both environment variables:
- export GPODDER_HOME=~/.config/gpodder/
- export GPODDER_DOWNLOAD_DIR=~/Podcasts/
+ export GPODDER_HOME=~/bla/gpodder/
+ export GPODDER_DOWNLOAD_DIR=~/Music/Podcasts/
- This will store the database and settings files in ~/.config/gpodder/
- and the downloads in ~/Podcasts/. If GPODDER_DOWNLOAD_DIR is not set,
- $GPODDER_HOME/Downloads/ will be used if it is set.
+ This will store the database and settings files in ~/bla/gpodder/
+ and the downloads in ~/Music/Podcasts/. If GPODDER_DOWNLOAD_DIR is
+ not set, $GPODDER_HOME will be used if $GPODDER_HOME is set, or
+ the XDG Base Directory (inside $XDG_DATA_HOME) otherwise.
[ LOGGING ]
- By default, gPodder writes log files to $GPODDER_HOME/Logs/ and removes
+ By default, gPodder writes log files to a folder in $XDG_CACHE_HOME (or
+ $GPODDER_HOME if it is set) and removes
them after a certain amount of times. To avoid this behavior, you can set
the environment variable GPODDER_WRITE_LOGS to "no", e.g:
View
@@ -37,30 +37,46 @@ def __init__(self,
database_class=storage.Database,
model_class=model.Model,
prefix=None,
- verbose=True):
+ verbose=True,
+ progname='gpodder'):
self._set_socket_timeout()
self.prefix = prefix
if not self.prefix:
# XXX
self.prefix = os.path.abspath('.')
- # Home folder: ~/gPodder or $GPODDER_HOME (if set)
- self.home = os.path.abspath(os.environ.get('GPODDER_HOME',
- os.path.expanduser(os.path.join('~', 'gPodder'))))
+ home = os.path.expanduser('~')
+
+ xdg_data_home = os.environ.get('XDG_DATA_HOME',
+ os.path.join(home, '.local', 'share'))
+ xdg_config_home = os.environ.get('XDG_CONFIG_HOME',
+ os.path.join(home, '.config'))
+ xdg_cache_home = os.environ.get('XDG_CACHE_HOME',
+ os.path.join(home, '.cache'))
+
+ self.data_home = os.path.join(xdg_data_home, progname)
+ self.config_home = os.path.join(xdg_config_home, progname)
+ self.cache_home = os.path.join(xdg_cache_home, progname)
+
+ # Use $GPODDER_HOME to set a fixed config and data folder
+ if 'GPODDER_HOME' in os.environ:
+ home = os.environ['GPODDER_HOME']
+ self.data_home = self.config_home = self.cache_home = home
# Setup logging
- log.setup(self.home, verbose)
+ log.setup(self.cache_home, verbose)
self.logger = logging.getLogger(__name__)
- config_file = os.path.join(self.home, 'Settings.json')
- database_file = os.path.join(self.home, 'Database')
- # Downloads folder: <home>/Downloads or $GPODDER_DOWNLOAD_DIR (if set)
+ config_file = os.path.join(self.config_home, 'Settings.json')
+ database_file = os.path.join(self.data_home, 'Database')
+ # Downloads go to <data_home> or $GPODDER_DOWNLOAD_DIR
self.downloads = os.environ.get('GPODDER_DOWNLOAD_DIR',
- os.path.join(self.home, 'Downloads'))
+ os.path.join(self.data_home))
- # Initialize the gPodder home directory
- util.make_directory(self.home)
+ # Initialize the gPodder home directories
+ util.make_directory(self.data_home)
+ util.make_directory(self.config_home)
# Open the database and configuration file
self.db = database_class(database_file)

0 comments on commit 320f79a

Please sign in to comment.