]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/base.py
11 from . import fireinfo
13 from . import memcached
14 from . import messages
18 from . import releases
19 from . import settings
22 from . import zeiterfassung
23 from .decorators
import *
25 DEFAULT_CONFIG
= io
.StringIO("""
30 static_dir = %(data_dir)s/static
31 templates_dir = %(data_dir)s/templates
34 class Backend(object):
35 def __init__(self
, configfile
, debug
=False):
36 # Read configuration file.
37 self
.config
= self
.read_config(configfile
)
39 # Enable debug logging if configured
40 self
.debug
= debug
or self
.config
.getboolean("global", "debug")
45 # Initialize settings first.
46 self
.settings
= settings
.Settings(self
)
47 self
.memcache
= memcached
.Memcached(self
)
49 # Initialize backend modules.
50 self
.accounts
= accounts
.Accounts(self
)
51 self
.geoip
= geoip
.GeoIP(self
)
52 self
.fireinfo
= fireinfo
.Fireinfo(self
)
53 self
.iuse
= iuse
.IUse(self
)
54 self
.mirrors
= mirrors
.Mirrors(self
)
55 self
.netboot
= netboot
.NetBoot(self
)
56 self
.nopaste
= nopaste
.Nopaste(self
)
57 self
.releases
= releases
.Releases(self
)
58 self
.talk
= talk
.Talk(self
)
60 self
.blog
= blog
.Blog(self
)
61 self
.wiki
= wiki
.Wiki(self
)
62 self
.zeiterfassung
= zeiterfassung
.ZeiterfassungClient(self
)
64 def read_config(self
, configfile
):
65 cp
= configparser
.ConfigParser()
67 # Initialize configuration with some sensible defaults
68 cp
.readfp(DEFAULT_CONFIG
)
75 def setup_database(self
):
77 Sets up the database connection.
80 "host" : self
.config
.get("database", "server"),
81 "database" : self
.config
.get("database", "database"),
82 "user" : self
.config
.get("database", "username"),
83 "password" : self
.config
.get("database", "password"),
86 self
.db
= database
.Connection(**credentials
)
88 @tornado.gen
.coroutine
89 def run_task(self
, task
, *args
, **kwargs
):
91 "cleanup-messages" : self
.messages
.queue
.cleanup
,
92 "scan-files" : self
.releases
.scan_files
,
93 "send-all-messages" : self
.messages
.queue
.send_all
,
94 "update-blog-feeds" : self
.blog
.update_feeds
,
97 # Get the task from the list of all tasks
98 func
= tasks
.get(task
, None)
100 raise ValueError("Unknown task: %s" % task
)
103 r
= yield func(*args
, **kwargs
)
105 # If any error code has been returned,
106 # we will end the program
112 return messages
.Messages(self
)