4 import dbus
.mainloop
.glib
12 from chanpool
import ChanPool
15 INTERFACE
= 'py.chans.dbus'
17 PLUGINS_DIR
= 'plugins'
19 mainloop
= gobject
.MainLoop()
23 signal
.signal(signal
.SIGTERM
, sigTermCB
)
24 logging
.basicConfig(level
=logging
.DEBUG
, filename
=logfile
, format
='[%(asctime)s] [%(levelname)s] %(message)s', datefmt
='%Y-%m-%d %H:%M:%S')
26 options
= config
.read_config('configs/config.cfg')
27 boards
= load_boards('plugins')
29 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
30 session_bus
= dbus
.SessionBus()
31 name
= dbus
.service
.BusName(INTERFACE
, session_bus
)
34 for chan
in options
.keys(): # ['2ch', 'iichan']
36 for board_type
in options
[chan
]['boards'].keys(): # {'wakaba': ['b', 's'], 'kareha': ['beta/v', 'beta/a']}
37 if boards
.has_key(board_type
):
38 for board
in options
[chan
]['boards'][board_type
]: # ['b', 's']
39 myboards
.append( boards
[board_type
](session_bus
, OBJ_PATH
+'/'+ chan
+'/'+ board
, name
=board
, base_uri
=options
[chan
]['base_uri']) )
41 chans
.append( Chan(session_bus
, OBJ_PATH
+'/'+ chan
, name
=chan
, base_uri
=options
[chan
]['base_uri'], boards
=myboards
) )
43 ChanPool(session_bus
, OBJ_PATH
, chans
)
47 def load_boards(path
):
50 for plugin
in os
.listdir(path
):
51 if plugin
.startswith('plugin_') and plugin
.endswith('.py'):
53 board_type
= plugin
[7:]
54 file, pathname
, description
= imp
.find_module(path
+ '/' + plugin
)
57 metaboard
= imp
.load_module(plugin
, file, pathname
, description
).MetaBoard
59 # logging.error('PLUGIN: can\'t load %s' %board_type)
61 boards
[board_type
] = metaboard
62 logging
.info('PLUGIN: %s loaded' %board_type
)
67 def sigTermCB(signum
, frame
):
69 os
.remove('chanspyd.pid')