Author: dmeyer Date: Sat Oct 13 07:42:43 2007 New Revision: 2857 Log: Add code to plug in the feedmanager into beacon as server plugin and replace the kaa-feedmanager with beacon-feedmanager.
Added: trunk/feedmanager/bin/beacon-feedmanager (contents, props changed) trunk/feedmanager/src/beacon/ trunk/feedmanager/src/beacon/feeds.py Removed: trunk/feedmanager/bin/kaa-feedmanager Modified: trunk/feedmanager/setup.py Added: trunk/feedmanager/bin/beacon-feedmanager ============================================================================== --- (empty file) +++ trunk/feedmanager/bin/beacon-feedmanager Sat Oct 13 07:42:43 2007 @@ -0,0 +1,170 @@ +#!/usr/bin/python +# -*- coding: iso-8859-1 -*- +# ----------------------------------------------------------------------------- +# beacon-feedmanager +# ----------------------------------------------------------------------------- +# $Id$ +# +# ----------------------------------------------------------------------------- +# kaa.feedmanager - Manage RSS/Atom Feeds +# Copyright (C) 2007 Dirk Meyer +# +# First Edition: Dirk Meyer <[EMAIL PROTECTED]> +# Maintainer: Dirk Meyer <[EMAIL PROTECTED]> +# +# Please see the file AUTHORS for a complete list of authors. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MER- +# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# ----------------------------------------------------------------------------- + +import sys + +import kaa +import kaa.notifier +import kaa.beacon + +kaa.beacon.connect() +rpc = kaa.beacon._client.rpc + +def help(): + print 'beacon_feedmanager' + print 'options:' + print '-l list all feeds' + print '-a options add a feed, see examples below' + print '-r id remove feed with the given id' + print '-u [ id ] update all feeds or only the feed with the given id' + print + print 'The beacon_feedmanager adds feeds like audio and video podcasts' + print 'to the filesystem. It either downloads the files or just adds' + print 'the url into the directory. The later is hidden from the normal' + print 'filessytem, only beacon clients such as Freevo can see it.' + print 'Right now, only RSS feeds with links directly to a video or audio' + print 'file are supported, other feeds can be integrated with a plugin' + print 'interface, but there are no special plugins yet.' + print + print 'To add a feed use -a and add the url and the directory where the' + print 'items should be stored as parameter. This will download all files' + print 'on update and keep the old files even when they are not listed in' + print 'the rss feed anymore. There are three further paramater to control' + print 'if the file should be downloaded, the number of items to consider' + print 'and if old files should be kept.' + print + print 'Example:' + print 'download all entries and keep old one' + print 'beacon_feedmanager -a http://url /media/mypodcasts' + print 'link to all entries and not keep old one' + print 'beacon_feedmanager -a http://url /media/mypodcasts False 0 False' + print 'download up to 4 entries and delete old one' + print 'beacon_feedmanager -a http://url /media/mypodcasts True 4 False' + print + sys.exit(0) + +if len(sys.argv) < 2: + help() + +if sys.argv[1] in ('--list', '-l'): + def rpc_return(result): + for f in result: + print 'Feed %d' % f['id'] + for key in ('id', 'url', 'directory', 'download', 'num', 'keep'): + print ' %10s = %s' % (key, f[key]) + print + sys.exit(0) + rpc('feeds.list').connect(rpc_return) + +elif sys.argv[1] in ('--add', '-a') and len(sys.argv) > 3: + def rpc_return(result): + sys.exit(0) + + url = sys.argv[2] + destdir = sys.argv[3] + if len(sys.argv) > 4: + if len(sys.argv) != 7: + help() + if sys.argv[4].lower() in ('true', 'yes'): + download = True + elif sys.argv[4].lower() in ('false', 'no'): + download = False + num = int(sys.argv[5]) + if sys.argv[6].lower() in ('true', 'yes'): + keep = True + elif sys.argv[6].lower() in ('false', 'no'): + keep = False + rpc('feeds.add', url, destdir, download, num, keep).connect(rpc_return) + else: + rpc('feeds.add', url, destdir).connect(rpc_return) + +elif sys.argv[1] in ('--remove', '-r') and len(sys.argv) > 2: + def rpc_return(result): + if not result: + print 'feed not found' + sys.exit(0) + rpc('feeds.remove', int(sys.argv[2])).connect(rpc_return) + +elif sys.argv[1] in ('--update', '-u'): + + @kaa.notifier.yield_execution() + def update(): + n = None + if len(sys.argv) > 2: + n = int(sys.argv[2]) + feeds = rpc('feeds.list') + yield feeds + for f in feeds.get_result(): + if n is None or n == f.get('id'): + print 'update', f.get('url'), '...', + sys.stdout.flush() + result = rpc('feeds.update', f.get('id')) + yield result + if result.get_result(): + print 'ok' + else: + print 'failed' + sys.exit(0) + + @kaa.notifier.yield_execution() + def parallel_update(): + global active + active = 0 + + def finished(result, feed): + print 'finished', feed.get('url'), + if result: + print 'ok' + else: + print 'failed' + global active + active -= 1 + if active == 0: + sys.exit(0) + + feeds = rpc('feeds.list') + yield feeds + for f in feeds.get_result(): + active += 1 + print 'update', f.get('url') + rpc('feeds.update', f.get('id')).connect(finished, f) + +# kaa.beacon.connect() + if len(sys.argv) > 2 and sys.argv[2] == "-p": + parallel_update() + else: + update() + +else: + help() + +kaa.main() Modified: trunk/feedmanager/setup.py ============================================================================== --- trunk/feedmanager/setup.py (original) +++ trunk/feedmanager/setup.py Sat Oct 13 07:42:43 2007 @@ -41,7 +41,8 @@ version = '0.1.0', license = 'LGPL', summary = 'RSS/Atom Feedmanager', - scripts = [ 'bin/kaa-feedmanager' ], + plugins = { 'kaa.beacon.server.plugins': 'src/beacon' }, + scripts = [ 'bin/beacon-feedmanager' ], rpminfo = { 'requires': 'python-kaa-beacon >= 0.1.0', 'build_requires': 'python-kaa-beacon >= 0.1.0' Added: trunk/feedmanager/src/beacon/feeds.py ============================================================================== --- (empty file) +++ trunk/feedmanager/src/beacon/feeds.py Sat Oct 13 07:42:43 2007 @@ -0,0 +1,95 @@ +# -*- coding: iso-8859-1 -*- +# ----------------------------------------------------------------------------- +# beacon/feedmanager.py - Beacon server plugin +# ----------------------------------------------------------------------------- +# $Id$ +# +# ----------------------------------------------------------------------------- +# kaa.feedmanager - Manage RSS/Atom Feeds +# Copyright (C) 2007 Dirk Meyer +# +# First Edition: Dirk Meyer <[EMAIL PROTECTED]> +# Maintainer: Dirk Meyer <[EMAIL PROTECTED]> +# +# Please see the file AUTHORS for a complete list of authors. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MER- +# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# ----------------------------------------------------------------------------- + +# python imports +import os +import logging + +# kaa imports +import kaa.notifier +import kaa.notifier.url +import kaa.feedmanager +import kaa.rpc + +# plugin config object +config = kaa.feedmanager.config + +logging.getLogger('feedmanager').setLevel(logging.DEBUG) + +class IPC(object): + """ + Class to connect the feedmanager to the beacon server ipc. + """ + + @kaa.rpc.expose('feeds.list') + def list(self): + """ + List feeds. + """ + return kaa.feedmanager.list_feeds() + + @kaa.rpc.expose('feeds.add') + def add(self, url, destdir, download=True, num=0, keep=True): + """ + Add a feed. + """ + return kaa.feedmanager.add_feed(url, destdir, download, num, keep) + + @kaa.rpc.expose('feeds.remove') + def remove(self, feed): + """ + Remove the given feed. + """ + if isinstance(feed, dict): + feed = feed.get('id') + return kaa.feedmanager.remove_feed(feed) + + @kaa.rpc.expose('feeds.update') + def update(self, feed): + """ + Update the given feed. + """ + if isinstance(feed, dict): + feed = feed.get('id') + return kaa.feedmanager.update_feed(feed) + + +def plugin_init(server, db): + """ + Init the plugin. + """ + # use ~/.beacon/feedmanager as base dir + database = os.path.join(db.get_directory(), 'feedmanager') + kaa.feedmanager.set_database(database) + server.ipc.connect(IPC()) + # add password information + for auth in kaa.feedmanager.config.authentication: + kaa.notifier.url.add_password(None, auth.site, auth.username, auth.password) ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Freevo-cvslog mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freevo-cvslog
