]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/base.py
10 from . import fireinfo
15 from . import releases
16 from . import settings
20 from . import zeiterfassung
22 DEFAULT_CONFIG
= io
.StringIO("""
27 static_dir = %(data_dir)s/static
28 templates_dir = %(data_dir)s/templates
31 class Backend(object):
32 def __init__(self
, configfile
, debug
=False):
33 # Read configuration file.
34 self
.config
= self
.read_config(configfile
)
36 # Enable debug logging if configured
37 self
.debug
= debug
or self
.config
.getboolean("global", "debug")
42 # Initialize settings first.
43 self
.settings
= settings
.Settings(self
)
45 # Initialize backend modules.
46 self
.accounts
= accounts
.Accounts(self
)
47 self
.geoip
= geoip
.GeoIP(self
)
48 self
.fireinfo
= fireinfo
.Fireinfo(self
)
49 self
.iuse
= iuse
.IUse(self
)
50 self
.mirrors
= mirrors
.Mirrors(self
)
51 self
.netboot
= netboot
.NetBoot(self
)
52 self
.nopaste
= nopaste
.Nopaste(self
)
53 self
.releases
= releases
.Releases(self
)
54 self
.talk
= talk
.Talk(self
)
56 self
.blog
= blog
.Blog(self
)
57 self
.zeiterfassung
= zeiterfassung
.ZeiterfassungClient(self
)
59 def read_config(self
, configfile
):
60 cp
= configparser
.ConfigParser()
62 # Initialize configuration with some sensible defaults
63 cp
.readfp(DEFAULT_CONFIG
)
70 def setup_database(self
):
72 Sets up the database connection.
75 "host" : self
.config
.get("database", "server"),
76 "database" : self
.config
.get("database", "database"),
77 "user" : self
.config
.get("database", "username"),
78 "password" : self
.config
.get("database", "password"),
81 self
.db
= database
.Connection(**credentials
)
83 @tornado.gen
.coroutine
84 def run_task(self
, task
, *args
, **kwargs
):
86 "update-blog-feeds" : self
.blog
.update_feeds
,
89 # Get the task from the list of all tasks
90 func
= tasks
.get(task
, None)
92 raise ValueError("Unknown task: %s" % task
)
95 r
= yield func(*args
, **kwargs
)
97 # If any error code has been returned,
98 # we will end the program