source: newsbeuter-dbus/trunk/newsbeuter_dbus.py @ 51

Last change on this file since 51 was 47, checked in by simon, 17 years ago
  • Initial version of newsbeuter_dbus.py, a script implementing the org.gnome.feed.Reader interface to add feed URLs to the newsbeuter urls file.
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-python
File size: 1.2 KB
RevLine 
[47]1#!/usr/bin/env python
2
3import dbus.service
4import os.path
5import sys
6
7service = 'org.gnome.feed.Reader'
8object_path = '/org/gnome/feed/Reader'
9interface = 'org.gnome.feed.Reader'
10
11urls_source = os.path.expanduser('~/.newsbeuter/urls')
12
13
14class FeedReader(dbus.service.Object):
15
16    @dbus.service.method(dbus_interface=interface,
17                         in_signature='s', out_signature='b')
18    def Subscribe(self, url):
19        added = False
20        try:
21            urls = open(urls_source, 'a')
22            urls.write(url+'\n')
23            urls.close()
24            added = True
25        finally:
26            return added
27
28
29if __name__ == '__main__':
30    import logging
31    logging.basicConfig(level=logging.DEBUG)
32
33    import gobject
34    from dbus import SessionBus
35    from dbus.mainloop.glib import DBusGMainLoop
36
37    DBusGMainLoop(set_as_default=True)
38
39    session_bus = SessionBus()
40    bus_name = dbus.service.BusName(service, bus=session_bus)
41    feed_reader = FeedReader(object_path=object_path, bus_name=bus_name)
42
43    try:
44        main_loop = gobject.MainLoop()
45        main_loop.run()
46    except KeyboardInterrupt:
47        logging.info('Keyboard Interrupt. Exiting.')
48    except:
49        logging.error(sys.exc_info[0])
Note: See TracBrowser for help on using the repository browser.