Skip to content

Commit

Permalink
fix simplejson import in buildbot.db
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Feb 15, 2010
1 parent d7dcf3e commit b458737
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions buildbot/db.py
Expand Up @@ -36,7 +36,11 @@
# ***** END LICENSE BLOCK *****

import sys, time, collections, base64
import simplejson
try:
import simplejson
json = simplejson # this hushes pyflakes
except ImportError:
import json
from twisted.python import log, reflect, threadable
from twisted.internet import defer, reactor
from twisted.enterprise import adbapi
Expand Down Expand Up @@ -572,7 +576,7 @@ def _txn_addChangeToDatabase(self, t, change):
" VALUES (?,?)"),
(change.number, filename))
for propname,propvalue in change.properties.properties.items():
encoded_value = simplejson.dumps(propvalue)
encoded_value = json.dumps(propvalue)
t.execute(self.quoteq("INSERT INTO change_properties"
" (changeid, property_name, property_value)"
" VALUES (?,?,?)"),
Expand Down Expand Up @@ -796,7 +800,7 @@ def _txn_get_properties_from_db(self, t, tablename, idname, id):
t.execute(q, (id,))
retval = Properties()
for key, valuepair in t.fetchall():
value, source = simplejson.loads(valuepair)
value, source = json.loads(valuepair)
retval.setProperty(str(key), value, source)
return retval

Expand Down Expand Up @@ -826,7 +830,7 @@ def _addSchedulers(self, t, added):
t.execute(q)
max_changeid = _one_or_else(t.fetchall(), 0)
state = scheduler.get_initial_state(max_changeid)
state_json = simplejson.dumps(state)
state_json = json.dumps(state)
q = self.quoteq("INSERT INTO schedulers"
" (schedulerid, name, state)"
" VALUES (?,?,?)")
Expand All @@ -839,10 +843,10 @@ def scheduler_get_state(self, schedulerid, t):
t.execute(q, (schedulerid,))
state_json = _one_or_else(t.fetchall())
assert state_json is not None
return simplejson.loads(state_json)
return json.loads(state_json)

def scheduler_set_state(self, schedulerid, t, state):
state_json = simplejson.dumps(state)
state_json = json.dumps(state)
q = self.quoteq("UPDATE schedulers SET state=? WHERE schedulerid=?")
t.execute(q, (state_json, schedulerid))

Expand Down Expand Up @@ -890,7 +894,7 @@ def create_buildset(self, ssid, reason, properties, builderNames, t,
" VALUES (?,?,?,?,?)"),
(bsid, external_idstring, reason, ssid, now))
for propname, propvalue in properties.properties.items():
encoded_value = simplejson.dumps(propvalue)
encoded_value = json.dumps(propvalue)
t.execute(self.quoteq("INSERT INTO buildset_properties"
" (buildsetid, property_name, property_value)"
" VALUES (?,?,?)"),
Expand Down Expand Up @@ -1190,7 +1194,7 @@ def generic_get(self, key, default=None, t=None):
def _txn_generic_get(self, t, key, default):
q = self.quoteq("SELECT value FROM generic WHERE `key`=?")
t.execute(q, (key,))
return _one_or_else(t.fetchall(), default, simplejson.loads)
return _one_or_else(t.fetchall(), default, json.loads)

def generic_set(self, key, value, t=None):
if t:
Expand All @@ -1202,10 +1206,10 @@ def _txn_generic_set(self, t, key, value):
t.execute(q, (key,))
if t.fetchall():
q = self.quoteq("UPDATE generic SET value=? WHERE `key`=?")
t.execute(q, (simplejson.dumps(value), key))
t.execute(q, (json.dumps(value), key))
else:
q = self.quoteq("INSERT INTO generic (`key`, value) VALUES (?,?)")
t.execute(q, (key, simplejson.dumps(value)))
t.execute(q, (key, json.dumps(value)))

# test/debug methods

Expand Down

0 comments on commit b458737

Please sign in to comment.