Hi,
On 26.11.04, Nicolas Évrard wrote:
As promised (but later than expected due to the sudden arrival of the real life in my geek life) here comes the first plugin architecture (what a presomptuous name for this hack).
Feature:
- Supports the audioscrobbler plugin (which has became official now, if you use it change the client name to 'pte').
Mis-feature:
- the audioscrobbler plugin might be the only one supported
PS: The diff is against debian's pytone 2.1
Thanks a lot. Note that I did not yet include the plugin support in PyTone 2.1.3. I want to stabilize this release a little bit, before going ahead with new features.
I've added a few comments below.
diff -rub --exclude='*pyc' pytone-2.1.0/src/config.py pytone-2.1.0.mine/src/config.py --- pytone-2.1.0/src/config.py 2004-07-28 22:04:37.000000000 +0200 +++ pytone-2.1.0.mine/src/config.py 2004-11-26 00:57:02.000000000 +0100 @@ -120,7 +120,16 @@ def _convert(self, s): return float(s)
+class configlist(configitem):
- def _check(self, s):
try:items = s.split(',')except:raise ConfigError("Expecting list, got '%s'" % s)- def _convert(self, s):
return s.split(',')class configcolor(configitem):
@@ -616,13 +625,16 @@ rescan = configkeys("u U") shuffle = configkeys("r R")
+class plugins(configsection):
- torun = configlist('')
# # register known configuration sections #
sections = ['mixerwindow', 'helpwindow', 'filelistwindow', 'database', 'iteminfowindow', 'logwindow', 'mixer', 'colors', 'playerwindow', 'playlistwindow', 'general',
'inputwindow', 'network', 'player', 'keybindings']
'inputwindow', 'network', 'player', 'keybindings', 'plugins']
If there is only one configuration option ("torun"), we probably don't need a new section.
############################################################################## # end configuration tree
[ snip ws changes ]
diff -rub --exclude='*pyc' pytone-2.1.0/src/pytone.py pytone-2.1.0.mine/src/pytone.py --- pytone-2.1.0/src/pytone.py 2004-07-19 19:58:07.000000000 +0200 +++ pytone-2.1.0.mine/src/pytone.py 2004-11-26 00:46:39.000000000 +0100 @@ -109,6 +109,7 @@ import network network.unixserver(os.path.expanduser(config.network.socketfile)).start()
- # Now that everything is setup, we can initialize the players. This has # to be done after all other services have been setup because # the players immediately start requesting a new song
@@ -119,6 +120,33 @@ hub.hub.notify(events.quit(), 100) raise
+############################################################################## +# Plugins initialization +############################################################################## +initializedPlugins = []
+# Adding the plugin to sys.path +sys.path.insert(0, os.path.expanduser('~/.pytone/plugins'))
We probably should also search in a global module plugins in the pytone module hierarchy.
+# Initializing the plugins determined in the config file +plugins = config.plugins.torun +for name in plugins:
- plugin = __import__(name)
- initializedPlugins.append(plugin.initialize())
+# Now we put sys.path back to normal +del sys.path[0]
+# And now the plugins are all started +for plugin in initializedPlugins:
- try:
plugin.start()- except:
# If a plugin cannot be started it's not really annoying# TODO We should warn the userpass
At the moment, you only support plugins which do not need to create any new window (think about the ID3 tag editor proposed on the list). While this may be okay for the beginning, we have to keep in mind that things like this should be possible.
Btw, could you also send the new version of the audioscrobbler plugin.
Thanks,
Jörg