4 import dbus
.mainloop
.glib
10 from chanpool
import ChanPool
13 INTERFACE
= 'py.chans.dbus'
16 mainloop
= gobject
.MainLoop()
18 #----------------------------------------------
19 def start(logfile
, opt_chans
):
20 """Loading plugins and run dbus mainloop."""
22 # settings in config file?
23 logging
.basicConfig(level
=logging
.DEBUG
, filename
=logfile
, format
='[%(asctime)s] [%(levelname)s] %(message)s', datefmt
='%Y-%m-%d %H:%M:%S')
25 boards
= load_plugins('plugins')
27 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
28 session_bus
= dbus
.SessionBus()
29 tmp
= dbus
.service
.BusName(INTERFACE
, session_bus
)
32 for chan
in opt_chans
: # [{'2ch': ...}, {'iichan': ...}]
33 chan_name
, settings
= chan
.popitem()
36 for board_dict
in settings
['boards']: # [{'wakaba': ['b', 's']}, {'kareha': ['beta/v', 'beta/a']}]
37 board_type
, boards_list
= board_dict
.popitem()
39 if boards
.has_key(board_type
):
40 for board
in boards_list
: # ['b', 's']
41 myboards
.append( boards
[board_type
](session_bus
, OBJ_PATH
+'/'+ chan_name
+'/'+ board
, name
=board
, base_uri
=settings
['base_uri']) )
43 chans
.append( Chan(session_bus
, OBJ_PATH
+'/'+ chan_name
, name
=chan_name
, base_uri
=settings
['base_uri'], boards
=myboards
) )
45 ChanPool(session_bus
, OBJ_PATH
, chans
)
48 #----------------------------------------------
49 def load_plugins(path
):
50 """Load boards engines."""
54 for plugin
in os
.listdir(path
):
55 if plugin
.startswith('plugin_') and plugin
.endswith('.py'):
57 board_type
= plugin
[7:]
58 file, pathname
, description
= imp
.find_module(path
+ '/' + plugin
)
61 metaboard
= imp
.load_module(plugin
, file, pathname
, description
).MetaBoard
63 # logging.error('PLUGIN: can\'t load %s' %board_type)
65 boards
[board_type
] = metaboard
66 logging
.info('PLUGIN: %s loaded' %board_type
)
70 #----------------------------------------------
72 """Stopping services."""