]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/base.py
f85d2ad891c88c112e57e95235dceabeb2c7cb3b
5 import tornado
.httpclient
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")
48 self
.http_client
= tornado
.httpclient
.AsyncHTTPClient(
50 "User-Agent" : "IPFireWebApp",
53 # Initialize settings first.
54 self
.settings
= settings
.Settings(self
)
55 self
.memcache
= memcached
.Memcached(self
)
57 # Initialize backend modules.
58 self
.accounts
= accounts
.Accounts(self
)
59 self
.geoip
= geoip
.GeoIP(self
)
60 self
.fireinfo
= fireinfo
.Fireinfo(self
)
61 self
.iuse
= iuse
.IUse(self
)
62 self
.mirrors
= mirrors
.Mirrors(self
)
63 self
.netboot
= netboot
.NetBoot(self
)
64 self
.nopaste
= nopaste
.Nopaste(self
)
65 self
.releases
= releases
.Releases(self
)
66 self
.talk
= talk
.Talk(self
)
68 self
.blog
= blog
.Blog(self
)
69 self
.wiki
= wiki
.Wiki(self
)
70 self
.zeiterfassung
= zeiterfassung
.ZeiterfassungClient(self
)
72 def read_config(self
, configfile
):
73 cp
= configparser
.ConfigParser()
75 # Initialize configuration with some sensible defaults
76 cp
.readfp(DEFAULT_CONFIG
)
83 def setup_database(self
):
85 Sets up the database connection.
88 "host" : self
.config
.get("database", "server"),
89 "database" : self
.config
.get("database", "database"),
90 "user" : self
.config
.get("database", "username"),
91 "password" : self
.config
.get("database", "password"),
94 self
.db
= database
.Connection(**credentials
)
96 async def run_task(self
, task
, *args
, **kwargs
):
98 "check-mirrors" : self
.mirrors
.check_all
,
99 "check-spam" : self
.accounts
.check_spam
,
100 "cleanup" : self
.cleanup
,
101 "scan-files" : self
.releases
.scan_files
,
102 "send-all-messages" : self
.messages
.queue
.send_all
,
103 "test-blacklist" : self
.geoip
.test_blacklist
,
104 "test-ldap" : self
.accounts
.test_ldap
,
105 "tweet" : self
.tweets
.tweet
,
106 "update-blog-feeds" : self
.blog
.update_feeds
,
109 # Get the task from the list of all tasks
110 func
= tasks
.get(task
, None)
112 raise ValueError("Unknown task: %s" % task
)
115 r
= await func(*args
, **kwargs
)
117 # If any error code has been returned,
118 # we will end the program
124 return accounts
.Groups(self
)
128 return messages
.Messages(self
)
131 def ratelimiter(self
):
132 return ratelimit
.RateLimiter(self
)
136 return tweets
.Tweets(self
)
138 async def cleanup(self
):
139 # Cleanup message queue
140 with self
.db
.transaction():
141 self
.messages
.queue
.cleanup()
143 # Cleanup in accounts
144 with self
.db
.transaction():
145 self
.accounts
.cleanup()