]>
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
23 from . import zeiterfassung
24 from .decorators
import *
26 DEFAULT_CONFIG
= io
.StringIO("""
31 static_dir = %(data_dir)s/static
32 templates_dir = %(data_dir)s/templates
35 class Backend(object):
36 def __init__(self
, configfile
, debug
=False):
37 # Read configuration file.
38 self
.config
= self
.read_config(configfile
)
40 # Enable debug logging if configured
41 self
.debug
= debug
or self
.config
.getboolean("global", "debug")
46 # Initialize settings first.
47 self
.settings
= settings
.Settings(self
)
48 self
.memcache
= memcached
.Memcached(self
)
50 # Initialize backend modules.
51 self
.accounts
= accounts
.Accounts(self
)
52 self
.geoip
= geoip
.GeoIP(self
)
53 self
.fireinfo
= fireinfo
.Fireinfo(self
)
54 self
.iuse
= iuse
.IUse(self
)
55 self
.mirrors
= mirrors
.Mirrors(self
)
56 self
.netboot
= netboot
.NetBoot(self
)
57 self
.nopaste
= nopaste
.Nopaste(self
)
58 self
.releases
= releases
.Releases(self
)
59 self
.talk
= talk
.Talk(self
)
61 self
.blog
= blog
.Blog(self
)
62 self
.wiki
= wiki
.Wiki(self
)
63 self
.zeiterfassung
= zeiterfassung
.ZeiterfassungClient(self
)
65 def read_config(self
, configfile
):
66 cp
= configparser
.ConfigParser()
68 # Initialize configuration with some sensible defaults
69 cp
.readfp(DEFAULT_CONFIG
)
76 def setup_database(self
):
78 Sets up the database connection.
81 "host" : self
.config
.get("database", "server"),
82 "database" : self
.config
.get("database", "database"),
83 "user" : self
.config
.get("database", "username"),
84 "password" : self
.config
.get("database", "password"),
87 self
.db
= database
.Connection(**credentials
)
89 @tornado.gen
.coroutine
90 def run_task(self
, task
, *args
, **kwargs
):
92 "check-mirrors" : self
.mirrors
.check_all
,
93 "cleanup-messages" : self
.messages
.queue
.cleanup
,
94 "scan-files" : self
.releases
.scan_files
,
95 "send-all-messages" : self
.messages
.queue
.send_all
,
96 "tweet" : self
.tweets
.tweet
,
97 "update-blog-feeds" : self
.blog
.update_feeds
,
100 # Get the task from the list of all tasks
101 func
= tasks
.get(task
, None)
103 raise ValueError("Unknown task: %s" % task
)
106 r
= yield func(*args
, **kwargs
)
108 # If any error code has been returned,
109 # we will end the program
115 return messages
.Messages(self
)
119 return tweets
.Tweets(self
)