Remove dependency on libgpodder/gPodderLib for most modules
Some modules are still left that need some more refactoring. These are: gui.py and libpodcasts.py. All other modules now have their dependency on gPodderLib or the config object (almost all really just depend on the config object) injected instead of accessing a global variable.
This commit is contained in:
parent
b2fc9dc777
commit
a67174a597
|
@ -121,7 +121,7 @@ def run():
|
|||
db.commit()
|
||||
|
||||
def sync_device():
|
||||
device = sync.open_device()
|
||||
device = sync.open_device(gl.config)
|
||||
if device is None:
|
||||
msg('error', _('No device configured. Please use the GUI.'))
|
||||
return False
|
||||
|
@ -155,7 +155,7 @@ def sync_device():
|
|||
|
||||
def sync_stats():
|
||||
size = 0
|
||||
device = sync.open_device()
|
||||
device = sync.open_device(gl.config)
|
||||
if device is None:
|
||||
msg('error', _('No device configured. Please use the GUI.'))
|
||||
return False
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
from gpodder.liblogger import log
|
||||
from gpodder.libgpodder import gl
|
||||
from gpodder import util
|
||||
from gpodder import resolver
|
||||
import gpodder
|
||||
|
@ -322,8 +321,9 @@ class DownloadQueueWorker(threading.Thread):
|
|||
|
||||
|
||||
class DownloadQueueManager(object):
|
||||
def __init__(self, download_status_manager):
|
||||
def __init__(self, download_status_manager, config):
|
||||
self.download_status_manager = download_status_manager
|
||||
self._config = config
|
||||
self.tasks = collections.deque()
|
||||
|
||||
self.worker_threads_access = threading.RLock()
|
||||
|
@ -335,16 +335,16 @@ class DownloadQueueManager(object):
|
|||
|
||||
def spawn_and_retire_threads(self, request_new_thread=False):
|
||||
with self.worker_threads_access:
|
||||
if len(self.worker_threads) > gl.config.max_downloads and \
|
||||
gl.config.max_downloads_enabled:
|
||||
if len(self.worker_threads) > self._config.max_downloads and \
|
||||
self._config.max_downloads_enabled:
|
||||
# Tell the excessive amount of oldest worker threads to quit, but keep at least one
|
||||
count = min(len(self.worker_threads)-1, len(self.worker_threads)-gl.config.max_downloads)
|
||||
count = min(len(self.worker_threads)-1, len(self.worker_threads)-self._config.max_downloads)
|
||||
for worker in self.worker_threads[:count]:
|
||||
worker.stop_accepting_tasks()
|
||||
|
||||
if request_new_thread and (len(self.worker_threads) == 0 or \
|
||||
len(self.worker_threads) < gl.config.max_downloads or \
|
||||
not gl.config.max_downloads_enabled):
|
||||
len(self.worker_threads) < self._config.max_downloads or \
|
||||
not self._config.max_downloads_enabled):
|
||||
# We have to create a new thread here, there's work to do
|
||||
log('I am going to spawn a new worker thread.', sender=self)
|
||||
worker = DownloadQueueWorker(self.tasks, self.__exit_callback)
|
||||
|
@ -372,7 +372,7 @@ class DownloadTask(object):
|
|||
|
||||
You can create a new download task like this:
|
||||
|
||||
task = DownloadTask(episode)
|
||||
task = DownloadTask(episode, gpodder.config.Config(CONFIGFILE))
|
||||
task.status = DownloadTask.QUEUED
|
||||
task.run()
|
||||
|
||||
|
@ -477,10 +477,11 @@ class DownloadTask(object):
|
|||
if self.status != self.DONE:
|
||||
util.delete_file(self.tempname)
|
||||
|
||||
def __init__(self, episode):
|
||||
def __init__(self, episode, config):
|
||||
self.__status = DownloadTask.INIT
|
||||
self.__status_changed = True
|
||||
self.__episode = episode
|
||||
self._config = config
|
||||
|
||||
# Create the target filename and save it in the database
|
||||
self.filename = self.__episode.local_filename(create=True)
|
||||
|
@ -494,8 +495,8 @@ class DownloadTask(object):
|
|||
# Variables for speed limit and speed calculation
|
||||
self.__start_time = 0
|
||||
self.__start_blocks = 0
|
||||
self.__limit_rate_value = gl.config.limit_rate_value
|
||||
self.__limit_rate = gl.config.limit_rate
|
||||
self.__limit_rate_value = self._config.limit_rate_value
|
||||
self.__limit_rate = self._config.limit_rate
|
||||
|
||||
# If the tempname already exists, set progress accordingly
|
||||
if os.path.exists(self.tempname):
|
||||
|
@ -532,18 +533,18 @@ class DownloadTask(object):
|
|||
now = time.time()
|
||||
if self.__start_time > 0:
|
||||
# Has rate limiting been enabled or disabled?
|
||||
if self.__limit_rate != gl.config.limit_rate:
|
||||
if self.__limit_rate != self._config.limit_rate:
|
||||
# If it has been enabled then reset base time and block count
|
||||
if gl.config.limit_rate:
|
||||
if self._config.limit_rate:
|
||||
self.__start_time = now
|
||||
self.__start_blocks = count
|
||||
self.__limit_rate = gl.config.limit_rate
|
||||
self.__limit_rate = self._config.limit_rate
|
||||
|
||||
# Has the rate been changed and are we currently limiting?
|
||||
if self.__limit_rate_value != gl.config.limit_rate_value and self.__limit_rate:
|
||||
if self.__limit_rate_value != self._config.limit_rate_value and self.__limit_rate:
|
||||
self.__start_time = now
|
||||
self.__start_blocks = count
|
||||
self.__limit_rate_value = gl.config.limit_rate_value
|
||||
self.__limit_rate_value = self._config.limit_rate_value
|
||||
|
||||
passed = now - self.__start_time
|
||||
if passed > 0:
|
||||
|
@ -558,10 +559,10 @@ class DownloadTask(object):
|
|||
|
||||
self.speed = float(speed)
|
||||
|
||||
if gl.config.limit_rate and speed > gl.config.limit_rate_value:
|
||||
if self._config.limit_rate and speed > self._config.limit_rate_value:
|
||||
# calculate the time that should have passed to reach
|
||||
# the desired download rate and wait if necessary
|
||||
should_have_passed = float((count-self.__start_blocks)*blockSize)/(gl.config.limit_rate_value*1024.0)
|
||||
should_have_passed = float((count-self.__start_blocks)*blockSize)/(self._config.limit_rate_value*1024.0)
|
||||
if should_have_passed > passed:
|
||||
# sleep a maximum of 10 seconds to not cause time-outs
|
||||
delay = min(10.0, float(should_have_passed-passed))
|
||||
|
@ -611,7 +612,7 @@ class DownloadTask(object):
|
|||
self.__episode.channel.addDownloadedItem(self.__episode)
|
||||
|
||||
# If a user command has been defined, execute the command setting some environment variables
|
||||
if len(gl.config.cmd_download_complete) > 0:
|
||||
if len(self._config.cmd_download_complete) > 0:
|
||||
os.environ["GPODDER_EPISODE_URL"]=self.__episode.url or ''
|
||||
os.environ["GPODDER_EPISODE_TITLE"]=self.__episode.title or ''
|
||||
os.environ["GPODDER_EPISODE_FILENAME"]=self.filename or ''
|
||||
|
@ -619,7 +620,7 @@ class DownloadTask(object):
|
|||
os.environ["GPODDER_EPISODE_LINK"]=self.__episode.link or ''
|
||||
os.environ["GPODDER_EPISODE_DESC"]=self.__episode.description or ''
|
||||
os.environ["GPODDER_CHANNEL_TITLE"]=self.__episode.channel.title or ''
|
||||
util.run_external_command(gl.config.cmd_download_complete)
|
||||
util.run_external_command(self._config.cmd_download_complete)
|
||||
except DownloadCancelledException:
|
||||
log('Download has been cancelled/paused: %s', self, sender=self)
|
||||
if self.status == DownloadTask.CANCELLED:
|
||||
|
|
|
@ -503,7 +503,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.gpodder_episode_window = None
|
||||
|
||||
self.download_status_manager = services.DownloadStatusManager()
|
||||
self.download_queue_manager = download.DownloadQueueManager(self.download_status_manager)
|
||||
self.download_queue_manager = download.DownloadQueueManager(self.download_status_manager, gl.config)
|
||||
|
||||
self.fullscreen = False
|
||||
self.minimized = False
|
||||
|
@ -2442,7 +2442,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
continue
|
||||
|
||||
try:
|
||||
task = download.DownloadTask(episode)
|
||||
task = download.DownloadTask(episode, gl.config)
|
||||
except Exception, e:
|
||||
self.show_message(_('Download error while downloading %s:\n\n%s') % (episode.title, str(e)), _('Download error'))
|
||||
log('Download error while downloading %s', episode.title, sender=self, traceback=True)
|
||||
|
@ -2529,7 +2529,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.notification( message, title )
|
||||
return
|
||||
|
||||
device = sync.open_device()
|
||||
device = sync.open_device(gl.config)
|
||||
device.register( 'post-done', self.sync_to_ipod_completed )
|
||||
|
||||
if device is None:
|
||||
|
@ -2639,7 +2639,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
('released', None, None, _('Released')),
|
||||
)
|
||||
|
||||
device = sync.open_device()
|
||||
device = sync.open_device(gl.config)
|
||||
|
||||
if device is None:
|
||||
title = _('No device configured')
|
||||
|
@ -2689,7 +2689,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.notification( message, title )
|
||||
return
|
||||
|
||||
device = sync.open_device()
|
||||
device = sync.open_device(gl.config)
|
||||
|
||||
if device is None:
|
||||
title = _('No device configured')
|
||||
|
@ -2708,7 +2708,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
|
||||
def show_hide_tray_icon(self):
|
||||
if gl.config.display_tray_icon and have_trayicon and self.tray_icon is None:
|
||||
self.tray_icon = trayicon.GPodderStatusIcon(self, gpodder.icon_file)
|
||||
self.tray_icon = trayicon.GPodderStatusIcon(self, gpodder.icon_file, gl.config)
|
||||
elif not gl.config.display_tray_icon and self.tray_icon is not None:
|
||||
self.tray_icon.set_visible(False)
|
||||
del self.tray_icon
|
||||
|
@ -3567,7 +3567,7 @@ class gPodderProperties(BuilderWidget):
|
|||
|
||||
self.iPodMountpoint.set_label( gl.config.ipod_mount)
|
||||
self.filesystemMountpoint.set_label( gl.config.mp3_player_folder)
|
||||
self.chooserDownloadTo.set_current_folder(gl.downloaddir)
|
||||
self.chooserDownloadTo.set_current_folder(gl.config.download_dir)
|
||||
|
||||
self.on_sync_delete.set_sensitive(not self.delete_episodes_marked_played.get_active())
|
||||
self.on_sync_mark_played.set_sensitive(not self.delete_episodes_marked_played.get_active())
|
||||
|
@ -3662,14 +3662,6 @@ class gPodderProperties(BuilderWidget):
|
|||
# return index of custom command or first item
|
||||
return max(0, index_custom)
|
||||
|
||||
def set_download_dir( self, new_download_dir, event = None):
|
||||
gl.downloaddir = self.chooserDownloadTo.get_filename()
|
||||
if gl.downloaddir != self.chooserDownloadTo.get_filename():
|
||||
self.notification(_('There has been an error moving your downloads to the specified location. The old download directory will be used instead.'), _('Error moving downloads'))
|
||||
|
||||
if event:
|
||||
event.set()
|
||||
|
||||
def on_auto_update_feeds_toggled( self, widget, *args):
|
||||
self.auto_update_frequency.set_sensitive(widget.get_active())
|
||||
|
||||
|
@ -3814,57 +3806,7 @@ class gPodderProperties(BuilderWidget):
|
|||
gl.config.ipod_mount = self.iPodMountpoint.get_label()
|
||||
gl.config.mp3_player_folder = self.filesystemMountpoint.get_label()
|
||||
|
||||
if gl.downloaddir != self.chooserDownloadTo.get_filename():
|
||||
new_download_dir = self.chooserDownloadTo.get_filename()
|
||||
download_dir_size = util.calculate_size( gl.downloaddir)
|
||||
download_dir_size_string = util.format_filesize( download_dir_size)
|
||||
event = Event()
|
||||
|
||||
dlg = gtk.Dialog( _('Moving downloads folder'), self.gPodderProperties)
|
||||
dlg.vbox.set_spacing( 5)
|
||||
dlg.set_border_width( 5)
|
||||
|
||||
label = gtk.Label()
|
||||
label.set_line_wrap( True)
|
||||
label.set_markup( _('Moving downloads from <b>%s</b> to <b>%s</b>...') % ( saxutils.escape( gl.downloaddir), saxutils.escape( new_download_dir), ))
|
||||
myprogressbar = gtk.ProgressBar()
|
||||
|
||||
# put it all together
|
||||
dlg.vbox.pack_start( label)
|
||||
dlg.vbox.pack_end( myprogressbar)
|
||||
|
||||
# switch windows
|
||||
dlg.show_all()
|
||||
self.gPodderProperties.hide_all()
|
||||
|
||||
# hide action area and separator line
|
||||
dlg.action_area.hide()
|
||||
dlg.set_has_separator( False)
|
||||
|
||||
args = ( new_download_dir, event, )
|
||||
|
||||
thread = Thread( target = self.set_download_dir, args = args)
|
||||
thread.start()
|
||||
|
||||
while not event.isSet():
|
||||
try:
|
||||
new_download_dir_size = util.calculate_size( new_download_dir)
|
||||
except:
|
||||
new_download_dir_size = 0
|
||||
if download_dir_size > 0:
|
||||
fract = (1.00*new_download_dir_size) / (1.00*download_dir_size)
|
||||
else:
|
||||
fract = 0.0
|
||||
if fract < 0.99:
|
||||
myprogressbar.set_text( _('%s of %s') % ( util.format_filesize( new_download_dir_size), download_dir_size_string, ))
|
||||
else:
|
||||
myprogressbar.set_text( _('Finishing... please wait.'))
|
||||
myprogressbar.set_fraction(max(0.0,min(1.0,fract)))
|
||||
event.wait( 0.1)
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration( False)
|
||||
|
||||
dlg.destroy()
|
||||
# FIXME: set gl.config.download_dir to self.chooserDownloadTo.get_filename() and move download folder!
|
||||
|
||||
device_type = self.comboboxDeviceType.get_active()
|
||||
if device_type == 0:
|
||||
|
|
|
@ -71,20 +71,20 @@ class gPodderLib(object):
|
|||
self.database_file = os.path.join(gpodder_dir, 'database.sqlite')
|
||||
|
||||
def find_partial_files(self):
|
||||
return glob.glob(os.path.join(self.downloaddir, '*', '*.partial'))
|
||||
return glob.glob(os.path.join(self.config.download_dir, '*', '*.partial'))
|
||||
|
||||
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.downloaddir)
|
||||
temporary_files = glob.glob('%s/*/.tmp-*' % self.config.download_dir)
|
||||
|
||||
if delete_partial:
|
||||
temporary_files += glob.glob('%s/*/*.partial' % self.downloaddir)
|
||||
temporary_files += glob.glob('%s/*/*.partial' % self.config.download_dir)
|
||||
|
||||
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.downloaddir, '*'))
|
||||
download_dirs = glob.glob(os.path.join(self.config.download_dir, '*'))
|
||||
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, '*'))
|
||||
|
@ -92,33 +92,6 @@ class gPodderLib(object):
|
|||
log('Stale download directory found: %s', os.path.basename(ddir), sender=self)
|
||||
shutil.rmtree(ddir, ignore_errors=True)
|
||||
|
||||
def get_download_dir( self):
|
||||
util.make_directory( self.config.download_dir)
|
||||
return self.config.download_dir
|
||||
|
||||
def set_download_dir( self, new_downloaddir):
|
||||
if self.config.download_dir != new_downloaddir:
|
||||
log( 'Moving downloads from %s to %s', self.config.download_dir, new_downloaddir)
|
||||
try:
|
||||
# Fix error when moving over disk boundaries
|
||||
if os.path.isdir( new_downloaddir) and not os.listdir( new_downloaddir):
|
||||
os.rmdir( new_downloaddir)
|
||||
|
||||
shutil.move( self.config.download_dir, new_downloaddir)
|
||||
except NameError:
|
||||
log( 'Fixing a bug in shutil. See http://bugs.python.org/issue2549')
|
||||
errno = subprocess.call(["rm", "-rf", self.config.download_dir])
|
||||
if errno <> 0:
|
||||
log( 'Error while deleting %s: rm returned error %i', self.config.download_dir, errno)
|
||||
return
|
||||
except Exception, exc:
|
||||
log( 'Error while moving %s to %s: %s',self.config.download_dir, new_downloaddir, exc)
|
||||
return
|
||||
|
||||
self.config.download_dir = new_downloaddir
|
||||
|
||||
downloaddir = property(fget=get_download_dir,fset=set_download_dir)
|
||||
|
||||
def streaming_possible(self):
|
||||
return self.config.player and self.config.player != 'default'
|
||||
|
||||
|
|
|
@ -398,8 +398,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(gl.downloaddir, new_folder_name)
|
||||
old_folder = os.path.join(gl.downloaddir, self.foldername)
|
||||
new_folder = os.path.join(gl.config.download_dir, new_folder_name)
|
||||
old_folder = os.path.join(gl.config.download_dir, self.foldername)
|
||||
if os.path.exists(old_folder):
|
||||
if not os.path.exists(new_folder):
|
||||
# Old folder exists, new folder does not -> simply rename
|
||||
|
@ -446,7 +446,7 @@ class PodcastChannel(PodcastModelObject):
|
|||
factory=self.episode_factory) if check_is_new(episode)]
|
||||
|
||||
def update_m3u_playlist(self):
|
||||
m3u_filename = os.path.join(gl.downloaddir, os.path.basename(self.save_dir)+'.m3u')
|
||||
m3u_filename = os.path.join(gl.config.download_dir, os.path.basename(self.save_dir)+'.m3u')
|
||||
log('Writing playlist to %s', m3u_filename, sender=self)
|
||||
|
||||
f = open(m3u_filename, 'w')
|
||||
|
@ -585,15 +585,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(gl.downloaddir, urldigest)):
|
||||
if self.foldername is None and os.path.exists(os.path.join(gl.config.download_dir, 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(gl.downloaddir, wanted_foldername)
|
||||
old_folder_name = os.path.join(gl.downloaddir, self.foldername)
|
||||
new_folder_name = os.path.join(gl.config.download_dir, wanted_foldername)
|
||||
old_folder_name = os.path.join(gl.config.download_dir, 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
|
||||
|
@ -610,7 +610,7 @@ class PodcastChannel(PodcastModelObject):
|
|||
self.foldername = wanted_foldername
|
||||
self.save()
|
||||
|
||||
save_dir = os.path.join(gl.downloaddir, self.foldername)
|
||||
save_dir = os.path.join(gl.config.download_dir, self.foldername)
|
||||
|
||||
# Create save_dir if it does not yet exist
|
||||
if not util.make_directory( save_dir):
|
||||
|
|
|
@ -28,7 +28,6 @@ from __future__ import with_statement
|
|||
|
||||
import gpodder
|
||||
from gpodder.liblogger import log
|
||||
from gpodder.libgpodder import gl
|
||||
|
||||
from gpodder import util
|
||||
from gpodder import resolver
|
||||
|
|
|
@ -29,7 +29,6 @@ from gpodder import services
|
|||
from gpodder import libconverter
|
||||
|
||||
from gpodder.liblogger import log
|
||||
from gpodder.libgpodder import gl
|
||||
|
||||
import time
|
||||
import calendar
|
||||
|
@ -83,14 +82,14 @@ import email.Utils
|
|||
import re
|
||||
|
||||
|
||||
def open_device():
|
||||
device_type = gl.config.device_type
|
||||
def open_device(config):
|
||||
device_type = config.device_type
|
||||
if device_type == 'ipod':
|
||||
return iPodDevice()
|
||||
return iPodDevice(config)
|
||||
elif device_type == 'filesystem':
|
||||
return MP3PlayerDevice()
|
||||
return MP3PlayerDevice(config)
|
||||
elif device_type == 'mtp':
|
||||
return MTPDevice()
|
||||
return MTPDevice(config)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -153,7 +152,8 @@ class SyncTrack(object):
|
|||
|
||||
|
||||
class Device(services.ObservableService):
|
||||
def __init__(self):
|
||||
def __init__(self, config):
|
||||
self._config = config
|
||||
self.cancelled = False
|
||||
self.allowed_types = ['audio', 'video']
|
||||
self.errors = []
|
||||
|
@ -170,7 +170,7 @@ class Device(services.ObservableService):
|
|||
|
||||
def close(self):
|
||||
self.notify('status', _('Writing data to disk'))
|
||||
if gl.config.sync_disks_after_transfer:
|
||||
if self._config.sync_disks_after_transfer:
|
||||
successful_sync = (os.system('sync') == 0)
|
||||
else:
|
||||
log('Not syncing disks. Unmount your device before unplugging.', sender=self)
|
||||
|
@ -184,7 +184,7 @@ class Device(services.ObservableService):
|
|||
# Filter tracks that are not meant to be synchronized
|
||||
does_not_exist = not track.was_downloaded(and_exists=True)
|
||||
exclude_played = track.is_played and not force_played and \
|
||||
gl.config.only_sync_not_played
|
||||
self._config.only_sync_not_played
|
||||
wrong_type = track.file_type() not in self.allowed_types
|
||||
|
||||
if does_not_exist or exclude_played or wrong_type:
|
||||
|
@ -200,11 +200,11 @@ class Device(services.ObservableService):
|
|||
|
||||
added = self.add_track(track)
|
||||
|
||||
if gl.config.on_sync_mark_played:
|
||||
if self._config.on_sync_mark_played:
|
||||
log('Marking as played on transfer: %s', track.url, sender=self)
|
||||
track.mark(is_played=True)
|
||||
|
||||
if added and gl.config.on_sync_delete:
|
||||
if added and self._config.on_sync_delete:
|
||||
log('Removing episode after transfer: %s', track.url, sender=self)
|
||||
track.delete_from_disk()
|
||||
return True
|
||||
|
@ -216,7 +216,7 @@ class Device(services.ObservableService):
|
|||
assert filename is not None
|
||||
(fn, extension) = os.path.splitext(filename)
|
||||
if libconverter.converters.has_converter(extension):
|
||||
if gl.config.disable_pre_sync_conversion:
|
||||
if self._config.disable_pre_sync_conversion:
|
||||
log('Pre-sync conversion is not enabled, set disable_pre_sync_conversion to "False" to enable')
|
||||
return filename
|
||||
|
||||
|
@ -263,10 +263,10 @@ class Device(services.ObservableService):
|
|||
return False
|
||||
|
||||
class iPodDevice(Device):
|
||||
def __init__(self):
|
||||
Device.__init__(self)
|
||||
def __init__(self, config):
|
||||
Device.__init__(self, config)
|
||||
|
||||
self.mountpoint = str(gl.config.ipod_mount)
|
||||
self.mountpoint = str(self._config.ipod_mount)
|
||||
|
||||
self.itdb = None
|
||||
self.podcast_playlist = None
|
||||
|
@ -500,14 +500,9 @@ class MP3PlayerDevice(Device):
|
|||
# .scrobbler.log, add them to this list
|
||||
scrobbler_log_filenames = ['.scrobbler.log']
|
||||
|
||||
# This is the maximum length of a file name that is
|
||||
# created on the MP3 player, because FAT32 has a
|
||||
# 255-character limit for the whole path
|
||||
MAX_FILENAME_LENGTH = gl.config.mp3_player_max_filename_length
|
||||
|
||||
def __init__(self):
|
||||
Device.__init__(self)
|
||||
self.destination = gl.config.mp3_player_folder
|
||||
def __init__(self, config):
|
||||
Device.__init__(self, config)
|
||||
self.destination = self._config.mp3_player_folder
|
||||
self.buffer_size = 1024*1024 # 1 MiB
|
||||
self.scrobbler_log = []
|
||||
|
||||
|
@ -521,7 +516,7 @@ class MP3PlayerDevice(Device):
|
|||
self.notify('status', _('MP3 player opened'))
|
||||
# build the initial tracks_list
|
||||
self.tracks_list = self.get_all_tracks()
|
||||
if gl.config.mp3_player_use_scrobbler_log:
|
||||
if self._config.mp3_player_use_scrobbler_log:
|
||||
mp3_player_mount_point = util.find_mount_point(self.destination)
|
||||
# If a moint point cannot be found look inside self.destination for scrobbler_log_filenames
|
||||
# this prevents us from os.walk()'ing the entire / filesystem
|
||||
|
@ -537,17 +532,17 @@ class MP3PlayerDevice(Device):
|
|||
def add_track(self, episode):
|
||||
self.notify('status', _('Adding %s') % episode.title)
|
||||
|
||||
if gl.config.fssync_channel_subfolders:
|
||||
if self._config.fssync_channel_subfolders:
|
||||
# Add channel title as subfolder
|
||||
folder = episode.channel.title
|
||||
# Clean up the folder name for use on limited devices
|
||||
folder = util.sanitize_filename(folder, self.MAX_FILENAME_LENGTH)
|
||||
folder = util.sanitize_filename(folder, self._config.mp3_player_max_filename_length)
|
||||
folder = os.path.join(self.destination, folder)
|
||||
else:
|
||||
folder = self.destination
|
||||
|
||||
from_file = util.sanitize_encoding(self.convert_track(episode))
|
||||
filename_base = util.sanitize_filename(episode.sync_filename(), self.MAX_FILENAME_LENGTH)
|
||||
filename_base = util.sanitize_filename(episode.sync_filename(), self._config.mp3_player_max_filename_length)
|
||||
|
||||
to_file = filename_base + os.path.splitext(from_file)[1].lower()
|
||||
|
||||
|
@ -566,25 +561,25 @@ class MP3PlayerDevice(Device):
|
|||
log('Cannot create folder on MP3 player: %s', folder, sender=self)
|
||||
return False
|
||||
|
||||
if (gl.config.mp3_player_use_scrobbler_log and not episode.is_played
|
||||
if (self._config.mp3_player_use_scrobbler_log and not episode.is_played
|
||||
and [episode.channel.title, episode.title] in self.scrobbler_log):
|
||||
log('Marking "%s" from "%s" as played', episode.title, episode.channel.title, sender=self)
|
||||
episode.mark(is_played=True)
|
||||
|
||||
if gl.config.rockbox_copy_coverart and not os.path.exists(os.path.join(folder, 'cover.bmp')):
|
||||
if self._config.rockbox_copy_coverart and not os.path.exists(os.path.join(folder, 'cover.bmp')):
|
||||
log('Creating Rockbox album art for "%s"', episode.channel.title, sender=self)
|
||||
self.copy_player_cover_art(folder, from_file, \
|
||||
'cover.bmp', 'BMP', gl.config.rockbox_coverart_size)
|
||||
'cover.bmp', 'BMP', self._config.rockbox_coverart_size)
|
||||
|
||||
if gl.config.custom_player_copy_coverart \
|
||||
if self._config.custom_player_copy_coverart \
|
||||
and not os.path.exists(os.path.join(folder, \
|
||||
gl.config.custom_player_coverart_name)):
|
||||
self._config.custom_player_coverart_name)):
|
||||
log('Creating custom player album art for "%s"',
|
||||
episode.channel.title, sender=self)
|
||||
self.copy_player_cover_art(folder, from_file, \
|
||||
gl.config.custom_player_coverart_name, \
|
||||
gl.config.custom_player_coverart_format, \
|
||||
gl.config.custom_player_coverart_size)
|
||||
self._config.custom_player_coverart_name, \
|
||||
self._config.custom_player_coverart_format, \
|
||||
self._config.custom_player_coverart_size)
|
||||
|
||||
if not os.path.exists(to_file):
|
||||
log('Copying %s => %s', os.path.basename(from_file), to_file.decode(util.encoding), sender=self)
|
||||
|
@ -641,7 +636,7 @@ class MP3PlayerDevice(Device):
|
|||
def get_all_tracks(self):
|
||||
tracks = []
|
||||
|
||||
if gl.config.fssync_channel_subfolders:
|
||||
if self._config.fssync_channel_subfolders:
|
||||
files = glob.glob(os.path.join(self.destination, '*', '*'))
|
||||
else:
|
||||
files = glob.glob(os.path.join(self.destination, '*'))
|
||||
|
@ -652,7 +647,7 @@ class MP3PlayerDevice(Device):
|
|||
|
||||
timestamp = util.file_modification_timestamp(filename)
|
||||
modified = util.format_date(timestamp)
|
||||
if gl.config.fssync_channel_subfolders:
|
||||
if self._config.fssync_channel_subfolders:
|
||||
podcast_name = os.path.basename(os.path.dirname(filename))
|
||||
else:
|
||||
podcast_name = None
|
||||
|
@ -662,14 +657,14 @@ class MP3PlayerDevice(Device):
|
|||
return tracks
|
||||
|
||||
def episode_on_device(self, episode):
|
||||
e = util.sanitize_filename(episode.sync_filename(), gl.config.mp3_player_max_filename_length)
|
||||
e = util.sanitize_filename(episode.sync_filename(), self._config.mp3_player_max_filename_length)
|
||||
return self._track_on_device(e)
|
||||
|
||||
def remove_track(self, track):
|
||||
self.notify('status', _('Removing %s') % track.title)
|
||||
util.delete_file(track.filename)
|
||||
directory = os.path.dirname(track.filename)
|
||||
if self.directory_is_empty(directory) and gl.config.fssync_channel_subfolders:
|
||||
if self.directory_is_empty(directory) and self._config.fssync_channel_subfolders:
|
||||
try:
|
||||
os.rmdir(directory)
|
||||
except:
|
||||
|
@ -752,8 +747,8 @@ class MP3PlayerDevice(Device):
|
|||
return True
|
||||
|
||||
class MTPDevice(Device):
|
||||
def __init__(self):
|
||||
Device.__init__(self)
|
||||
def __init__(self, config):
|
||||
Device.__init__(self, config)
|
||||
self.__model_name = None
|
||||
self.__MTPDevice = pymtp.MTP()
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import datetime
|
|||
|
||||
import gpodder
|
||||
from gpodder.liblogger import log
|
||||
from gpodder.libgpodder import gl
|
||||
|
||||
_ = gpodder.gettext
|
||||
|
||||
|
@ -65,7 +64,7 @@ class GPodderStatusIcon(gtk.StatusIcon):
|
|||
STATUS_SYNCHRONIZING = (_('Synchronizing to player'), 'multimedia-player')
|
||||
STATUS_DELETING = (_('Cleaning files'), gtk.STOCK_DELETE)
|
||||
|
||||
def __init__(self, gp, icon_filename):
|
||||
def __init__(self, gp, icon_filename, config):
|
||||
gtk.StatusIcon.__init__(self)
|
||||
log('Creating tray icon', sender=self)
|
||||
|
||||
|
@ -122,9 +121,9 @@ class GPodderStatusIcon(gtk.StatusIcon):
|
|||
menu.append(menuItem)
|
||||
|
||||
# menus's label will adapt to the synchronisation device name
|
||||
if gl.config.device_type != 'none':
|
||||
if self._config.device_type != 'none':
|
||||
menuItem = gtk.ImageMenuItem(sync_label)
|
||||
menuItem.set_sensitive(gl.config.device_type != 'none')
|
||||
menuItem.set_sensitive(self._config.device_type != 'none')
|
||||
menuItem.set_image(gtk.image_new_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_MENU))
|
||||
menuItem.connect('activate', self.__gpodder.on_sync_to_ipod_activate)
|
||||
menu.append(menuItem)
|
||||
|
@ -242,7 +241,7 @@ class GPodderStatusIcon(gtk.StatusIcon):
|
|||
|
||||
def __is_notification_on(self):
|
||||
# tray icon not visible or notifications disabled
|
||||
if not self.get_visible() or not gl.config.enable_notifications:
|
||||
if not self.get_visible() or not self._config.enable_notifications:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in New Issue