Skip to content

Commit

Permalink
Respect GPODDER_DOWNLOAD_DIR in the environment (bug 466)
Browse files Browse the repository at this point in the history
If this variable is set, it will override the $GPODDER_HOME
settings for the downloads directory *only*, i.e. you can
now have the downloads and DB/settings in different directories
without having to resort to using symlinks or other hacks.
  • Loading branch information
thp committed Aug 16, 2012
1 parent 4481584 commit 15e8137
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README
Expand Up @@ -159,6 +159,28 @@

export GPODDER_HOME=/media/usbdisk/gpodder-data/


[ CHANGING THE DOWNLOAD DIRECTORY ]

The run-time environment variable GPODDER_DOWNLOAD_DIR is used to
set the location for storing the downloads only (independent of the
data directory GPODDER_HOME):

export GPODDER_DOWNLOAD_DIR=/media/BigDisk/Podcasts/

In this case, the database and settings will be stored in the default
location, with the downloads stored in /media/BigDisk/Podcasts/.

Another example would be to set both environment variables:

export GPODDER_HOME=~/.config/gpodder/
export GPODDER_DOWNLOAD_DIR=~/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.


[ LOGGING ]

By default, gPodder writes log files to $GPODDER_HOME/Logs/ and removes
Expand All @@ -167,6 +189,7 @@

export GPODDER_WRITE_LOGS=no


[ EXTENSIONS ]

Extensions are normally loaded from gPodder's "extensions/" folder (in
Expand Down
15 changes: 12 additions & 3 deletions src/gpodder/__init__.py
Expand Up @@ -154,22 +154,31 @@ def __init__(self):
downloads = None
prefix = None

ENV_HOME, ENV_DOWNLOADS = 'GPODDER_HOME', 'GPODDER_DOWNLOAD_DIR'

# Function to set a new gPodder home folder
def set_home(new_home):
global home, config_file, database_file, downloads
home = os.path.abspath(new_home)

config_file = os.path.join(home, 'Settings.json')
database_file = os.path.join(home, 'Database')
downloads = os.path.join(home, 'Downloads')
if ENV_DOWNLOADS not in os.environ:
downloads = os.path.join(home, 'Downloads')

# Default locations for configuration and data files
default_home = os.path.expanduser(os.path.join('~', 'gPodder'))
set_home(os.environ.get('GPODDER_HOME', default_home))
set_home(os.environ.get(ENV_HOME, default_home))

if home != default_home:
print >>sys.stderr, 'Storing data in', home, '(GPODDER_HOME is set)'

if ENV_DOWNLOADS in os.environ:
# Allow to relocate the downloads folder (pull request 4, bug 466)
downloads = os.environ[ENV_DOWNLOADS]
print >>sys.stderr, 'Storing downloads in %s (%s is set)' % (downloads,
ENV_DOWNLOADS)

# Plugins to load by default
DEFAULT_PLUGINS = [
'gpodder.plugins.soundcloud',
Expand Down Expand Up @@ -205,7 +214,7 @@ def detect_platform():
ui.fremantle = ('Maemo 5' in etc_issue)
ui.harmattan = ('MeeGo 1.2 Harmattan' in etc_issue)

if (ui.fremantle or ui.harmattan) and 'GPODDER_HOME' not in os.environ:
if (ui.fremantle or ui.harmattan) and ENV_HOME not in os.environ:
new_home = os.path.expanduser(os.path.join('~', 'MyDocs', 'gPodder'))
set_home(os.path.expanduser(new_home))

0 comments on commit 15e8137

Please sign in to comment.