diff --git a/Post/management/commands/culldb.py b/Post/management/commands/culldb.py
index bd70ffc..46c586d 100644
--- a/Post/management/commands/culldb.py
+++ b/Post/management/commands/culldb.py
@@ -9,44 +9,38 @@
 # Create your views here.
 # vi: tabstop=8 expandtab shiftwidth=4 softtabstop=4
 
-from django.core.management.base import BaseCommand, CommandError
-from Post.models import Build, BuildFailure
-from optparse import make_option
+from django.core.management.base import BaseCommand
+from Post.models import Build
 import time
 import sys
 
 class Command(BaseCommand):
     help = 'Culls the database to size in rows'
-    args = '<size>'
-    option_list = BaseCommand.option_list + (
-        make_option('-i',
-                    '--info',
-                    dest='info',
-                    action="store_true",
-                    help='Show the current database size'),
-    )
+
+    def add_arguments(self, parser):
+        parser.add_argument('size', nargs='?', type=int,
+                            help='Number of builds to keep')
+        parser.add_argument('-i',
+                            '--info',
+                            action="store_true",
+                            help='Show the current database size')
 
     def handle(self, *args, **options):
         count = Build.objects.count()
 
         if options['info']:
-            print "Current builds table size: %d" % Build.objects.count()
+            print("Current builds table size: %d" % Build.objects.count())
             return
 
-        if len(args) > 0 and args[0]:
-            try:
-                new_size = int(args[0])
-            except ValueError:
-                print "Not a valid size"
-                return
-
+        if options['size'] is not None:
+            new_size = options['size']
 
             num_to_delete = count - new_size
-            print "\nReducing the database size to %d which will DELETE %d rows" % (new_size, num_to_delete)
+            print("\nReducing the database size to %d which will DELETE %d rows" % (new_size, num_to_delete))
             i = 1
             while i != 0:
                 i = i-1
-                print 'Ctrl+c TO CANCEL. Executing in... %d \r' % i,
+                print('Ctrl+c TO CANCEL. Executing in... %d \r' % i, end='')
                 sys.stdout.flush()
                 time.sleep(1)
 
diff --git a/Post/purge.py b/Post/purge.py
index dd58441..f4989fb 100644
--- a/Post/purge.py
+++ b/Post/purge.py
@@ -20,7 +20,7 @@ def main():
     #print query
     items = BuildFailure.objects.raw(query)
     for item in items:
-        print "Deleting: ", item.id
+        print("Deleting: ", item.id)
         item.delete()
 
 if __name__ == "__main__":
diff --git a/Post/test.py b/Post/test.py
index 734b99c..9527a9f 100755
--- a/Post/test.py
+++ b/Post/test.py
@@ -1,5 +1,7 @@
 import urllib.request, urllib.parse, urllib.error
 import json
+from unittest.mock import patch
+from django.core.management import call_command
 import re
 from django.test import Client, TestCase, override_settings
 from Post.models import BuildFailure, Build
@@ -385,3 +387,22 @@ class LinkBackSubmissionTest(TestCase):
         bf = self._submit("http://example.com/build/42")
         self.assertEqual(bf.BUILD.LINK_BACK, "http://example.com/build/42")
 
+
+
+@patch("Post.management.commands.culldb.time.sleep")
+class CullDbTest(TestCase):
+    def setUp(self):
+        for _ in range(3):
+            Build.objects.create()
+
+    def test_culls_to_size(self, _sleep):
+        call_command("culldb", "1")
+        self.assertEqual(Build.objects.count(), 1)
+
+    def test_zero_culls_everything(self, _sleep):
+        call_command("culldb", "0")
+        self.assertEqual(Build.objects.count(), 0)
+
+    def test_info_deletes_nothing(self, _sleep):
+        call_command("culldb", "--info")
+        self.assertEqual(Build.objects.count(), 3)
