diff options
author | jerous <jerous@gmail.com> | 2008-09-17 02:44:30 +0200 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-09-17 02:47:05 +0200 |
commit | 5d8d3a37313f0b5a08ecc25730204bed5e605384 (patch) | |
tree | 627d843c54b4598dd231f7118bf60def1d2eb76b /plugins | |
parent | 3750d2f7570920364b55d5a71c9be5f8420e58fe (diff) |
logging in plugins through clPlugin
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/AlbumCover.py | 23 | ||||
-rw-r--r-- | plugins/Lyrics.py | 20 | ||||
-rw-r--r-- | plugins/PlayControl.py | 21 | ||||
-rw-r--r-- | plugins/Scrobbler.py | 27 | ||||
-rw-r--r-- | plugins/Tabs.py | 2 |
5 files changed, 48 insertions, 45 deletions
diff --git a/plugins/AlbumCover.py b/plugins/AlbumCover.py index 117c243..4fa397a 100644 --- a/plugins/AlbumCover.py +++ b/plugins/AlbumCover.py @@ -1,7 +1,6 @@ from clPlugin import * from traceback import print_exc from thread import start_new_thread -import log # FETCH MODES AC_NO_FETCH='0' @@ -20,6 +19,7 @@ class wgAlbumCover(QtGui.QWidget): " container for the image" img=None imgLoaded=False + p=None # plugin def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.img=QtGui.QImage() @@ -41,7 +41,7 @@ class wgAlbumCover(QtGui.QWidget): p.drawImage(rect,self.img) def refresh(self): - log.extended("AlbumCover: refreshing cover") + self.p.extended("refreshing cover") song=monty.getCurrentSong() try: song._data['file'] @@ -90,9 +90,9 @@ class wgAlbumCover(QtGui.QWidget): return False # get the url from amazon WS coverURL=AmazonAlbumImage(song.getArtist(), song.getAlbum()).fetch() - log.extended("AlbumCover: fetch from Amazon") + self.p.extended("fetch from Amazon") if not coverURL: - log.normal("AlbumCover: not found on Amazon") + self.p.normal("not found on Amazon") return False # read the url, i.e. retrieve image data img=urllib.urlopen(coverURL) @@ -110,11 +110,11 @@ class wgAlbumCover(QtGui.QWidget): self.img.load(file) return True except: - log.normal("AlbumCover: failed to download cover from Amazon") + self.p.normal("failed to download cover from Amazon") print_exc() return False if src==AC_FETCH_LOCAL_DIR: - log.extended("AlbumCover: looking in local directory") + self.p.extended("looking in local directory") # look in local directory # create all possible album cover filenames ... coverFiles=[] @@ -125,7 +125,7 @@ class wgAlbumCover(QtGui.QWidget): elif src==AC_FETCH_ALBUM_DIR: - log.extended("AlbumCover: looking in album directory") + self.p.extended("looking in album directory") # look in album directory path=settings.get('albumcover.dir') fInfo=QtCore.QFileInfo(path) @@ -142,10 +142,10 @@ class wgAlbumCover(QtGui.QWidget): if QtCore.QFileInfo(file).exists(): try: self.img.load(file) - log.extended("AlbumCover: cover set!") + self.p.extended("cover set!") return True except: - log.normal("AlbumCover: failed to load %s"%(file)) + self.p.normal("failed to load %s"%(file)) return False @@ -160,6 +160,7 @@ class pluginAlbumCover(Plugin): def _load(self): self.o=wgAlbumCover(None) + self.o.p=self self.o.refresh() def _unload(self): self.o=None @@ -234,7 +235,7 @@ class AmazonAlbumImage(object): try: prod_data = urllib.urlopen(url).read() except: - log.important("AlbumCover: timeout opening %s"%(url)) + self.important("timeout opening %s"%(url)) return None m = img_re.search(prod_data) if not m: @@ -261,7 +262,7 @@ class AmazonAlbumImage(object): return fd.read() except: # this is very probable a timeout exception - log.important("AlbumCover: timeout openening %s"%(self.awsurl)) + self.important("timeout openening %s"%(self.awsurl)) return None diff --git a/plugins/Lyrics.py b/plugins/Lyrics.py index 492e058..8d2ff8b 100644 --- a/plugins/Lyrics.py +++ b/plugins/Lyrics.py @@ -9,7 +9,6 @@ from misc import * from clSettings import settings,mpdSettings from clMonty import monty from clPlugin import * -import log class ResetEvent(QtCore.QEvent): song=None @@ -35,6 +34,7 @@ class wgLyrics(QtGui.QWidget): btnRefetch=None btnSave=None editMode=False + p=None # plugin def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.curLyrics="" @@ -84,7 +84,7 @@ class wgLyrics(QtGui.QWidget): os.remove(lyFName) except: pass - self.onSongChange(None) + self.refresh() def refresh(self): # if we're editing while song changes, too bad: we don't save, for the moment! @@ -130,25 +130,24 @@ class wgLyrics(QtGui.QWidget): QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) lyFName=self.getLyricsFilePath(song) - log.debug("lyrics: checking %s"%(lyFName)) + self.p.debug("checking %s"%(lyFName)) self.curLyrics="" # does the file exist? if yes, read that one! try: - # we have it: load, and return! file=open(lyFName, 'r') self.curLyrics=file.read() - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent(self.curLyrics)) file.close() + QtCore.QCoreApplication.postEvent(self, AddHtmlEvent(self.curLyrics)) self._fetchCnt=0 - log.extended("Fetch lyrics from file") + self.p.extended("Fetch lyrics from file") return - except: - log.debug("lyrics: fail") + except Exception, e: + self.p.debug("fail - %s"%(str(e))) pass # fetch from inet QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('<i>Searching lyrics ...</i>')) - log.extended("Fetch lyrics from internet") + self.p.extended("Fetch lyrics from internet") lines=settings.get('lyrics.sites', LY_DEFAULT_SITES).split('\n') sites={} @@ -174,7 +173,7 @@ class wgLyrics(QtGui.QWidget): pass else: txt="No lyrics found :'(<br /><br /><a href='%s'>Search yourself!</a>"%(SE) - log.extended("Lyrics not found!") + self.p.extended("Lyrics not found!") self.curLyrics="" QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) @@ -204,6 +203,7 @@ class pluginLyrics(Plugin): self.addMontyListener('onDisconnect', self.onDisconnect) def _load(self): self.o=wgLyrics(None) + self.o.p=self self.o.refresh() def _unload(self): self.o=None diff --git a/plugins/PlayControl.py b/plugins/PlayControl.py index 8d2160a..53352a9 100644 --- a/plugins/PlayControl.py +++ b/plugins/PlayControl.py @@ -5,7 +5,6 @@ from clMonty import monty from clPlugin import * from thread import start_new_thread from random import randint -import log # Some predefined constants. # Note that REPEAT precedes RANDOM. E.g. if repeat @@ -41,14 +40,13 @@ class wgPlayControl(QtGui.QWidget): cmbRepeat=None cmbShuffle=None - plugin=None + p=None " contains the songs of the album the current song is playing. None, if the album is not set" curAlbumSongs=None - def __init__(self, plugin, parent=None): + def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) - self.plugin=plugin class wgSvgSwitcher(QtSvg.QSvgWidget): """Widget showing an svg-image, which, when clicked, will (un)hide an element.""" @@ -125,7 +123,7 @@ class wgPlayControl(QtGui.QWidget): self.connect(self.cmbShuffle, QtCore.SIGNAL('currentIndexChanged(int)'),self.onCmbShuffleChanged) def onBtnJmpCurrentClick(self): - self.plugin.getWinMain().getPlugin("Playlist").getPlaylist().ensureVisible(monty.getCurrentSong().getID()) + self.p.getWinMain().getPlugin("Playlist").getPlaylist().ensureVisible(monty.getCurrentSong().getID()) def onStateChange(self, params): newState=monty.getStatus()['state'] @@ -224,21 +222,21 @@ class wgPlayControl(QtGui.QWidget): status=monty.getStatus() if status['state']=='play': monty.pause() - log.extended("Starting playback") + self.p.extended("Toggling playback") elif status['state']=='stop': monty.play(None) - log.extended("Pausing playback") + self.p.extended("Pausing playback") else: monty.resume() def onBtnStopClick(self): monty.stop() - log.extended("Stopping playback") + self.p.extended("Stopping playback") def onBtnPreviousClick(self): monty.previous() - log.extended("Playing previous") + self.p.extended("Playing previous") def onBtnNextClick(self): monty.next() - log.extended("Playing next") + self.p.extended("Playing next") def onTimeSliderChange(self): monty.seek(self.slrTime.value()) def onVolumeSliderChange(self): @@ -276,7 +274,8 @@ class pluginPlayControl(Plugin): self.addMontyListener('onDisconnect', self.onDisconnect) self.addMontyListener('onTimeChange', self.onTimeChange) def _load(self): - self.o=wgPlayControl(self) + self.o=wgPlayControl(None) + self.o.p=self def _unload(self): self.o=None def getInfo(self): diff --git a/plugins/Scrobbler.py b/plugins/Scrobbler.py index e717c0a..b07af59 100644 --- a/plugins/Scrobbler.py +++ b/plugins/Scrobbler.py @@ -2,7 +2,8 @@ import time import datetime from clPlugin import * -import log + +# TODO cached failed submissions class pluginScrobbler(Plugin): submitted=False @@ -18,11 +19,11 @@ class pluginScrobbler(Plugin): def _login(self): self.submitting=False if self._username(): - log.normal("Scrobbler: logging in %s"%(self._username())) + self.normal("logging in %s"%(self._username())) login(self._username(), self._password()) - log.normal("Scrobbler: logged in") + self.normal("logged in") else: - log.debug("Scrobbler: no username provided, not logging in") + self.debug("no username provided, not logging in") def _username(self): return settings.get('scrobbler.username', '') @@ -34,33 +35,33 @@ class pluginScrobbler(Plugin): if song.getTag('time')>30: if int(params['newTime'])>int(song.getTag('time'))/2 \ or int(params['newTime'])>240: - log.normal("Scrobbler: submitting song") + self.normal("submitting song") submit(song.getArtist(), song.getTitle(), self.time, 'P', '', song.getTag('time'), song.getAlbum(), song.getTrack(), False) - log.debug("Scrobbler: flushing ...") + self.debug("flushing ...") try: flush() self.submitted=True except SessionError, e: - log.important("Scrobbler: failed to submit song - %s"%(e)) - log.extended("Logging in ...") + self.important("failed to submit song - %s"%(e)) + self.extended("Logging in ...") self._login() try: flush() self.submitted=True except Exception, e: - log.important("Scrobbler: failed to submit song - %s"%(e)) - log.debug("Scrobbler: flushed") + self.important("failed to submit song - %s"%(e)) + self.debug("flushed") def onSongChange(self, params): self.time=int(time.mktime(datetime.utcnow().timetuple())) self.submitted=False song=monty.getCurrentSong() try: - log.extended("Scrobbler: submitting now playing") + self.extended("submitting now playing") now_playing(song.getArtist(), song.getTitle(), song.getAlbum(), "", song.getTrack()) - log.debug("Scrobbler: submitted") + self.debug("submitted") except AuthError, e: - log.important("Scrobbler: failed to submit playing song - %s"%(e)) + self.important("failed to submit playing song - %s"%(e)) def _getSettings(self): return [ ['scrobbler.username', 'Username', 'Username to submit to last.fm.', QtGui.QLineEdit(self._username())], diff --git a/plugins/Tabs.py b/plugins/Tabs.py index 9d95701..2a04733 100644 --- a/plugins/Tabs.py +++ b/plugins/Tabs.py @@ -28,6 +28,7 @@ TABS_DEFAULT_SITES='azchords.com <pre>(.*?)</pre>\n'\ class wgTabs(QtGui.QWidget): " contains the tabs" txt=None + p=None # plugin def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.txt=QtGui.QTextEdit(parent) @@ -137,6 +138,7 @@ class pluginTabs(Plugin): self.addMontyListener('onDisconnect', self.onDisconnect) def _load(self): self.o=wgTabs(None) + self.o.p=self self.refresh(None) def _unload(self): self.o=None |