]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/base.py
40cc70a0ee74e02837ee1e324c95fe490b2eedc5
11 from . import fireinfo
13 from . import memcached
14 from . import messages
18 from . import ratelimit
19 from . import releases
20 from . import settings
24 from . import zeiterfassung
25 from .decorators
import *
27 DEFAULT_CONFIG
= io
.StringIO("""
32 static_dir = %(data_dir)s/static
33 templates_dir = %(data_dir)s/templates
36 class Backend(object):
37 def __init__(self
, configfile
, debug
=False):
38 # Read configuration file.
39 self
.config
= self
.read_config(configfile
)
41 # Enable debug logging if configured
42 self
.debug
= debug
or self
.config
.getboolean("global", "debug")
47 # Initialize settings first.
48 self
.settings
= settings
.Settings(self
)
49 self
.memcache
= memcached
.Memcached(self
)
51 # Initialize backend modules.
52 self
.accounts
= accounts
.Accounts(self
)
53 self
.geoip
= geoip
.GeoIP(self
)
54 self
.fireinfo
= fireinfo
.Fireinfo(self
)
55 self
.iuse
= iuse
.IUse(self
)
56 self
.mirrors
= mirrors
.Mirrors(self
)
57 self
.netboot
= netboot
.NetBoot(self
)
58 self
.nopaste
= nopaste
.Nopaste(self
)
59 self
.releases
= releases
.Releases(self
)
60 self
.talk
= talk
.Talk(self
)
62 self
.blog
= blog
.Blog(self
)
63 self
.wiki
= wiki
.Wiki(self
)
64 self
.zeiterfassung
= zeiterfassung
.ZeiterfassungClient(self
)
66 def read_config(self
, configfile
):
67 cp
= configparser
.ConfigParser()
69 # Initialize configuration with some sensible defaults
70 cp
.readfp(DEFAULT_CONFIG
)
77 def setup_database(self
):
79 Sets up the database connection.
82 "host" : self
.config
.get("database", "server"),
83 "database" : self
.config
.get("database", "database"),
84 "user" : self
.config
.get("database", "username"),
85 "password" : self
.config
.get("database", "password"),
88 self
.db
= database
.Connection(**credentials
)
90 @tornado.gen
.coroutine
91 def run_task(self
, task
, *args
, **kwargs
):
93 "check-mirrors" : self
.mirrors
.check_all
,
94 "cleanup" : self
.cleanup
,
95 "scan-files" : self
.releases
.scan_files
,
96 "send-all-messages" : self
.messages
.queue
.send_all
,
97 "tweet" : self
.tweets
.tweet
,
98 "update-blog-feeds" : self
.blog
.update_feeds
,
101 # Get the task from the list of all tasks
102 func
= tasks
.get(task
, None)
104 raise ValueError("Unknown task: %s" % task
)
107 r
= yield func(*args
, **kwargs
)
109 # If any error code has been returned,
110 # we will end the program
116 return messages
.Messages(self
)
119 def ratelimiter(self
):
120 return ratelimit
.RateLimiter(self
)
124 return tweets
.Tweets(self
)
126 @tornado.gen
.coroutine
128 # Cleanup message queue
129 with self
.db
.transaction():
130 self
.messages
.queue
.cleanup()
132 # Cleanup in accounts
133 with self
.db
.transaction():
134 self
.accounts
.cleanup()