forked from buildbot/buildbot
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into buildbot-0.8.0
* master: migrate recode_changes into OldChangeManager, don't convert to string add docs for potential encoding problems tweaks to contrib script Get fix_changes_pickle_encoding script working and tested...sort of Improve exception on unicode decode failure Raise an exception if the db can't store unicode data formatting Test regular ascii data Test that trying to import non-utf8 data will raise exceptions Make remove_none return u"" for None, and not replace data Reduce length of scheduler name, class_name columns so they fit with Decode strings from change objects as if they're utf-8.
- Loading branch information
Showing
10 changed files
with
269 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
buildbot/test/regressions/test_import_unicode_changes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
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 | ||
|
||
import buildbot | ||
|
||
class Thing: | ||
def __init__(self, **kwargs): | ||
self.__dict__.update(kwargs) | ||
|
||
|
||
class TestUnicodeChanges(unittest.TestCase): | ||
def setUp(self): | ||
self.basedir = "UnicodeChanges" | ||
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() | ||
|
||
def testUnicodeChange(self): | ||
# Create changes.pck | ||
changes = [Change(who=u"Frosty the \N{SNOWMAN}".encode("utf8"), | ||
files=["foo"], comments=u"Frosty the \N{SNOWMAN}".encode("utf8"), | ||
branch="b1", revision=12345)] | ||
cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, | ||
"changes.pck"), "w")) | ||
|
||
sm = manager.DBSchemaManager(self.spec, self.basedir) | ||
sm.upgrade(quiet=True) | ||
|
||
c = self.db.getChangeNumberedNow(1) | ||
|
||
self.assertEquals(c.who, u"Frosty the \N{SNOWMAN}") | ||
self.assertEquals(c.comments, u"Frosty the \N{SNOWMAN}") | ||
|
||
def testNonUnicodeChange(self): | ||
# Create changes.pck | ||
changes = [Change(who="\xff\xff\x00", files=["foo"], | ||
comments="\xff\xff\x00", branch="b1", revision=12345)] | ||
cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, | ||
"changes.pck"), "w")) | ||
|
||
sm = manager.DBSchemaManager(self.spec, self.basedir) | ||
self.assertRaises(UnicodeError, lambda : sm.upgrade(quiet=True)) | ||
|
||
def testAsciiChange(self): | ||
# Create changes.pck | ||
changes = [Change(who="Frosty the Snowman", | ||
files=["foo"], comments="Frosty the Snowman", branch="b1", revision=12345)] | ||
cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, | ||
"changes.pck"), "w")) | ||
|
||
sm = manager.DBSchemaManager(self.spec, self.basedir) | ||
sm.upgrade(quiet=True) | ||
|
||
c = self.db.getChangeNumberedNow(1) | ||
|
||
self.assertEquals(c.who, "Frosty the Snowman") | ||
self.assertEquals(c.comments, "Frosty the Snowman") | ||
|
||
def testUTF16Change(self): | ||
# Create changes.pck | ||
cm = OldChangeMaster() | ||
cm.changes = [Change(who=u"Frosty the \N{SNOWMAN}".encode("utf16"), | ||
files=["foo"], comments=u"Frosty the \N{SNOWMAN}".encode("utf16"), | ||
branch="b1", revision=12345)] | ||
|
||
# instead of running contrib/fix_changes_pickle_encoding.py, we just call | ||
# the changemanager's recode_changes directly - it's the function at the | ||
# heart of the script anyway. | ||
cm.recode_changes('utf16', quiet=True) | ||
|
||
# and dump the recoded changemanager to changes.pck before trying a schema upgrade | ||
cPickle.dump(cm, open(os.path.join(self.basedir, "changes.pck"), "w")) | ||
|
||
sm = manager.DBSchemaManager(self.spec, self.basedir) | ||
sm.upgrade(quiet=True) | ||
|
||
c = self.db.getChangeNumberedNow(1) | ||
|
||
self.assertEquals(c.who, u"Frosty the \N{SNOWMAN}") | ||
self.assertEquals(c.comments, u"Frosty the \N{SNOWMAN}") | ||
|
||
class TestMySQLDBUnicodeChanges(TestUnicodeChanges): | ||
def setUp(self): | ||
self.basedir = "MySQLDBUnicodeChanges" | ||
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( | ||
"mysql://buildbot_test:buildbot_test@localhost/buildbot_test", self.basedir) | ||
|
||
self.db = DBConnector(self.spec) | ||
self.db.start() | ||
|
||
result = self.db.runQueryNow("SHOW TABLES") | ||
for row in result: | ||
self.db.runQueryNow("DROP TABLE %s" % row[0]) | ||
self.db.runQueryNow("COMMIT") | ||
|
||
try: | ||
import MySQLdb | ||
conn = MySQLdb.connect(user="buildbot_test", db="buildbot_test", | ||
passwd="buildbot_test", use_unicode=True, charset='utf8') | ||
except: | ||
TestMySQLDBUnicodeChanges.skip = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python | ||
"""%prog [options] [changes.pck] old_encoding | ||
Re-encodes changes in a pickle file to UTF-8 from the given encoding | ||
""" | ||
|
||
if __name__ == '__main__': | ||
import sys, os | ||
from cPickle import load, dump | ||
from optparse import OptionParser | ||
|
||
parser = OptionParser(__doc__) | ||
|
||
options, args = parser.parse_args() | ||
|
||
if len(args) == 2: | ||
changes_file = args[0] | ||
old_encoding = args[1] | ||
elif len(args) == 1: | ||
changes_file = "changes.pck" | ||
old_encoding = args[0] | ||
else: | ||
parser.error("Need at least one argument") | ||
|
||
print "opening %s" % (changes_file,) | ||
try: | ||
fp = open(changes_file) | ||
except IOError, e: | ||
parser.error("Couldn't open %s: %s" % (changes_file, str(e))) | ||
|
||
changemgr = load(fp) | ||
fp.close() | ||
|
||
print "decoding bytestrings in %s using %s" % (changes_file, old_encoding) | ||
changemgr.recode_changes(old_encoding) | ||
|
||
changes_backup = changes_file + ".old" | ||
i = 0 | ||
while os.path.exists(changes_backup): | ||
i += 1 | ||
changes_backup = changes_file + ".old.%i" % i | ||
print "backing up %s to %s" % (changes_file, changes_backup) | ||
os.rename(changes_file, changes_backup) | ||
|
||
dump(changemgr, open(changes_file, "w")) |
Oops, something went wrong.