Merge download_dir and gpodder.home
This commit is contained in:
parent
ff1221b0e1
commit
e3e4a81272
8
README
8
README
|
@ -113,17 +113,13 @@
|
|||
Portable mode / roaming profiles
|
||||
================================
|
||||
|
||||
You can set the environment variables GPODDER_HOME and GPODDER_DOWNLOAD_DIR
|
||||
to point to locations for storing the database and downloaded files:
|
||||
|
||||
GPODDER_HOME ........... location for configuration and database
|
||||
GPODDER_DOWNLOAD_DIR ... location for downloaded episodes
|
||||
You can set the environment variable GPODDER_HOME to set the location for
|
||||
storing the database and downloaded files.
|
||||
|
||||
You can use this to have different configurations for gPodder or to put
|
||||
gPodder's data directly on your MP3 player or USB disk, for example:
|
||||
|
||||
export GPODDER_HOME=/media/usbdisk/gpodder-data/
|
||||
export GPODDER_DOWLOAD_DIR=/media/usbdisk/podcasts/
|
||||
gpodder
|
||||
|
||||
=========================================
|
||||
|
|
|
@ -124,14 +124,15 @@ user_hooks = None
|
|||
STATE_NORMAL, STATE_DOWNLOADED, STATE_DELETED = range(3)
|
||||
|
||||
# Default locations for configuration and data files
|
||||
default_home = os.path.expanduser(os.path.join('~', '.config', 'gpodder'))
|
||||
default_home = os.path.expanduser(os.path.join('~', 'gPodder'))
|
||||
home = os.environ.get('GPODDER_HOME', None)
|
||||
if home is None:
|
||||
home = default_home
|
||||
else:
|
||||
print >>sys.stderr, 'Using', home, 'to store data (GPODDER_HOME is set)'
|
||||
config_file = os.path.join(home, 'gpodder.conf')
|
||||
database_file = os.path.join(home, 'gpodder.db')
|
||||
config_file = os.path.join(home, 'Settings')
|
||||
database_file = os.path.join(home, 'Database')
|
||||
downloads = os.path.join(home, 'Downloads')
|
||||
|
||||
# Plugins to load by default
|
||||
DEFAULT_PLUGINS = ['gpodder.soundcloud', 'gpodder.xspf']
|
||||
|
|
|
@ -183,7 +183,7 @@ class PodcastClient(object):
|
|||
|
||||
Returns all the subscribed podcasts from gPodder.
|
||||
"""
|
||||
return [Podcast(p, self) for p in PodcastChannel.load_from_db(self._db, self._config.download_dir)]
|
||||
return [Podcast(p, self) for p in PodcastChannel.load_from_db(self._db)]
|
||||
|
||||
def get_podcast(self, url):
|
||||
"""Get a specific podcast by URL
|
||||
|
@ -192,7 +192,7 @@ class PodcastClient(object):
|
|||
the podcast has not been subscribed to.
|
||||
"""
|
||||
url = util.normalize_feed_url(url)
|
||||
channel = PodcastChannel.load(self._db, url, create=False, download_dir=self._config.download_dir)
|
||||
channel = PodcastChannel.load(self._db, url, create=False)
|
||||
if channel is None:
|
||||
return None
|
||||
else:
|
||||
|
@ -208,7 +208,6 @@ class PodcastClient(object):
|
|||
url = util.normalize_feed_url(url)
|
||||
podcast = PodcastChannel.load(self._db, url, create=True, \
|
||||
max_episodes=self._config.max_episodes_per_feed, \
|
||||
download_dir=self._config.download_dir, \
|
||||
mimetype_prefs=self._config.mimetype_prefs)
|
||||
if podcast is not None:
|
||||
if title is not None:
|
||||
|
@ -231,7 +230,7 @@ class PodcastClient(object):
|
|||
This has to be called from the API user after
|
||||
data-changing actions have been carried out.
|
||||
"""
|
||||
podcasts = PodcastChannel.load_from_db(self._db, self._config.download_dir)
|
||||
podcasts = PodcastChannel.load_from_db(self._db)
|
||||
self._db.commit()
|
||||
return True
|
||||
|
||||
|
|
|
@ -36,18 +36,7 @@ import ConfigParser
|
|||
|
||||
_ = gpodder.gettext
|
||||
|
||||
if gpodder.ui.fremantle:
|
||||
default_download_dir = os.path.join(os.path.expanduser('~'), 'MyDocs/Podcasts')
|
||||
elif gpodder.ui.diablo:
|
||||
default_download_dir = '/media/mmc2/gpodder'
|
||||
else:
|
||||
default_download_dir = os.path.join(os.path.expanduser('~'), 'gpodder-downloads')
|
||||
|
||||
|
||||
gPodderSettings = {
|
||||
# Directory where downloads are saved
|
||||
'download_dir': default_download_dir,
|
||||
|
||||
# External applications used for playback
|
||||
'player': 'default',
|
||||
'videoplayer': 'default',
|
||||
|
@ -180,11 +169,6 @@ class Config(dict):
|
|||
|
||||
self.load()
|
||||
|
||||
download_dir = os.environ.get('GPODDER_DOWNLOAD_DIR', None)
|
||||
if download_dir is not None:
|
||||
log('Setting download_dir from environment: %s', download_dir, sender=self)
|
||||
self.download_dir = download_dir
|
||||
|
||||
atexit.register( self.__atexit)
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
|
|
@ -42,8 +42,8 @@ def synchronize_device(db, config):
|
|||
device.register('progress', callback_progress)
|
||||
|
||||
if device.open():
|
||||
channels = [c for c in PodcastChannel.load_from_db(db, \
|
||||
config.download_dir) if c.sync_to_devices]
|
||||
channels = [c for c in PodcastChannel.load_from_db(db) \
|
||||
if c.sync_to_devices]
|
||||
|
||||
for channel in channels:
|
||||
episodes = [e for e in channel.get_downloaded_episodes() \
|
||||
|
|
|
@ -510,7 +510,7 @@ class PodcastChannelProxy(object):
|
|||
self._save_dir_size_set = True
|
||||
|
||||
def update_save_dir_size(self):
|
||||
self.save_dir_size = util.calculate_size(self._config.download_dir)
|
||||
self.save_dir_size = util.calculate_size(gpodder.downloads)
|
||||
|
||||
|
||||
class PodcastListModel(gtk.ListStore):
|
||||
|
|
|
@ -455,7 +455,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
# Subscribed channels
|
||||
self.active_channel = None
|
||||
self.channels = PodcastChannel.load_from_db(self.db, self.config.download_dir)
|
||||
self.channels = PodcastChannel.load_from_db(self.db)
|
||||
self.channel_list_changed = True
|
||||
self.update_podcasts_tab()
|
||||
|
||||
|
@ -481,7 +481,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
def find_partial_downloads():
|
||||
# Look for partial file downloads
|
||||
partial_files = glob.glob(os.path.join(self.config.download_dir, '*', '*.partial'))
|
||||
partial_files = glob.glob(os.path.join(gpodder.downloads, '*', '*.partial'))
|
||||
count = len(partial_files)
|
||||
resumable_episodes = []
|
||||
if count:
|
||||
|
@ -583,7 +583,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
if uri.startswith('/'):
|
||||
uri = 'file://' + uri
|
||||
|
||||
prefix = 'file://' + self.config.download_dir
|
||||
prefix = 'file://' + gpodder.downloads
|
||||
|
||||
if uri.startswith(prefix):
|
||||
# File is on the local filesystem in the download folder
|
||||
|
@ -2081,16 +2081,16 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
def clean_up_downloads(self, delete_partial=False):
|
||||
# Clean up temporary files left behind by old gPodder versions
|
||||
temporary_files = glob.glob('%s/*/.tmp-*' % self.config.download_dir)
|
||||
temporary_files = glob.glob('%s/*/.tmp-*' % gpodder.downloads)
|
||||
|
||||
if delete_partial:
|
||||
temporary_files += glob.glob('%s/*/*.partial' % self.config.download_dir)
|
||||
temporary_files += glob.glob('%s/*/*.partial' % gpodder.downloads)
|
||||
|
||||
for tempfile in temporary_files:
|
||||
util.delete_file(tempfile)
|
||||
|
||||
# Clean up empty download folders and abandoned download folders
|
||||
download_dirs = glob.glob(os.path.join(self.config.download_dir, '*'))
|
||||
download_dirs = glob.glob(os.path.join(gpodder.downloads, '*'))
|
||||
for ddir in download_dirs:
|
||||
if os.path.isdir(ddir) and False: # FIXME not db.channel_foldername_exists(os.path.basename(ddir)):
|
||||
globr = glob.glob(os.path.join(ddir, '*'))
|
||||
|
@ -2646,7 +2646,6 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
channel = PodcastChannel.load(self.db, url=url, create=True, \
|
||||
authentication_tokens=auth_tokens.get(url, None), \
|
||||
max_episodes=self.config.max_episodes_per_feed, \
|
||||
download_dir=self.config.download_dir, \
|
||||
mimetype_prefs=self.config.mimetype_prefs)
|
||||
|
||||
try:
|
||||
|
@ -2755,7 +2754,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.db.commit()
|
||||
self.updating_feed_cache = False
|
||||
|
||||
self.channels = PodcastChannel.load_from_db(self.db, self.config.download_dir)
|
||||
self.channels = PodcastChannel.load_from_db(self.db)
|
||||
|
||||
# Process received episode actions for all updated URLs
|
||||
self.process_received_episode_actions(updated_urls)
|
||||
|
@ -2940,7 +2939,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
return
|
||||
|
||||
if not force_update:
|
||||
self.channels = PodcastChannel.load_from_db(self.db, self.config.download_dir)
|
||||
self.channels = PodcastChannel.load_from_db(self.db)
|
||||
self.channel_list_changed = True
|
||||
self.update_podcast_list_model(select_url=select_url_afterwards)
|
||||
return
|
||||
|
@ -4137,21 +4136,6 @@ def main(options=None):
|
|||
if user_hooks.has_modules():
|
||||
gpodder.user_hooks = user_hooks
|
||||
|
||||
if gpodder.ui.diablo:
|
||||
# Detect changing of SD cards between mmc1/mmc2 if a gpodder
|
||||
# folder exists there (allow moving "gpodder" between SD cards or USB)
|
||||
# Also allow moving "gpodder" to home folder (e.g. rootfs on SD)
|
||||
if not os.path.exists(config.download_dir):
|
||||
log('Downloads might have been moved. Trying to locate them...')
|
||||
for basedir in ['/media/mmc1', '/media/mmc2']+glob.glob('/media/usb/*')+['/home/user/MyDocs']:
|
||||
dir = os.path.join(basedir, 'gpodder')
|
||||
if os.path.exists(dir):
|
||||
log('Downloads found in: %s', dir)
|
||||
config.download_dir = dir
|
||||
break
|
||||
else:
|
||||
log('Downloads NOT FOUND in %s', dir)
|
||||
|
||||
config.mygpo_device_type = util.detect_device_type()
|
||||
|
||||
gp = gPodder(bus_name, config)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"""
|
||||
Loads and executes user hooks.
|
||||
|
||||
Hooks are python scripts in ~/.config/gpodder/hooks. Each script
|
||||
Hooks are python scripts in the "Hooks" folder of $GPODDER_HOME. Each script
|
||||
must define a class named "gPodderHooks", otherwise it will be ignored.
|
||||
|
||||
The hooks class defines several callbacks that will be called by the
|
||||
|
@ -69,7 +69,7 @@ class HookManager(object):
|
|||
"""Create a new hook manager"""
|
||||
self.modules = []
|
||||
|
||||
for filename in glob.glob(os.path.join(gpodder.home, 'hooks', '*.py')):
|
||||
for filename in glob.glob(os.path.join(gpodder.home, 'Hooks', '*.py')):
|
||||
try:
|
||||
module = self._load_module(filename)
|
||||
if module is not None:
|
||||
|
@ -95,7 +95,7 @@ class HookManager(object):
|
|||
such a class.
|
||||
"""
|
||||
basename, extension = os.path.splitext(os.path.basename(filepath))
|
||||
module = imp.load_module(basename, file(filepath, 'r'), os.path.dirname(filepath), (extension, 'r', imp.PY_SOURCE))
|
||||
module = imp.load_module(basename, file(filepath, 'r'), filepath, (extension, 'r', imp.PY_SOURCE))
|
||||
hook_class = getattr(module, HookManager.HOOK_CLASS, None)
|
||||
|
||||
if hook_class is None:
|
||||
|
|
|
@ -64,17 +64,13 @@ if __name__ == '__main__':
|
|||
gpodder.images_folder = images_folder
|
||||
gpodder.ui.desktop = True
|
||||
|
||||
# Portable version support
|
||||
if (os.path.exists('downloads') and os.path.exists('config')) or \
|
||||
not os.path.exists(os.path.expanduser('~/.config/gpodder')):
|
||||
home = os.path.join(os.getcwd(), 'config')
|
||||
if not os.path.exists(home):
|
||||
os.mkdir(home)
|
||||
gpodder.home = home
|
||||
gpodder.config_file = os.path.join(home, 'gpodder.conf')
|
||||
gpodder.database_file = os.path.join(home, 'gpodder.db')
|
||||
download_dir = os.path.join(os.getcwd(), 'downloads')
|
||||
os.environ['GPODDER_DOWNLOAD_DIR'] = download_dir
|
||||
home = os.path.join(os.getcwd())
|
||||
if not os.path.exists(home):
|
||||
os.mkdir(home)
|
||||
gpodder.home = home
|
||||
gpodder.config_file = os.path.join(home, 'Settings')
|
||||
gpodder.database_file = os.path.join(home, 'Database')
|
||||
gpodder.downloads = os.path.join(home, 'Downloads')
|
||||
|
||||
from gpodder import gui
|
||||
|
||||
|
|
|
@ -120,27 +120,21 @@ class PodcastChannel(PodcastModelObject):
|
|||
feed_fetcher = gPodderFetcher()
|
||||
|
||||
@classmethod
|
||||
def build_factory(cls, download_dir):
|
||||
def factory(dict, db):
|
||||
return cls.create_from_dict(dict, db, download_dir)
|
||||
return factory
|
||||
|
||||
@classmethod
|
||||
def load_from_db(cls, db, download_dir):
|
||||
return db.load_channels(factory=cls.build_factory(download_dir))
|
||||
def load_from_db(cls, db):
|
||||
return db.load_channels(factory=cls.create_from_dict)
|
||||
|
||||
@classmethod
|
||||
def load(cls, db, url, create=True, authentication_tokens=None,\
|
||||
max_episodes=0, download_dir=None, \
|
||||
max_episodes=0, \
|
||||
mimetype_prefs=''):
|
||||
if isinstance(url, unicode):
|
||||
url = url.encode('utf-8')
|
||||
|
||||
tmp = db.load_channels(factory=cls.build_factory(download_dir), url=url)
|
||||
tmp = db.load_channels(factory=cls.create_from_dict, url=url)
|
||||
if len(tmp):
|
||||
return tmp[0]
|
||||
elif create:
|
||||
tmp = PodcastChannel(db, download_dir)
|
||||
tmp = PodcastChannel(db)
|
||||
tmp.url = url
|
||||
if authentication_tokens is not None:
|
||||
tmp.username = authentication_tokens[0]
|
||||
|
@ -362,9 +356,8 @@ class PodcastChannel(PodcastModelObject):
|
|||
def authenticate_url(self, url):
|
||||
return util.url_add_authentication(url, self.username, self.password)
|
||||
|
||||
def __init__(self, db, download_dir):
|
||||
def __init__(self, db):
|
||||
self.db = db
|
||||
self.download_dir = download_dir
|
||||
self.id = None
|
||||
self.url = None
|
||||
self.title = ''
|
||||
|
@ -435,8 +428,8 @@ class PodcastChannel(PodcastModelObject):
|
|||
new_folder_name = self.find_unique_folder_name(custom_title)
|
||||
if len(new_folder_name) > 0 and new_folder_name != self.foldername:
|
||||
log('Changing foldername based on custom title: %s', custom_title, sender=self)
|
||||
new_folder = os.path.join(self.download_dir, new_folder_name)
|
||||
old_folder = os.path.join(self.download_dir, self.foldername)
|
||||
new_folder = os.path.join(gpodder.downloads, new_folder_name)
|
||||
old_folder = os.path.join(gpodder.downloads, self.foldername)
|
||||
if os.path.exists(old_folder):
|
||||
if not os.path.exists(new_folder):
|
||||
# Old folder exists, new folder does not -> simply rename
|
||||
|
@ -540,15 +533,15 @@ class PodcastChannel(PodcastModelObject):
|
|||
wanted_foldername = self.find_unique_folder_name(fn_template)
|
||||
|
||||
# if the foldername has not been set, check if the (old) md5 filename exists
|
||||
if self.foldername is None and os.path.exists(os.path.join(self.download_dir, urldigest)):
|
||||
if self.foldername is None and os.path.exists(os.path.join(gpodder.downloads, urldigest)):
|
||||
log('Found pre-0.15.0 download folder for %s: %s', self.title, urldigest, sender=self)
|
||||
self.foldername = urldigest
|
||||
|
||||
# we have a valid, new folder name in "current_try" -> use that!
|
||||
if self.foldername is not None and wanted_foldername != self.foldername:
|
||||
# there might be an old download folder crawling around - move it!
|
||||
new_folder_name = os.path.join(self.download_dir, wanted_foldername)
|
||||
old_folder_name = os.path.join(self.download_dir, self.foldername)
|
||||
new_folder_name = os.path.join(gpodder.downloads, wanted_foldername)
|
||||
old_folder_name = os.path.join(gpodder.downloads, self.foldername)
|
||||
if os.path.exists(old_folder_name):
|
||||
if not os.path.exists(new_folder_name):
|
||||
# Old folder exists, new folder does not -> simply rename
|
||||
|
@ -565,7 +558,7 @@ class PodcastChannel(PodcastModelObject):
|
|||
self.foldername = wanted_foldername
|
||||
self.save()
|
||||
|
||||
save_dir = os.path.join(self.download_dir, self.foldername)
|
||||
save_dir = os.path.join(gpodder.downloads, self.foldername)
|
||||
|
||||
# Create save_dir if it does not yet exist
|
||||
if not util.make_directory( save_dir):
|
||||
|
|
|
@ -164,7 +164,7 @@ class Change(object):
|
|||
|
||||
|
||||
class MygPoClient(object):
|
||||
STORE_FILE = 'mygpo.queue.sqlite'
|
||||
STORE_FILE = 'gpodder.net'
|
||||
FLUSH_TIMEOUT = 60
|
||||
FLUSH_RETRIES = 3
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class qtPodder(QApplication):
|
|||
def __init__(self, args, config, db):
|
||||
QApplication.__init__(self, args)
|
||||
|
||||
podcasts = model.PodcastChannel.load_from_db(db, config.download_dir)
|
||||
podcasts = model.PodcastChannel.load_from_db(db)
|
||||
|
||||
self.podcast_list = gPodderListView(self.on_podcast_selected)
|
||||
self.podcast_list.setModel(gPodderListModel(podcasts))
|
||||
|
|
|
@ -98,7 +98,7 @@ def get_metadata(url):
|
|||
class SoundcloudUser(object):
|
||||
def __init__(self, username):
|
||||
self.username = username
|
||||
self.cache_file = os.path.join(gpodder.home, 'soundcloud.cache')
|
||||
self.cache_file = os.path.join(gpodder.home, 'Soundcloud')
|
||||
if os.path.exists(self.cache_file):
|
||||
try:
|
||||
self.cache = json.load(open(self.cache_file, 'r'))
|
||||
|
|
Loading…
Reference in New Issue