/
dbconfig.py
68 lines (52 loc) · 2.06 KB
/
dbconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
from buildbot.db import enginestrategy
from buildbot.db import model
from buildbot.db import state
class FakeDBConnector(object):
pass
class FakeCacheManager(object):
def get_cache(self, cache_name, miss_fn):
return None
class FakeMaster(object):
pass
class FakePool(object):
pass
class DbConfig(object):
def __init__(self, db_url, basedir, name="config"):
self.db_url = db_url
self.basedir = basedir
self.name = name
def getDb(self):
db_engine = enginestrategy.create_engine(self.db_url,
basedir=self.basedir)
db = FakeDBConnector()
db.master = FakeMaster()
db.pool = FakePool()
db.pool.engine = db_engine
db.master.caches = FakeCacheManager()
db.model = model.Model(db)
db.state = state.StateConnectorComponent(db)
self.objectid = db.state.thdGetObjectId(db_engine, self.name, "DbConfig")['id']
return db
def get(self, name, default=state.StateConnectorComponent.Thunk):
db = self.getDb()
ret = db.state.thdGetState(db.pool.engine, self.objectid, name, default=default)
db.pool.engine.close()
return ret
def set(self, name, value):
db = self.getDb()
db.state.thdSetState(db.pool.engine, self.objectid, name, value)
db.pool.engine.close()