Store more as plain strings.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 17 Nov 2010 00:11:37 +0000 (01:11 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 17 Nov 2010 00:11:37 +0000 (01:11 +0100)
admin.py
buildfarm/sqldb.py
buildfarm/tests/test_hostdb.py
buildfarm/web/__init__.py

index 79c6ce70d87cb98fe9e938c503dbe4c11a7805ff..cc8edf9f4ac066f27e66df7d9d0790ca94bb8f48 100755 (executable)
--- a/admin.py
+++ b/admin.py
@@ -70,7 +70,7 @@ else:
 if op == "remove":
     hostname = raw_input("Please enter hostname to delete: ")
     try:
 if op == "remove":
     hostname = raw_input("Please enter hostname to delete: ")
     try:
-        db.deletehost(hostname.decode("utf-8"))
+        db.deletehost(hostname)
     except hostdb.NoSuchHost, e:
         print "No such host '%s'" % e.name
         sys.exit(1)
     except hostdb.NoSuchHost, e:
         print "No such host '%s'" % e.name
         sys.exit(1)
@@ -81,7 +81,7 @@ if op == "remove":
 elif op == "modify":
     hostname = raw_input("Please enter hostname to modify: ")
     try:
 elif op == "modify":
     hostname = raw_input("Please enter hostname to modify: ")
     try:
-        host = db.host(hostname.decode("utf-8"))
+        host = db.host(hostname)
     except hostdb.NoSuchHost, e:
         print "No such host '%s'" % e.name
         sys.exit(1)
     except hostdb.NoSuchHost, e:
         print "No such host '%s'" % e.name
         sys.exit(1)
@@ -108,7 +108,7 @@ elif op == "modify":
 elif op == "add":
     hostname = raw_input("Machine hostname: ")
     try:
 elif op == "add":
     hostname = raw_input("Machine hostname: ")
     try:
-        db.host(hostname.decode("utf-8"))
+        db.host(hostname)
     except hostdb.NoSuchHost, e:
         pass
     else:
     except hostdb.NoSuchHost, e:
         pass
     else:
@@ -129,7 +129,7 @@ elif op == "add":
         line = raw_input("")
 
     try:
         line = raw_input("")
 
     try:
-        db.createhost(hostname.decode("utf-8"), platform.decode("utf-8"),
+        db.createhost(hostname, platform.decode("utf-8"),
             owner.decode("utf-8"), owner_email.decode("utf-8"),
             password.decode("utf-8"),
             "".join(permission).decode("utf-8", "replace"))
             owner.decode("utf-8"), owner_email.decode("utf-8"),
             password.decode("utf-8"),
             "".join(permission).decode("utf-8", "replace"))
@@ -192,7 +192,7 @@ Thanks, your friendly Samba build farm administrator <build@samba.org>""" % owne
 elif op == "info":
     hostname = raw_input("Hostname: ")
     try:
 elif op == "info":
     hostname = raw_input("Hostname: ")
     try:
-        host = db.host(hostname.decode("utf-8"))
+        host = db.host(hostname)
     except hostdb.NoSuchHost, e:
         print "No such host '%s'" % e.name
         sys.exit(1)
     except hostdb.NoSuchHost, e:
         print "No such host '%s'" % e.name
         sys.exit(1)
index cac733e7357dd8522b818e4a3b0b78db2b352caa..25347cb52e93037c01b50bfd8e91dfa3091b2d9d 100644 (file)
@@ -47,13 +47,13 @@ class StormBuild(Build):
     __storm_table__ = "build"
 
     id = Int(primary=True)
     __storm_table__ = "build"
 
     id = Int(primary=True)
-    tree = Unicode()
+    tree = RawStr()
     revision = RawStr()
     revision = RawStr()
-    host = Unicode()
-    compiler = Unicode()
+    host = RawStr()
+    compiler = RawStr()
     checksum = RawStr()
     age = Int()
     checksum = RawStr()
     age = Int()
-    status_str = Unicode(name="status")
+    status_str = RawStr(name="status")
     commit_revision = RawStr()
 
     def status(self):
     commit_revision = RawStr()
 
     def status(self):
@@ -73,7 +73,7 @@ class StormBuild(Build):
 class StormHost(Host):
     __storm_table__ = "host"
 
 class StormHost(Host):
     __storm_table__ = "host"
 
-    name = Unicode(primary=True)
+    name = RawStr(primary=True)
     owner_name = Unicode(name="owner")
     owner_email = Unicode()
     password = Unicode()
     owner_name = Unicode(name="owner")
     owner_email = Unicode()
     password = Unicode()
@@ -111,7 +111,7 @@ class StormHostDatabase(HostDatabase):
     def createhost(self, name, platform=None, owner=None, owner_email=None,
             password=None, permission=None):
         """See `HostDatabase.createhost`."""
     def createhost(self, name, platform=None, owner=None, owner_email=None,
             password=None, permission=None):
         """See `HostDatabase.createhost`."""
-        newhost = StormHost(unicode(name), owner=owner, owner_email=owner_email, password=password, permission=permission, platform=platform)
+        newhost = StormHost(name, owner=owner, owner_email=owner_email, password=password, permission=permission, platform=platform)
         try:
             self.store.add(newhost)
             self.store.flush()
         try:
             self.store.add(newhost)
             self.store.flush()
@@ -153,18 +153,18 @@ class StormCachingBuildResultStore(BuildResultStore):
 
     def get_previous_revision(self, tree, host, compiler, revision):
         result = self.store.find(StormBuild,
 
     def get_previous_revision(self, tree, host, compiler, revision):
         result = self.store.find(StormBuild,
-            StormBuild.tree == unicode(tree),
-            StormBuild.host == unicode(host),
-            StormBuild.compiler == unicode(compiler),
+            StormBuild.tree == tree,
+            StormBuild.host == host,
+            StormBuild.compiler == compiler,
             StormBuild.commit_revision == revision)
         cur_build = result.any()
         if cur_build is None:
             raise NoSuchBuildError(tree, host, compiler, revision)
 
         result = self.store.find(StormBuild,
             StormBuild.commit_revision == revision)
         cur_build = result.any()
         if cur_build is None:
             raise NoSuchBuildError(tree, host, compiler, revision)
 
         result = self.store.find(StormBuild,
-            StormBuild.tree == unicode(tree),
-            StormBuild.host == unicode(host),
-            StormBuild.compiler == unicode(compiler),
+            StormBuild.tree == tree,
+            StormBuild.host == host,
+            StormBuild.compiler == compiler,
             StormBuild.commit_revision != revision,
             StormBuild.id < cur_build.id)
         result = result.order_by(Desc(StormBuild.id))
             StormBuild.commit_revision != revision,
             StormBuild.id < cur_build.id)
         result = result.order_by(Desc(StormBuild.id))
@@ -175,9 +175,9 @@ class StormCachingBuildResultStore(BuildResultStore):
 
     def get_latest_revision(self, tree, host, compiler):
         result = self.store.find(StormBuild,
 
     def get_latest_revision(self, tree, host, compiler):
         result = self.store.find(StormBuild,
-            StormBuild.tree == unicode(tree),
-            StormBuild.host == unicode(host),
-            StormBuild.compiler == unicode(compiler))
+            StormBuild.tree == tree,
+            StormBuild.host == host,
+            StormBuild.compiler == compiler)
         result = result.order_by(Desc(StormBuild.id))
         build = result.first()
         if build is None:
         result = result.order_by(Desc(StormBuild.id))
         build = result.first()
         if build is None:
@@ -200,11 +200,11 @@ class StormCachingBuildResultStore(BuildResultStore):
         rev, timestamp = build.revision_details()
         super(StormCachingBuildResultStore, self).upload_build(build)
         new_basename = self.build_fname(build.tree, build.host, build.compiler, rev)
         rev, timestamp = build.revision_details()
         super(StormCachingBuildResultStore, self).upload_build(build)
         new_basename = self.build_fname(build.tree, build.host, build.compiler, rev)
-        new_build = StormBuild(new_basename, unicode(build.tree), unicode(build.host),
-            unicode(build.compiler), rev)
+        new_build = StormBuild(new_basename, build.tree, build.host,
+            build.compiler, rev)
         new_build.checksum = build.log_checksum()
         new_build.age = build.age_mtime()
         new_build.checksum = build.log_checksum()
         new_build.age = build.age_mtime()
-        new_build.status_str = unicode(build.status().__serialize__())
+        new_build.status_str = build.status().__serialize__()
         self.store.add(new_build)
         return new_build
 
         self.store.add(new_build)
         return new_build
 
index f50c568ab9ce18ef829f680ba1db9b8a91656457..a6f544db1ea677a96d87e868f159d5b2d189bf39 100644 (file)
@@ -23,49 +23,49 @@ import testtools
 class HostTests(testtools.TestCase):
 
     def test_create_simple(self):
 class HostTests(testtools.TestCase):
 
     def test_create_simple(self):
-        host = hostdb.Host(name=u"foo")
+        host = hostdb.Host(name="foo")
         self.assertEquals(None, host.owner)
         self.assertEquals("foo", host.name)
 
     def test_create_with_owner(self):
         host = hostdb.Host(name="foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
         self.assertEquals((u"Jelmer", u"jelmer@samba.org"), host.owner)
         self.assertEquals(None, host.owner)
         self.assertEquals("foo", host.name)
 
     def test_create_with_owner(self):
         host = hostdb.Host(name="foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
         self.assertEquals((u"Jelmer", u"jelmer@samba.org"), host.owner)
-        self.assertEquals(u"foo", host.name)
+        self.assertEquals("foo", host.name)
 
 
 class HostDatabaseTests(object):
 
     def test_createhost(self):
 
 
 class HostDatabaseTests(object):
 
     def test_createhost(self):
-        self.db.createhost(u"charis", u"linux", u"Jelmer", u"jelmer@samba.org", u"bla", u"Pemrission?")
+        self.db.createhost("charis", u"linux", u"Jelmer", u"jelmer@samba.org", u"bla", u"Pemrission?")
         hosts = list(self.db.hosts())
         self.assertEquals(1, len(hosts))
         self.assertEquals("charis", hosts[0].name)
 
     def test_create_already_exists(self):
         hosts = list(self.db.hosts())
         self.assertEquals(1, len(hosts))
         self.assertEquals("charis", hosts[0].name)
 
     def test_create_already_exists(self):
-        host = self.db.createhost(name=u"foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
-        self.assertRaises(hostdb.HostAlreadyExists,  self.db.createhost, name=u"foo",
+        host = self.db.createhost(name="foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
+        self.assertRaises(hostdb.HostAlreadyExists,  self.db.createhost, name="foo",
             owner=u"Jelmer", owner_email=u"jelmer@samba.org")
 
     def test_delete(self):
             owner=u"Jelmer", owner_email=u"jelmer@samba.org")
 
     def test_delete(self):
-        host = self.db.createhost(name=u"foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
-        self.db.deletehost(u"foo")
+        host = self.db.createhost(name="foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
+        self.db.deletehost("foo")
 
     def test_delete_doesntexist(self):
 
     def test_delete_doesntexist(self):
-        self.assertRaises(hostdb.NoSuchHost, self.db.deletehost, u"foo")
+        self.assertRaises(hostdb.NoSuchHost, self.db.deletehost, "foo")
 
     def test_update_platform(self):
 
     def test_update_platform(self):
-        host = self.db.createhost(name=u"foo", owner=u"Jelmer",
+        host = self.db.createhost(name="foo", owner=u"Jelmer",
             owner_email=u"jelmer@samba.org")
         host.update_platform(u"Debian")
 
     def test_update_owner(self):
             owner_email=u"jelmer@samba.org")
         host.update_platform(u"Debian")
 
     def test_update_owner(self):
-        host = self.db.createhost(name=u"foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
+        host = self.db.createhost(name="foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org")
         host.update_owner(new_owner=u"Matthieu", new_owner_email=u"mat@samba.org")
 
     def test_create_hosts_list(self):
         host.update_owner(new_owner=u"Matthieu", new_owner_email=u"mat@samba.org")
 
     def test_create_hosts_list(self):
-        self.db.createhost(name=u"foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org",
+        self.db.createhost(name="foo", owner=u"Jelmer", owner_email=u"jelmer@samba.org",
             platform=u"Debian")
             platform=u"Debian")
-        self.db.createhost(name=u"bla", owner=u"Jelmer", owner_email=u"jelmer@samba.org",
+        self.db.createhost(name="bla", owner=u"Jelmer", owner_email=u"jelmer@samba.org",
             platform=u"Fedora")
         expected = [
             "foo: Debian\n",
             platform=u"Fedora")
         expected = [
             "foo: Debian\n",
@@ -76,8 +76,8 @@ class HostDatabaseTests(object):
         self.assertEquals(expected, got)
 
     def test_create_rsync_secrets(self):
         self.assertEquals(expected, got)
 
     def test_create_rsync_secrets(self):
-        self.db.createhost(name=u"foo")
-        self.db.createhost(name=u"bla", owner=u"Jelmer", owner_email=u"jelmer@samba.org",
+        self.db.createhost(name="foo")
+        self.db.createhost(name="bla", owner=u"Jelmer", owner_email=u"jelmer@samba.org",
             platform=u"Fedora", password=u"o")
         expected = [
             "# rsyncd.secrets file\n",
             platform=u"Fedora", password=u"o")
         expected = [
             "# rsyncd.secrets file\n",
index 2db0d0546237d8398a44a7a414def561edef0b56..6c2736f125fc624ba40406e18fe467719580b8c9 100755 (executable)
@@ -617,7 +617,7 @@ class ViewRecentBuildsPage(BuildFarmPage):
         for host in self.buildfarm.hostdb.hosts():
             for compiler in self.buildfarm.compilers:
                 try:
         for host in self.buildfarm.hostdb.hosts():
             for compiler in self.buildfarm.compilers:
                 try:
-                    build = self.buildfarm.get_build(tree, host.name.encode("utf-8"), compiler)
+                    build = self.buildfarm.get_build(tree, host.name, compiler)
                     status = build_status_html(myself, build)
                 except data.NoSuchBuildError:
                     pass
                     status = build_status_html(myself, build)
                 except data.NoSuchBuildError:
                     pass
@@ -633,9 +633,9 @@ class ViewRecentBuildsPage(BuildFarmPage):
                             age_ctime,
                             host.platform.encode("utf-8"),
                             "<a href='%s?function=View+Host;host=%s;tree=%s;compiler=%s#%s'>%s</a>"
                             age_ctime,
                             host.platform.encode("utf-8"),
                             "<a href='%s?function=View+Host;host=%s;tree=%s;compiler=%s#%s'>%s</a>"
-                                % (myself, host.name.encode("utf-8"),
-                                   tree, compiler, host.name.encode("utf-8"),
-                                   host.name.encode("utf-8")),
+                                % (myself, host.name,
+                                   tree, compiler, host.name,
+                                   host.name),
                             compiler, tree, status, build.status(),
                             revision_link(myself, revision, tree),
                             revision_time])
                             compiler, tree, status, build.status(),
                             revision_link(myself, revision, tree),
                             revision_time])
@@ -677,7 +677,7 @@ class ViewHostPage(BuildFarmPage):
     def _render_build_list_header(self, host):
         yield "<div class='host summary'>"
         yield "<a id='host' name='host'/>"
     def _render_build_list_header(self, host):
         yield "<div class='host summary'>"
         yield "<a id='host' name='host'/>"
-        yield "<h3>%s - %s</h3>" % (host.encode("utf-8"), self.buildfarm.hostdb.host(host).platform.encode("utf-8"))
+        yield "<h3>%s - %s</h3>" % (host, self.buildfarm.hostdb.host(host).platform.encode("utf-8"))
         yield "<table class='real'>"
         yield "<thead><tr><th>Target</th><th>Build<br/>Revision</th><th>Build<br />Age</th><th>Status<br />config/build<br />install/test</th><th>Warnings</th></tr></thead>"
         yield "<tbody>"
         yield "<table class='real'>"
         yield "<thead><tr><th>Target</th><th>Build<br/>Revision</th><th>Build<br />Age</th><th>Status<br />config/build<br />install/test</th><th>Warnings</th></tr></thead>"
         yield "<tbody>"
@@ -739,7 +739,7 @@ class ViewHostPage(BuildFarmPage):
                         "Tree", "Compiler", "Build Age", "Status", "Warnings")
                 for build in builds:
                     yield "%-12s %-10s %-10s %-10s %-10s\n" % (
                         "Tree", "Compiler", "Build Age", "Status", "Warnings")
                 for build in builds:
                     yield "%-12s %-10s %-10s %-10s %-10s\n" % (
-                            build.tree.encode("utf-8"), build.compiler.encode("utf-8"),
+                            build.tree, build.compiler,
                             util.dhm_time(build.age_mtime()),
                             str(build.status()), build.err_count())
                 yield "\n"
                             util.dhm_time(build.age_mtime()),
                             str(build.status()), build.err_count())
                 yield "\n"
@@ -911,7 +911,7 @@ class BuildFarmApp(object):
         self.buildfarm = buildfarm
 
         # host.properties are unicode object and the framework expect string object
         self.buildfarm = buildfarm
 
         # host.properties are unicode object and the framework expect string object
-        self.hosts = dict([(host.name.encode("utf-8"), host) for host in self.buildfarm.hostdb.hosts()])
+        self.hosts = dict([(host.name, host) for host in self.buildfarm.hostdb.hosts()])
 
     def main_menu(self):
         """main page"""
 
     def main_menu(self):
         """main page"""