Skip to content

Commit

Permalink
Handle change.files entries with nested lists
Browse files Browse the repository at this point in the history
I don't know where these come from, but they're easy enough to handle.
Fixes buildbot#915.
  • Loading branch information
Dustin J. Mitchell committed Jul 9, 2010
1 parent 5f50fc8 commit a0ca76e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
17 changes: 16 additions & 1 deletion master/buildbot/db/schema/v1.py
Expand Up @@ -297,7 +297,22 @@ def remove_none(x):
for link in change.links:
cursor.execute(util.sql_insert(self.dbapi, 'change_links', ('changeid', 'link')),
(change.number, link))
for filename in change.files:

# sometimes change.files contains nested lists -- why, I do not know! But we deal with
# it all the same - see bug #915. We'll assume for now that change.files contains *either*
# lists of filenames or plain filenames, not both.
def flatten(l):
if l and type(l[0]) == list:
rv = []
for e in l:
if type(e) == list:
rv.extend(e)
else:
rv.append(e)
return rv
else:
return l
for filename in flatten(change.files):
cursor.execute(util.sql_insert(self.dbapi, 'change_files', ('changeid', 'filename')),
(change.number, filename))
for propname,propvalue in change.properties.properties.items():
Expand Down
51 changes: 51 additions & 0 deletions master/buildbot/test/regressions/test_import_weird_changes.py
@@ -0,0 +1,51 @@
import os
import shutil
import cPickle

from twisted.trial import unittest

from buildbot.changes.changes import Change, OldChangeMaster

from buildbot.db.schema import manager
from buildbot.db.dbspec import DBSpec
from buildbot.db.connector import DBConnector

class TestWeirdChanges(unittest.TestCase):
def setUp(self):
self.basedir = "WeirdChanges"
if os.path.exists(self.basedir):
shutil.rmtree(self.basedir)
os.makedirs(self.basedir)

# Now try the upgrade process, which will import the old changes.
self.spec = DBSpec.from_url("sqlite:///state.sqlite", self.basedir)

self.db = DBConnector(self.spec)
self.db.start()

def tearDown(self):
if self.db:
self.db.stop()
if os.path.exists(self.basedir):
shutil.rmtree(self.basedir)

def mkchanges(self, changes):
import buildbot.changes.changes
cm = buildbot.changes.changes.OldChangeMaster()
cm.changes = changes
return cm

def testListsAsFilenames(self):
# Create changes.pck
changes = [Change(who=u"Frosty the \N{SNOWMAN}".encode("utf8"),
files=[["foo","bar"],['bing']], comments=u"Frosty the \N{SNOWMAN}".encode("utf8"),
branch="b1", revision=12345)]
cPickle.dump(self.mkchanges(changes), open(os.path.join(self.basedir,
"changes.pck"), "wb"))

sm = manager.DBSchemaManager(self.spec, self.basedir)
sm.upgrade(quiet=True)

c = self.db.getChangeNumberedNow(1)

self.assertEquals(sorted(c.files), sorted([u"foo", u"bar", u"bing"]))

0 comments on commit a0ca76e

Please sign in to comment.