/usr/share/avant-window-navigator/applets/comics/feed/__init__.py is in awn-applet-comics 0.4.1~bzr1507-0ubuntu7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | # -*- coding: utf-8 -*-
# Copyright (c) 2009 Moses Palmér
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import gobject
import os
from basic import NAME, URL
from rss import RSSFeed
from settings import Settings
from shared import PLUGINS_DIR
class FeedContainer(gobject.GObject):
FEED_ADDED = 0
FEED_REMOVED = 1
__gsignals__ = {
'feed_changed': (gobject.SIGNAL_RUN_FIRST, None, (str, int)),
}
def _add_feed_factory(self, name):
"""Dynamically loads a feed factory from a file and adds it to the list
of factories. If filename does not contain a feed factory, it is not
added."""
try:
module = __import__('plugins.%s' % name, globals(), locals(), [name], -1)
if hasattr(module, 'matches_url') and hasattr(module, 'get_class'):
self.feed_factories[name] = module
return True
else:
del module
except Exception, err:
print "Comics!: Error loading plugin: %s" % err
return False
def _load_feed_factories(self):
"""Loads all feed factories found in the plugin directory."""
try:
for filename in (f for f in os.listdir(PLUGINS_DIR)
if f.endswith('.py')):
self._add_feed_factory(filename.rpartition('.')[0])
except OSError:
pass
def add_feed(self, filename):
"""Loads a feed description from a file."""
# Read file
settings = Settings(filename)
# Check whether all required parameters have been supplied
if NAME in settings and URL in settings:
if settings[NAME] in self.feeds:
return True
try:
plugin = settings.get_string('plugin', '')
if plugin:
if plugin in self.feed_factories:
factory = self.feed_factories[plugin].get_class()
else:
print "Comics!: Plugin '%s' not found" % plugin
return False
else:
factory = RSSFeed
feed = factory(settings)
self.feeds[settings[NAME]] = feed
self.emit('feed-changed', feed, FeedContainer.FEED_ADDED)
except Exception, err:
print "Comics!: Error loading feed: %s" % err
return False
def get_feed_for_url(self, url):
"""Creates a feed suitable for a given URL. If no plugin matches the
URL, an RSSFeed is returned."""
for factory in self.feed_factories:
if self.feed_factories[factory].matches_url(url):
return self.feed_factories[factory].get_class()(url=url)
return RSSFeed(url=url)
def remove_feed(self, feed_name):
"""Removes the feed feed_name."""
if feed_name in self.feeds:
self.emit('feed-changed', feed_name, FeedContainer.FEED_REMOVED)
del self.feeds[feed_name]
def __init__(self):
super(FeedContainer, self).__init__()
self.directories = []
self.feed_factories = {}
self.feeds = {}
self._load_feed_factories()
def load_directory(self, directory):
"""Loads all feeds found in directory."""
# Traverse .feed-files in the directory
if directory not in self.directories:
self.directories.append(directory)
try:
for filename in (f for f in os.listdir(directory)
if f.endswith('.feed')):
self.add_feed(os.path.join(directory, filename))
except OSError:
pass
def update(self):
"""Updates all feeds."""
for feed in self.feeds.values():
feed.update()
|