]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/base.py
Add bot that automatically tweets some things
[ipfire.org.git] / src / backend / base.py
index 94b9de0f4080f85ceefab07746a86d95cd149616..6c79d8bf44406e4de7d85241b107a6ebabe1ef42 100644 (file)
@@ -1,27 +1,29 @@
 #!/usr/bin/python
 
-import ConfigParser as configparser
-import StringIO
-
-import accounts
-import ads
-import database
-import geoip
-import fireinfo
-import iuse
-import memcached
-import mirrors
-import netboot
-import nopaste
-import news
-import releases
-import settings
-import talk
+import configparser
+import io
+import tornado.gen
 
+from . import accounts
 from . import blog
+from . import database
+from . import geoip
+from . import fireinfo
+from . import iuse
+from . import memcached
+from . import messages
+from . import mirrors
+from . import netboot
+from . import nopaste
+from . import releases
+from . import settings
+from . import talk
+from . import tweets
+from . import wiki
 from . import zeiterfassung
+from .decorators import *
 
-DEFAULT_CONFIG = StringIO.StringIO("""
+DEFAULT_CONFIG = io.StringIO("""
 [global]
 debug = false
 
@@ -47,19 +49,17 @@ class Backend(object):
 
                # Initialize backend modules.
                self.accounts = accounts.Accounts(self)
-               self.advertisements = ads.Advertisements(self)
-               self.downloads = mirrors.Downloads(self)
                self.geoip = geoip.GeoIP(self)
                self.fireinfo = fireinfo.Fireinfo(self)
                self.iuse = iuse.IUse(self)
                self.mirrors = mirrors.Mirrors(self)
                self.netboot = netboot.NetBoot(self)
                self.nopaste = nopaste.Nopaste(self)
-               self.news = news.News(self)
                self.releases = releases.Releases(self)
                self.talk = talk.Talk(self)
 
                self.blog = blog.Blog(self)
+               self.wiki = wiki.Wiki(self)
                self.zeiterfassung = zeiterfassung.ZeiterfassungClient(self)
 
        def read_config(self, configfile):
@@ -85,3 +85,35 @@ class Backend(object):
                }
 
                self.db = database.Connection(**credentials)
+
+       @tornado.gen.coroutine
+       def run_task(self, task, *args, **kwargs):
+               tasks = {
+                       "check-mirrors"     : self.mirrors.check_all,
+                       "cleanup-messages"  : self.messages.queue.cleanup,
+                       "scan-files"        : self.releases.scan_files,
+                       "send-all-messages" : self.messages.queue.send_all,
+                       "tweet"             : self.tweets.tweet,
+                       "update-blog-feeds" : self.blog.update_feeds,
+               }
+
+               # Get the task from the list of all tasks
+               func = tasks.get(task, None)
+               if not func:
+                       raise ValueError("Unknown task: %s" % task)
+
+               # Run the task
+               r = yield func(*args, **kwargs)
+
+               # If any error code has been returned,
+               # we will end the program
+               if r:
+                       raise SystemExit(r)
+
+       @lazy_property
+       def messages(self):
+               return messages.Messages(self)
+
+       @lazy_property
+       def tweets(self):
+               return tweets.Tweets(self)