Added new logging facility (liblogger.py)

git-svn-id: svn://svn.berlios.de/gpodder/trunk@174 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
Thomas Perl 2006-11-17 14:26:10 +00:00
parent 923fa5ad3e
commit 87d9efbb57
12 changed files with 117 additions and 240 deletions

View file

@ -1,3 +1,12 @@
Fri, 17 Nov 2006 11:10:42 +0100 <thp@perli.net>
* src/gpodder/liblogger.py: Added new logging facility
* src/gpodder/libgpodder.py: Removed isDebugging() and debug flag
* src/gpodder/*: Use new liblogger instead of isDebugging() in
libwget.py, liblocdbreader.py, libplayers.py, libpodcasts.py,
libgpodder.py, libipodsync.py, gpodder.py and liblocaldb.py
* TODO: Updated TODO list
* bin/gpodder: bumped release date again
Thu, 16 Nov 2006 23:44:43 +0100 <thp@perli.net>
* src/gpodder/liblocaldb.py: Applied modified version of patch
from Alain Tauch to fix a bug in liblocaldb.py; re-factored the

5
TODO
View file

@ -23,11 +23,6 @@
did show up in the 'downloaded' tab, it did once I closed and
re-opened gPodder. (thanks to Haim Roitgrund for reporting this)
* re-factor "if libgpodder.isDebugging()" + "print" into a more
sophisticated logging/debugging infrastructure (the code should
not "print" debug messages, but hand the debug strings to the
logging facility, something like: libgpodder.debug( "bla bla")
* in libipodsync.py: use mime magic instead of extension-based
video detection? --> also, is mp4 always video or could it be
aac audio too? if so, how to check what is what?

View file

@ -26,8 +26,8 @@
# PLEASE DO NOT CHANGE FORMAT OF __version__ LINE (setup.py reads this)
__author__ = "Thomas Perl <thp@perli.net>"
__version__ = "0.8.0+svn20061116"
__date__ = "2006-11-16"
__version__ = "0.8.0+svn20061117"
__date__ = "2006-11-17"
__copyright__ = "Copyright (c) 2005-2006 %s. All rights reserved." % __author__
__licence__ = "GPL"

View file

@ -53,6 +53,7 @@ from libwget import downloadStatusManager
from libgpodder import gPodderLib
from libgpodder import gPodderChannelReader
from libgpodder import gPodderChannelWriter
from liblogger import log
from liblocaldb import localDB
@ -61,9 +62,6 @@ from libplayers import UserAppsReader
from libipodsync import gPodder_iPodSync
from libipodsync import ipod_supported
# for isDebugging:
import libgpodder
app_name = "gpodder"
app_version = "unknown" # will be set in main() call
app_authors = [
@ -110,11 +108,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.new {
def new(self):
if libgpodder.isDebugging():
print "A new %s has been created" % self.__class__.__name__
#self.gPodder.set_title( self.gPodder.get_title())
#self.statusLabel.set_text( "Welcome to gPodder! Suggestions? Mail to: thp@perli.net")
# set up the rendering of the comboAvailable combobox
cellrenderer = gtk.CellRendererText()
self.comboAvailable.pack_start( cellrenderer, True)
@ -240,8 +233,7 @@ class Gpodder(SimpleGladeApp):
self.comboDownloaded.set_active( self.active_downloaded_channels)
except:
self.active_downloaded_channels = 0
if libgpodder.isDebugging():
print _('No downloaded podcasts found.')
log( _('No downloaded podcasts found.'))
# end of self.updateDownloadedComboBox()
def updateTreeView( self):
@ -271,9 +263,7 @@ class Gpodder(SimpleGladeApp):
myresult = True
dlg.destroy()
if libgpodder.isDebugging():
print "I Asked: %s" % message
print "User answered: %s" % str(myresult)
log( "I Asked: %s\nUser answered: %s", message, str( myresult))
return myresult
def set_icon(self):
@ -332,11 +322,9 @@ class Gpodder(SimpleGladeApp):
if result != None and result != "" and (result[:4] == "http" or result[:3] == "ftp"):
for old_channel in self.channels:
if old_channel.url == result:
if libgpodder.isDebugging():
print 'channel already exists in my list :)'
log( 'Channel already exists: %s', result)
return
if libgpodder.isDebugging():
print ("Will add channel :%s") % result
log( 'Adding new channel: %s', result)
self.statusLabel.set_text( _("Fetching channel index..."))
channel_new = podcastChannel( result)
self.channels.append( channel_new)
@ -428,17 +416,13 @@ class Gpodder(SimpleGladeApp):
self.showMessage( _("You have already downloaded this episode\nor you are currently downloading it."))
# if we're not downloading it, but it exists: add to localdb (if not already done so)
if os.path.exists( filename) == True:
if libgpodder.isDebugging():
print "already downloaded, trying to add to localDB if needed"
log( 'Episode has already been downloaded.')
if current_channel.addDownloadedItem( current_podcast):
self.ldb.clear_cache()
#-- Gpodder custom methods }
#-- Gpodder.close_gpodder {
def close_gpodder(self, widget, *args):
if libgpodder.isDebugging():
print "close_gpodder called with self.%s" % widget.get_name()
if self.channels_loaded:
gPodderChannelWriter().write( self.channels)
@ -451,15 +435,11 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemUpdate_activate {
def on_itemUpdate_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemUpdate_activate called with self.%s" % widget.get_name()
self.update_feed_cache()
#-- Gpodder.on_itemUpdate_activate }
#-- Gpodder.on_sync_to_ipod_activate {
def on_sync_to_ipod_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_sync_to_ipod_activate called with self.%s" % widget.get_name()
sync_win = Gpoddersync()
while gtk.events_pending():
gtk.main_iteration( False)
@ -470,8 +450,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_cleanup_ipod_activate {
def on_cleanup_ipod_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_cleanup_ipod_activate called with self.%s" % widget.get_name()
if not self.showConfirmation( _('Do you really want to truncate the Podcasts playlist on your iPod?')):
return
sync_win = Gpoddersync()
@ -484,8 +462,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemPreferences_activate {
def on_itemPreferences_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemPreferences_activate called with self.%s" % widget.get_name()
if self.uar == None:
self.uar = UserAppsReader()
self.uar.read()
@ -495,8 +471,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemAddChannel_activate {
def on_itemAddChannel_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemAddChannel_activate called with self.%s" % widget.get_name()
ch = Gpodderchannel()
ch.entryURL.set_text( "http://")
result = ch.requestURL()
@ -505,8 +479,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemEditChannel_activate {
def on_itemEditChannel_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemEditChannel_activate called with self.%s" % widget.get_name()
channel = None
try:
channel = self.channels[self.active_channel]
@ -516,8 +488,7 @@ class Gpodder(SimpleGladeApp):
result = Gpodderchannel().requestURL( channel)
if result != channel.url and result != None and result != "" and (result[:4] == "http" or result[:3] == "ftp"):
if libgpodder.isDebugging():
print 'Changing ID %d from "%s" to "%s"' % (active, channel.url, result)
log( 'Changing channel #%d from "%s" to "%s"', active, channel.url, result)
self.statusLabel.set_text( _("Fetching channel index..."))
channel_new = podcastChannel( result)
new_channels = self.channels[0:active]
@ -535,9 +506,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemRemoveChannel_activate {
def on_itemRemoveChannel_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemRemoveChannel_activate called with self.%s" % widget.get_name()
try:
if self.showConfirmation( _("Do you really want to remove this channel?\n\n %s") % self.channels[self.active_channel].title) == False:
return
@ -551,8 +519,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemExportChannels_activate {
def on_itemExportChannels_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemExportChannels_activate called with self.%s" % widget.get_name()
if len( self.channels) == 0:
self.showMessage( _("Your channel list is empty. Nothing to export."))
return
@ -564,8 +530,7 @@ class Gpodder(SimpleGladeApp):
foutname = dlg.get_filename()
if foutname[-5:] != ".opml" and foutname[-4:] != ".xml":
foutname = foutname + ".opml"
if libgpodder.isDebugging():
print 'Exporting channels list to: %s' % foutname
log( 'Exporting channel list to: %s', foutname)
w = opmlWriter( foutname)
for ch in self.channels:
w.addChannel( ch)
@ -577,8 +542,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemImportChannels_activate {
def on_itemImportChannels_activate(self, widget, *args):
if libgpodder.isDebugging:
print "on_itemImportChannels_activate called with self.%s" % widget.get_name()
opml_lister = Gpodderopmllister()
gl = gPodderLib()
@ -589,8 +552,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_itemAbout_activate {
def on_itemAbout_activate(self, widget, *args):
if libgpodder.isDebugging():
print "on_itemAbout_activate called with self.%s" % widget.get_name()
dlg = gtk.AboutDialog()
dlg.set_name( app_name)
dlg.set_version( app_version)
@ -609,29 +570,22 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_wNotebook_switch_page {
def on_wNotebook_switch_page(self, widget, *args):
if libgpodder.isDebugging():
print "on_wNotebook_switch_page called with self.%s" % widget.get_name()
pass
#-- Gpodder.on_wNotebook_switch_page }
#-- Gpodder.on_comboAvailable_changed {
def on_comboAvailable_changed(self, widget, *args):
if libgpodder.isDebugging():
print "on_comboAvailable_changed called with self.%s" % widget.get_name()
self.active_channel = self.comboAvailable.get_active()
self.updateTreeView()
#-- Gpodder.on_comboAvailable_changed }
#-- Gpodder.on_btnEditChannel_clicked {
def on_btnEditChannel_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnEditChannel_clicked called with self.%s" % widget.get_name()
self.on_itemEditChannel_activate( widget, args)
#-- Gpodder.on_btnEditChannel_clicked }
#-- Gpodder.on_treeAvailable_row_activated {
def on_treeAvailable_row_activated(self, widget, *args):
if libgpodder.isDebugging():
print "on_treeAvailable_row_activated called with self.%s" % widget.get_name()
try:
selection = self.treeAvailable.get_selection()
selection_tuple = selection.get_selected_rows()
@ -651,15 +605,11 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_btnDownload_clicked {
def on_btnDownload_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnDownload_clicked called with self.%s" % widget.get_name()
self.on_treeAvailable_row_activated( widget, args)
#-- Gpodder.on_btnDownload_clicked }
#-- Gpodder.on_btnSelectAllAvailable_clicked {
def on_btnSelectAllAvailable_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnSelectAllAvailable_clicked called with self.%s" % widget.get_name()
self.treeAvailable.get_selection().select_all()
self.on_treeAvailable_row_activated( self.btnDownload, args)
self.treeAvailable.get_selection().unselect_all()
@ -667,13 +617,10 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_treeDownloads_row_activated {
def on_treeDownloads_row_activated(self, widget, *args):
if libgpodder.isDebugging():
print "on_treeDownloads_row_activated called with self.%s" % widget.get_name()
selection = self.treeDownloads.get_selection()
selection_tuple = selection.get_selected_rows()
if selection.count_selected_rows() == 0:
if libgpodder.isDebugging():
print "will not cancel any download. reason: nothing selected."
log( 'Nothing selected to cancel.')
return
if selection.count_selected_rows() == 1:
@ -688,21 +635,16 @@ class Gpodder(SimpleGladeApp):
url = self.download_status_manager.get_url_by_iter( selection_iter)
self.download_status_manager.cancel_by_url( url)
except:
if libgpodder.isDebugging():
print "error while cancelling downloads"
log( 'Error while cancelling downloads.')
#-- Gpodder.on_treeDownloads_row_activated }
#-- Gpodder.on_btnCancelDownloadStatus_clicked {
def on_btnCancelDownloadStatus_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnCancelDownloadStatus_clicked called with self.%s" % widget.get_name()
self.on_treeDownloads_row_activated( widget, None)
#-- Gpodder.on_btnCancelDownloadStatus_clicked }
#-- Gpodder.on_btnCancelAll_clicked {
def on_btnCancelAll_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnCancelAll_clicked called with self.%s" % widget.get_name()
self.treeDownloads.get_selection().select_all()
self.on_treeDownloads_row_activated( self.btnCancelDownloadStatus, None)
self.treeDownloads.get_selection().unselect_all()
@ -710,8 +652,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_comboDownloaded_changed {
def on_comboDownloaded_changed(self, widget, *args):
if libgpodder.isDebugging():
print "on_comboDownloaded_changed called with self.%s" % widget.get_name()
self.active_downloaded_channels = self.comboDownloaded.get_active()
try:
filename = self.get_current_channel_downloaded()
@ -724,8 +664,6 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_treeDownloaded_row_activated {
def on_treeDownloaded_row_activated(self, widget, *args):
if libgpodder.isDebugging():
print "on_treeDownloaded_row_activated called with self.%s" % widget.get_name()
try:
channel_filename = self.get_current_channel_downloaded()
@ -753,24 +691,18 @@ class Gpodder(SimpleGladeApp):
#-- Gpodder.on_btnDownloadedExecute_clicked {
def on_btnDownloadedExecute_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnDownloadedExecute_clicked called with self.%s" % widget.get_name()
self.on_treeDownloaded_row_activated( widget, args)
#-- Gpodder.on_btnDownloadedExecute_clicked }
#-- Gpodder.on_btnDownloadedDelete_clicked {
def on_btnDownloadedDelete_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnDownloadedDelete_clicked called with self.%s" % widget.get_name()
channel_filename = self.get_current_channel_downloaded()
selection = self.treeDownloaded.get_selection()
selection_tuple = selection.get_selected_rows()
model = self.treeDownloaded.get_model()
if selection.count_selected_rows() == 0:
if libgpodder.isDebugging():
print "will not remove any episode reason: nothing selected."
log( 'Nothing selected - will not remove any downloaded episode.')
return
if selection.count_selected_rows() == 1:
@ -796,14 +728,11 @@ class Gpodder(SimpleGladeApp):
self.updateComboBox()
self.updateDownloadedComboBox()
except:
if libgpodder.isDebugging():
print "error while deleting (some) downloads"
log( 'Error while deleting (some) downloads.')
#-- Gpodder.on_btnDownloadedDelete_clicked }
#-- Gpodder.on_btnDeleteAll_clicked {
def on_btnDeleteAll_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnDeleteAll_clicked called with self.%s" % widget.get_name()
self.treeDownloaded.get_selection().select_all()
self.on_btnDownloadedDelete_clicked( widget, args)
self.treeDownloaded.get_selection().unselect_all()
@ -827,8 +756,7 @@ class Gpodderchannel(SimpleGladeApp):
#-- Gpodderchannel.new {
def new(self):
if libgpodder.isDebugging():
print "A new %s has been created" % self.__class__.__name__
pass
#-- Gpodderchannel.new }
#-- Gpodderchannel custom methods {
@ -872,22 +800,16 @@ class Gpodderchannel(SimpleGladeApp):
#-- Gpodderchannel.on_gPodderChannel_destroy {
def on_gPodderChannel_destroy(self, widget, *args):
if libgpodder.isDebugging():
print "on_gPodderChannel_destroy called with self.%s" % widget.get_name()
self.result = False
#-- Gpodderchannel.on_gPodderChannel_destroy }
#-- Gpodderchannel.on_cbMusicChannel_toggled {
def on_cbMusicChannel_toggled(self, widget, *args):
if libgpodder.isDebugging():
print "on_cbMusicChannel_toggled called with self.%s" % widget.get_name()
self.musicPlaylist.set_sensitive( self.cbMusicChannel.get_active())
#-- Gpodderchannel.on_cbMusicChannel_toggled }
#-- Gpodderchannel.on_btnOK_clicked {
def on_btnOK_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnOK_clicked called with self.%s" % widget.get_name()
self.url = self.entryURL.get_text()
self.gPodderChannel.destroy()
self.result = True
@ -898,8 +820,6 @@ class Gpodderchannel(SimpleGladeApp):
#-- Gpodderchannel.on_btnCancel_clicked {
def on_btnCancel_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnCancel_clicked called with self.%s" % widget.get_name()
self.gPodderChannel.destroy()
self.result = False
@ -917,8 +837,6 @@ class Gpodderproperties(SimpleGladeApp):
#-- Gpodderproperties.new {
def new(self):
if libgpodder.isDebugging():
print "A new %s has been created" % self.__class__.__name__
gl = gPodderLib()
self.httpProxy.set_text( gl.http_proxy)
self.ftpProxy.set_text( gl.ftp_proxy)
@ -972,17 +890,12 @@ class Gpodderproperties(SimpleGladeApp):
#-- Gpodderproperties.on_gPodderProperties_destroy {
def on_gPodderProperties_destroy(self, widget, *args):
if libgpodder.isDebugging():
print "on_gPodderProperties_destroy called with self.%s" % widget.get_name()
if self.on_close != None:
self.on_close()
#-- Gpodderproperties.on_gPodderProperties_destroy }
#-- Gpodderproperties.on_comboPlayerApp_changed {
def on_comboPlayerApp_changed(self, widget, *args):
if libgpodder.isDebugging():
print "on_comboPlayerApp_changed called with self.%s" % widget.get_name()
# find out which one
iter = self.comboPlayerApp.get_active_iter()
model = self.comboPlayerApp.get_model()
@ -1000,8 +913,6 @@ class Gpodderproperties(SimpleGladeApp):
#-- Gpodderproperties.on_cbEnvironmentVariables_toggled {
def on_cbEnvironmentVariables_toggled(self, widget, *args):
if libgpodder.isDebugging():
print "on_cbEnvironmentVariables_toggled called with self.%s" % widget.get_name()
sens = not self.cbEnvironmentVariables.get_active()
self.httpProxy.set_sensitive( sens)
self.ftpProxy.set_sensitive( sens)
@ -1009,8 +920,6 @@ class Gpodderproperties(SimpleGladeApp):
#-- Gpodderproperties.on_btnOK_clicked {
def on_btnOK_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnOK_clicked called with self.%s" % widget.get_name()
gl = gPodderLib()
gl.http_proxy = self.httpProxy.get_text()
gl.ftp_proxy = self.ftpProxy.get_text()
@ -1030,8 +939,6 @@ class Gpodderproperties(SimpleGladeApp):
#-- Gpodderproperties.on_btnCancel_clicked {
def on_btnCancel_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnCancel_clicked called with self.%s" % widget.get_name()
self.gPodderProperties.destroy()
#-- Gpodderproperties.on_btnCancel_clicked }
@ -1045,8 +952,7 @@ class Gpodderepisode(SimpleGladeApp):
#-- Gpodderepisode.new {
def new(self):
if libgpodder.isDebugging():
print "A new %s has been created" % self.__class__.__name__
pass
#-- Gpodderepisode.new }
#-- Gpodderepisode custom methods {
@ -1072,16 +978,11 @@ class Gpodderepisode(SimpleGladeApp):
#-- Gpodderepisode.on_btnCloseWindow_clicked {
def on_btnCloseWindow_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnCloseWindow_clicked called with self.%s" % widget.get_name()
self.gPodderEpisode.destroy()
#-- Gpodderepisode.on_btnCloseWindow_clicked }
#-- Gpodderepisode.on_btnDownload_clicked {
def on_btnDownload_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnDownload_clicked called with self.%s" % widget.get_name()
# if we have a callback, .. well.. call it back! ;)
if self.download_callback != None:
self.download_callback()
@ -1101,8 +1002,6 @@ class Gpoddersync(SimpleGladeApp):
#-- Gpoddersync.new {
def new(self):
global artwork_dir
if libgpodder.isDebugging():
print "A new %s has been created" % self.__class__.__name__
self.imageSyncServer.set_from_file( artwork_dir + 'computer.png')
self.imageSyncAnimation.set_from_file( artwork_dir + 'sync-anim.gif')
self.imageSyncClient.set_from_file( artwork_dir + 'ipod-mini.png')
@ -1130,8 +1029,7 @@ class Gpoddersync(SimpleGladeApp):
#-- Gpoddersync.on_gPodderSync_destroy {
def on_gPodderSync_destroy(self, widget, *args):
if libgpodder.isDebugging():
print "on_gPodderSync_destroy called with self.%s" % widget.get_name()
pass
#-- Gpoddersync.on_gPodderSync_destroy }
@ -1145,9 +1043,6 @@ class Gpodderopmllister(SimpleGladeApp):
#-- Gpodderopmllister.new {
def new(self):
if libgpodder.isDebugging():
print "A new %s has been created" % self.__class__.__name__
# initiate channels list
self.channels = []
self.callback_for_channel = None
@ -1178,8 +1073,7 @@ class Gpodderopmllister(SimpleGladeApp):
else:
self.channels.remove( url)
if libgpodder.isDebugging():
print url
log( 'Edited: %s', url)
def get_channels_from_url( self, url, callback):
reader = opmlReader()
@ -1190,14 +1084,11 @@ class Gpodderopmllister(SimpleGladeApp):
#-- Gpodderopmllister.on_gPodderOpmlLister_destroy {
def on_gPodderOpmlLister_destroy(self, widget, *args):
if libgpodder.isDebugging():
print "on_gPodderOpmlLister_destroy called with self.%s" % widget.get_name()
pass
#-- Gpodderopmllister.on_gPodderOpmlLister_destroy }
#-- Gpodderopmllister.on_btnOK_clicked {
def on_btnOK_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnOK_clicked called with self.%s" % widget.get_name()
self.gPodderOpmlLister.destroy()
# add channels that have been selected
for url in self.channels:
@ -1207,8 +1098,6 @@ class Gpodderopmllister(SimpleGladeApp):
#-- Gpodderopmllister.on_btnCancel_clicked {
def on_btnCancel_clicked(self, widget, *args):
if libgpodder.isDebugging():
print "on_btnCancel_clicked called with self.%s" % widget.get_name()
self.gPodderOpmlLister.destroy()
#-- Gpodderopmllister.on_btnCancel_clicked }

View file

@ -52,6 +52,7 @@ from stat import ST_MODE
from librssreader import rssReader
from libpodcasts import podcastChannel
from libplayers import dotdesktop_command
from liblogger import log
from gtk.gdk import PixbufLoader
@ -59,10 +60,6 @@ from ConfigParser import ConfigParser
from xml.sax import saxutils
# global debugging variable, set to False on release
# TODO: while developing a new version, set this to "True"
debugging = True
# global recursive lock for thread exclusion
globalLock = threading.RLock()
@ -72,9 +69,6 @@ g_podder_lib = None
# default url to use for opml directory on the web
default_opml_directory = 'http://share.opml.org/opml/topPodcasts.opml'
def isDebugging():
return debugging
def getLock():
globalLock.acquire()
@ -125,8 +119,7 @@ class gPodderLibClass( object):
makedirs( path)
return True
except:
if isDebugging():
print 'createIfNecessary: could not create: %s' % ( path )
log( 'Could not create %s', path)
return False
return True
@ -163,8 +156,7 @@ class gPodderLibClass( object):
def get_from_parser( self, parser, option, default = ''):
try:
result = parser.get( self.gpodderconf_section, option)
if isDebugging():
print "get_from_parser( %s) = %s" % ( option, result )
log( 'Option "%s" is set to "%s"', option, result)
return result
except:
return default
@ -182,16 +174,14 @@ class gPodderLibClass( object):
try:
parser.set( self.gpodderconf_section, option, str(value))
except:
if isDebugging():
print 'write_to_parser: could not write config (option=%s, value=%s' % (option, value)
log( 'write_to_parser: could not write config (option=%s, value=%s)', option, value)
def loadConfig( self):
was_oldstyle = False
try:
fn = self.getConfigFilename()
if open(fn,'r').read(1) != '[':
if isDebugging():
print 'seems like old-style config. trying to read it anyways..'
log( 'seems like old-style config. trying to read it anyways..')
fp = open( fn, 'r')
http = fp.readline()
ftp = fp.readline()
@ -210,8 +200,7 @@ class gPodderLibClass( object):
self.ipod_mount = self.get_from_parser( parser, 'ipod_mount', '/media/ipod/')
self.update_on_startup = self.get_boolean_from_parser(parser, 'update_on_startup', default=False)
else:
if isDebugging():
print "config file %s has no section %s" % (fn, gpodderconf_section)
log( 'config file %s has no section %s', fn, gpodderconf_section)
if not self.proxy_use_environment:
self.http_proxy = strip( http)
self.ftp_proxy = strip( ftp)
@ -232,8 +221,7 @@ class gPodderLibClass( object):
self.saveConfig()
def openFilename( self, filename):
if isDebugging():
print 'open %s with %s' % ( filename, self.open_app )
log( 'Opening %s (with %s)', filename, self.open_app)
# use libplayers to create a commandline out of open_app plus filename, then exec in background ('&')
system( '%s &' % dotdesktop_command( self.open_app, filename))
@ -243,16 +231,12 @@ class gPodderLibClass( object):
return exists( symlink_path)
def createDesktopSymlink( self):
if isDebugging():
print "createDesktopSymlink requested"
if not self.getDesktopSymlink():
downloads_path = expanduser( "~/Desktop/")
self.createIfNecessary( downloads_path)
symlink( self.downloaddir, "%s%s" % (downloads_path, self.desktop_link))
def removeDesktopSymlink( self):
if isDebugging():
print "removeDesktopSymlink requested"
if self.getDesktopSymlink():
unlink( expanduser( "~/Desktop/%s" % self.desktop_link))
@ -262,20 +246,17 @@ class gPodderLibClass( object):
pixbuf = PixbufLoader()
if cover_file == None:
if isDebugging():
print "directly downloading %s" % url
log( 'Downloading %s', url)
pixbuf.write( urllib.urlopen(url).read())
if cover_file != None and not exists( cover_file):
if isDebugging():
print "downloading cover to %s" % cover_file
log( 'Downloading cover to %s', cover_file)
cachefile = open( cover_file, "w")
cachefile.write( urllib.urlopen(url).read())
cachefile.close()
if cover_file != None:
if isDebugging():
print "reading cover from %s" % cover_file
log( 'Reading cover from %s', cover_file)
pixbuf.write( open( cover_file, "r").read())
try:
@ -297,8 +278,7 @@ class gPodderLibClass( object):
thread.start()
def deleteFilename( self, filename):
if isDebugging():
print "deleteFilename: " + filename
log( 'deleteFilename: %s', filename)
try:
unlink( filename)
except:
@ -358,18 +338,17 @@ class gPodderChannelReader( DefaultHandler):
callback_proc( position, channel_count)
cachefile = channel.downloadRss(force_update)
log( 'cachefile for %s is %s', channel.url, cachefile)
# check if download was a success
if cachefile != None:
reader.parseXML(channel.url, cachefile)
if channel.filename != '__unknown__':
proposed_filename = channel.filename
if isDebugging():
print 'First proposed fn: %s' % ( proposed_filename )
log( 'First proposed fn: %s', proposed_filename)
i = 2
while self.channel_filename_exists( channel.url, proposed_filename):
proposed_filename = '%s%d' % ( channel.filename, i )
if isDebugging():
print 'New proposed fn: %s' % ( proposed_filename )
log( 'New proposed fn: %s', proposed_filename)
i = i+1
reader.channel.filename = proposed_filename
input_channels.append( reader.channel)

View file

@ -42,7 +42,8 @@ import sys
import time
import email.Utils
import libgpodder
from liblogger import log
import liblocaldb
import libpodcasts
@ -69,8 +70,7 @@ class gPodder_iPodSync(object):
def __init__( self, ipod_mount = '/media/ipod/', callback_progress = None, callback_status = None, callback_done = None):
if not ipod_supported():
if libgpodder.isDebugging():
print '(ipodsync) iPod functions not supported. (libgpod + eyed3 needed)'
log( '(ipodsync) iPod functions not supported. (libgpod + eyed3 needed)')
self.ipod_mount = ipod_mount
self.callback_progress = callback_progress
self.callback_status = callback_status
@ -107,8 +107,7 @@ class gPodder_iPodSync(object):
def remove_from_ipod( self, track, playlists):
if not ipod_supported():
return False
if libgpodder.isDebugging():
print '(ipodsync) REMOVING FROM IPOD!! track: %s' % track.title
log( '(ipodsync) Removing track from iPod: %s', track.title)
if self.callback_status != None:
gobject.idle_add( self.callback_status, track.title, track.artist)
fname = gpod.itdb_filename_on_ipod( track)
@ -130,13 +129,10 @@ class gPodder_iPodSync(object):
return False
for playlist in gpod.sw_get_playlists( self.itdb):
if playlist.name == playlistname:
if libgpodder.isDebugging():
print "(ipodsync) found old playlist: %s" % (playlist.name)
log( '(ipodsync) Found old playlist: %s', playlist.name)
return playlist
# if we arrive here: gpodder playlist not found!
if libgpodder.isDebugging():
print "creating new playlist: %s" % (playlistname)
log( '(ipodsync) New playlist: %s', playlistname)
new_playlist = gpod.itdb_playlist_new( str(playlistname), False)
gpod.itdb_playlist_add( self.itdb, new_playlist, -1)
return new_playlist
@ -152,8 +148,7 @@ class gPodder_iPodSync(object):
return False
for track in gpod.sw_get_playlist_tracks( self.get_playlist_for_channel( channel)):
if episode.title == track.title and channel.title == track.album:
if libgpodder.isDebugging():
print '(ipodsync) Already on iPod: %s (from %s)' % (episode.title, track.title)
log( '(ipodsync) Already on iPod: %s (from %s)', episode.title, track.title)
return True
return False
@ -162,8 +157,7 @@ class gPodder_iPodSync(object):
if not ipod_supported():
return False
for track in gpod.sw_get_playlist_tracks( self.pl_podcasts):
if libgpodder.isDebugging():
print '(ipodsync) trying to remove track %s' % track.title
log( '(ipodsync) Trying to remove: %s', track.title)
self.remove_from_ipod( track, [ self.pl_podcasts ])
def copy_channel_to_ipod( self, channel):
@ -194,8 +188,7 @@ class gPodder_iPodSync(object):
track.flag3 = 0x01
track.flag4 = 0x01
except:
if libgpodder.isDebugging():
print '(ipodsync) Seems like your python-gpod is out-of-date.'
log( '(ipodsync) Seems like your python-gpod is out-of-date.')
pass
def add_episode_from_channel( self, channel, episode):
@ -211,8 +204,7 @@ class gPodder_iPodSync(object):
# episode is already here :)
return True
if libgpodder.isDebugging():
print '(ipodsync) Adding item: %s from %s' % (episode.title, channel.title)
log( '(ipodsync) Adding item: %s from %s', episode.title, channel.title)
local_filename = str(channel.getPodcastFilename( episode.url))
try:
eyed3_info = eyeD3.Mp3AudioFile( local_filename)
@ -264,15 +256,12 @@ class gPodder_iPodSync(object):
gpod.itdb_playlist_add_track( self.pl_master, track, -1)
if gpod.itdb_cp_track_to_ipod( track, local_filename, None) != 1:
if libgpodder.isDebugging():
print '(ipodsync) could not add track: %s' % episode.title
log( '(ipodsync) Could not add %s', episode.title)
else:
if libgpodder.isDebugging():
print '(ipodsync) success for %s :)' % episode.title
log( '(ipodsync) Added %s', episode.title)
try:
os.system('sync')
except:
# silently ignore :)
pass

View file

@ -28,10 +28,10 @@
import gtk
import gobject
import libgpodder
from liblocdbreader import readLocalDB
from libgpodder import gPodderLib
from liblogger import log
from os import listdir
from os import sep
@ -39,16 +39,13 @@ from os.path import isfile
class localDB( object):
def __init__( self):
if libgpodder.isDebugging():
print "created new localDB object"
self.channel_list = None
self.local_db_cache = {}
def getDownloadedChannelsList( self):
# do not re-read downloaded channels list
if self.channel_list != None:
if libgpodder.isDebugging():
print "(localDB) using cached downloaded channels list"
log( '(localDB) using cached downloaded channels list')
return self.channel_list
self.channel_list = []
@ -74,8 +71,7 @@ class localDB( object):
new_model = gtk.ListStore( gobject.TYPE_STRING, gobject.TYPE_STRING)
for channel in self.getDownloadedChannelsList():
if libgpodder.isDebugging():
print "(getmodel) " + channel.title
log( 'Getting ListStore for %s', channel.title)
new_iter = new_model.append()
new_model.set( new_iter, 0, channel.url)
new_model.set( new_iter, 1, channel.title)

View file

@ -35,6 +35,8 @@ from string import strip
import libpodcasts
import libgpodder
from liblogger import log
class rssLocDBErrorHandler( ErrorHandler):
def __init__( self):
None
@ -83,8 +85,7 @@ class readLocalDB( DefaultHandler):
if attrs.get('music', 'false').lower() == 'true':
self.channel.is_music_channel = True
if attrs.get('nosync', 'false').lower() == 'true':
if libgpodder.isDebugging():
print 'local channel does not want to be synced: %s' % self.channel.title
log( 'iPod sync deactivated for %s', self.channel.title)
self.channel.sync_to_devices = False
def endElement( self, name):
@ -119,9 +120,6 @@ class readLocalDB( DefaultHandler):
self.current_item.pubDate = self.current_element_data
if name == "item":
self.channel.addItem( self.current_item)
# this produces lots of output and works ATM, so output disabled
if libgpodder.isDebugging() and False:
print "importing local db channel: " + self.current_item.url
self.current_item = None
def characters( self, ch):

37
src/gpodder/liblogger.py Normal file
View file

@ -0,0 +1,37 @@
#
# gPodder (a media aggregator / podcast client)
# Copyright (C) 2005-2006 Thomas Perl <thp at perli.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
# liblogger.py -- gPodder logging facility
# Thomas Perl <thp perli net> 20061117
#
#
write_to_stdout = True
def log( message, *args):
if write_to_stdout:
print message % args

View file

@ -41,7 +41,7 @@ from gtk import ListStore
from gtk.gdk import pixbuf_new_from_file_at_size
from gtk.gdk import Pixbuf
import libgpodder
from liblogger import log
# where are the .desktop files located?
userappsdirs = [ '/usr/share/applications/', '/usr/local/share/applications/' ]
@ -95,8 +95,7 @@ class UserAppsReader(object):
app_mime = parser.get( sect, 'MimeType')
app_icon = parser.get( sect, 'Icon')
if app_mime.find( 'audio/') != -1:
if libgpodder.isDebugging():
print "found app in " + dir + filename + " ("+app_name+")"
log( 'Player found: %s (%s in %s)', app_name, filename, dir)
self.apps.append( UserApplication( app_name, app_cmd, app_mime, app_icon))
except:
return

View file

@ -30,6 +30,7 @@ import gtk
import gobject
import htmlentitydefs
from liblogger import log
import libgpodder
from os.path import exists
@ -120,12 +121,10 @@ class podcastChannel(ListType):
try:
writeLocalDB( self.index_file, channel)
except:
if libgpodder.isDebugging():
print 'Cannot save localDB channel in set_localdb_channel( %s)' % channel.title
log( 'Cannot save channel in set_localdb_channel( %s)', channel.title)
def set_metadata_from_localdb( self):
if libgpodder.isDebugging():
print 'Reading metadata from localdb: %s' % self.index_file
log( 'Reading metadata from database: %s', self.index_file)
libgpodder.getLock()
ch = self.get_localdb_channel()
if ch != None:
@ -133,8 +132,7 @@ class podcastChannel(ListType):
libgpodder.releaseLock()
def save_metadata_to_localdb( self):
if libgpodder.isDebugging():
print 'Saving metadata to localdb: %s' % self.index_file
log( 'Saving metadata to database: %s', self.index_file)
libgpodder.getLock()
ch = self.get_localdb_channel()
if ch != None:
@ -152,8 +150,7 @@ class podcastChannel(ListType):
# no multithreaded access
libgpodder.getLock()
localdb = self.index_file
if libgpodder.isDebugging():
print "localdb: " + localdb
log( 'Local database: %s', localdb)
self.downloaded = self.get_localdb_channel()
@ -168,8 +165,7 @@ class podcastChannel(ListType):
if not already_in_list:
self.downloaded.append( item)
else:
if libgpodder.isDebugging():
print "no need to re-add already added podcast item to localDB"
log( 'Podcast episode already downloaded.')
writeLocalDB( localdb, self.downloaded)
libgpodder.releaseLock()
@ -214,7 +210,6 @@ class podcastChannel(ListType):
return -1
def downloadRss( self, force_update = True):
if (self.filename == "__unknown__" or exists( self.cache_file) == False) or force_update:
# remove old cache file
libgpodder.gPodderLib().deleteFilename( self.cache_file)
@ -258,9 +253,6 @@ class podcastChannel(ListType):
self.reset_download_dir()
return False
return True
# the following disabled at the moment..
#if libgpodder.isDebugging():
# print "set_download_dir: ", self, self.__download_dir
download_dir = property (fget=get_download_dir,
fset=set_download_dir)
@ -294,10 +286,10 @@ class podcastChannel(ListType):
legacy_location = self.save_dir + filename
new_location = self.save_dir + md5.new(url).hexdigest() + extension
# this supports legacy podcast locations, should be removed at some point (or move files from old location to new location)
# this supports legacy podcast locations, should be removed at
# some point (or move files from old location to new location)
if exists( legacy_location):
if libgpodder.isDebugging():
print "(gpodder < 0.7 compat) using old filename scheme for already downloaded podcast."
log( '(gpodder < 0.7 compat) Using old filename scheme for already downloaded podcast.')
return legacy_location
else:
return new_location
@ -306,14 +298,12 @@ class podcastChannel(ListType):
return exists( self.getPodcastFilename( url))
def deleteDownloadedItemByUrlAndTitle(self, url, title):
if libgpodder.isDebugging():
print "deleteDownloadedItemByUrlAndTitle: " + title + " (" + url + ")"
log( 'Delete %s (%s)', title, url)
# no multithreaded access
libgpodder.getLock()
nr_items = 0
localdb = self.index_file
if libgpodder.isDebugging():
print "localdb: " + localdb
log( 'Local database: %s', localdb)
try:
locdb_reader = readLocalDB()
locdb_reader.parseXML( localdb)
@ -324,8 +314,7 @@ class podcastChannel(ListType):
self.downloaded.remove(item)
except:
print _("No LocalDB found or error in existing LocalDB.")
if libgpodder.isDebugging():
print " found", nr_items, "matching item(s)"
log( 'Found %d matching item(s).', nr_items)
if nr_items > 0:
writeLocalDB( localdb, self.downloaded)
libgpodder.releaseLock()

View file

@ -34,7 +34,7 @@ from threading import Thread
from threading import Lock
from shutil import move
import libgpodder
from liblogger import log
import signal
import popen2
@ -98,8 +98,7 @@ class downloadThread( object):
def thread_function( self):
command = "wget \"" + self.url + "\" -O \"" + self.tempname + "\""
if libgpodder.isDebugging():
print command
log( 'Command: %s', command)
process = popen2.Popen3( command, True)
self.pid = process.pid
@ -107,9 +106,8 @@ class downloadThread( object):
while process.poll() == -1 and self.is_cancelled == False:
msg = stderr.readline( 80)
if libgpodder.isDebugging():
print msg
msg = msg.strip()
log( 'wget> %s', msg)
if msg.find("%") != -1:
try:
@ -136,8 +134,7 @@ class downloadThread( object):
# self.statusmgr
if self.result == 0 and self.channelitem != None and self.item != None:
if libgpodder.isDebugging():
print "downloadThread finished: adding downloaded item to downloaded list"
log( 'Download thread finished: Adding downloaded item to local database')
self.channelitem.addDownloadedItem( self.item)
# if we have received a localDB, clear its cache