Python code in webkit-perf.appspot.com uses camelCase
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2012 03:14:19 +0000 (03:14 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2012 03:14:19 +0000 (03:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77392

Reviewed by Adam Barth.

Use PEP8 style naming conventions instead of camelCase.

* Websites/webkit-perf.appspot.com/create_handler.py:
(CreateHandler.post):
(CreateHandler._create_builder):
(CreateHandler._create_branch):
(CreateHandler._create_platform):
* Websites/webkit-perf.appspot.com/dashboard_handler.py:
(DashboardHandler.get):
* Websites/webkit-perf.appspot.com/manifest_handler.py:
(ManifestHandler.get):
* Websites/webkit-perf.appspot.com/merge_tests_handler.py:
(MergeTestsHandler.post):
* Websites/webkit-perf.appspot.com/models.py:
(create_in_transaction_with_numeric_id_holder):
(delete_model_with_numeric_id_holder):
(modelFromNumericId):
(Builder.authenticate):
(Builder.hashed_password):
(Test.cache_key):
* Websites/webkit-perf.appspot.com/report_handler.py:
(ReportHandler.post):
(ReportHandler._model_by_key_name_in_body_or_error):
(ReportHandler._integer_in_body):
(ReportHandler._timestamp_in_body):
(ReportHandler.bypass_authentication):
(ReportHandler._results_are_valid):
(ReportHandler._results_are_valid._is_float_convertible):
(ReportHandler._create_build_if_possible):
(ReportHandler._create_build_if_possible.execute):
(ReportHandler._add_test_if_needed):
(ReportHandler._add_test_if_needed.execute):
(ReportHandler):
(AdminReportHandler.bypass_authentication):
* Websites/webkit-perf.appspot.com/runs_handler.py:
(RunsHandler.get):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106321 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Websites/webkit-perf.appspot.com/create_handler.py
Websites/webkit-perf.appspot.com/dashboard_handler.py
Websites/webkit-perf.appspot.com/manifest_handler.py
Websites/webkit-perf.appspot.com/merge_tests_handler.py
Websites/webkit-perf.appspot.com/models.py
Websites/webkit-perf.appspot.com/report_handler.py
Websites/webkit-perf.appspot.com/runs_handler.py

index dca82ed..a681b31 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,49 @@
 2012-01-30  Ryosuke Niwa  <rniwa@webkit.org>
 
+        Python code in webkit-perf.appspot.com uses camelCase
+        https://bugs.webkit.org/show_bug.cgi?id=77392
+
+        Reviewed by Adam Barth.
+
+        Use PEP8 style naming conventions instead of camelCase.
+
+        * Websites/webkit-perf.appspot.com/create_handler.py:
+        (CreateHandler.post):
+        (CreateHandler._create_builder):
+        (CreateHandler._create_branch):
+        (CreateHandler._create_platform):
+        * Websites/webkit-perf.appspot.com/dashboard_handler.py:
+        (DashboardHandler.get):
+        * Websites/webkit-perf.appspot.com/manifest_handler.py:
+        (ManifestHandler.get):
+        * Websites/webkit-perf.appspot.com/merge_tests_handler.py:
+        (MergeTestsHandler.post):
+        * Websites/webkit-perf.appspot.com/models.py:
+        (create_in_transaction_with_numeric_id_holder):
+        (delete_model_with_numeric_id_holder):
+        (modelFromNumericId):
+        (Builder.authenticate):
+        (Builder.hashed_password):
+        (Test.cache_key):
+        * Websites/webkit-perf.appspot.com/report_handler.py:
+        (ReportHandler.post):
+        (ReportHandler._model_by_key_name_in_body_or_error):
+        (ReportHandler._integer_in_body):
+        (ReportHandler._timestamp_in_body):
+        (ReportHandler.bypass_authentication):
+        (ReportHandler._results_are_valid):
+        (ReportHandler._results_are_valid._is_float_convertible):
+        (ReportHandler._create_build_if_possible):
+        (ReportHandler._create_build_if_possible.execute):
+        (ReportHandler._add_test_if_needed):
+        (ReportHandler._add_test_if_needed.execute):
+        (ReportHandler):
+        (AdminReportHandler.bypass_authentication):
+        * Websites/webkit-perf.appspot.com/runs_handler.py:
+        (RunsHandler.get):
+
+2012-01-30  Ryosuke Niwa  <rniwa@webkit.org>
+
         Enable memcache on webkit-perf.appspot.com
         https://bugs.webkit.org/show_bug.cgi?id=77378
 
index 98b6b69..70baaed 100644 (file)
@@ -37,7 +37,7 @@ from models import Builder
 from models import Branch
 from models import NumericIdHolder
 from models import Platform
-from models import createInTransactionWithNumericIdHolder
+from models import create_in_transaction_with_numeric_id_holder
 
 
 class CreateHandler(webapp2.RequestHandler):
@@ -54,11 +54,11 @@ class CreateHandler(webapp2.RequestHandler):
             return
 
         if model == 'builder':
-            error = self._createBuilder(name, password)
+            error = self._create_builder(name, password)
         elif model == 'branch':
-            error = self._createBranch(key, name)
+            error = self._create_branch(key, name)
         elif model == 'platform':
-            error = self._createPlatform(key, name)
+            error = self._create_platform(key, name)
         else:
             error = "Unknown model type: %s\n" % model
 
@@ -66,11 +66,11 @@ class CreateHandler(webapp2.RequestHandler):
         memcache.delete('dashboard')
         self.response.out.write(error + '\n' if error else 'OK')
 
-    def _createBuilder(self, name, password):
+    def _create_builder(self, name, password):
         if not name or not password:
             return 'Invalid name or password'
 
-        password = Builder.hashedPassword(password)
+        password = Builder.hashed_password(password)
 
         def execute():
             message = None
@@ -85,7 +85,7 @@ class CreateHandler(webapp2.RequestHandler):
 
         return db.run_in_transaction(execute)
 
-    def _createBranch(self, key, name):
+    def _create_branch(self, key, name):
         if not key or not name:
             return 'Invalid key or name'
 
@@ -99,10 +99,10 @@ class CreateHandler(webapp2.RequestHandler):
             branch.put()
             return branch
 
-        createInTransactionWithNumericIdHolder(execute)
+        create_in_transaction_with_numeric_id_holder(execute)
         return error[0]
 
-    def _createPlatform(self, key, name):
+    def _create_platform(self, key, name):
         if not key or not name:
             return 'Invalid key name'
 
@@ -116,5 +116,5 @@ class CreateHandler(webapp2.RequestHandler):
             platform.put()
             return platform
 
-        createInTransactionWithNumericIdHolder(execute)
+        create_in_transaction_with_numeric_id_holder(execute)
         return error[0]
index c6356c7..9778fbe 100644 (file)
@@ -41,18 +41,17 @@ from models import Test
 class DashboardHandler(webapp2.RequestHandler):
     def get(self):
         self.response.headers['Content-Type'] = 'application/json; charset=utf-8';
-
         cache = memcache.get('dashboard')
         if cache:
             self.response.out.write(cache)
             return
 
-        webkitTrunk = Branch.get_by_key_name('webkit-trunk')
+        webkit_trunk = Branch.get_by_key_name('webkit-trunk')
 
         # FIXME: Determine popular branches, platforms, and tests
         dashboard = {
             'defaultBranch': 'WebKit trunk',
-            'branchToId': {webkitTrunk.name: webkitTrunk.id},
+            'branchToId': {webkit_trunk.name: webkit_trunk.id},
             'platformToId': {},
             'testToId': {},
         }
index 7f76a29..12ce50a 100644 (file)
@@ -46,48 +46,48 @@ class ManifestHandler(webapp2.RequestHandler):
             self.response.out.write(cache)
             return
 
-        testMap = {}
-        platformIdMap = {}
-        branchIdMap = {}
+        test_map = {}
+        platform_id_map = {}
+        branch_id_map = {}
         for test in Test.all():
-            branchIds = [Branch.get(branchKey).id for branchKey in test.branches]
-            platformIds = [Platform.get(platformKey).id for platformKey in test.platforms]
-            testMap[test.id] = {
+            branch_ids = [Branch.get(branch_key).id for branch_key in test.branches]
+            platform_ids = [Platform.get(platform_key).id for platform_key in test.platforms]
+            test_map[test.id] = {
                 'name': test.name,
-                'branchIds': branchIds,
-                'platformIds': platformIds,
+                'branchIds': branch_ids,
+                'platformIds': platform_ids,
             }
 
-            for platformId in platformIds:
-                platformIdMap.setdefault(platformId, {'tests': [], 'branches': []})
-                platformIdMap[platformId]['tests'].append(test.id)
-                platformIdMap[platformId]['branches'] += branchIds
+            for platform_id in platform_ids:
+                platform_id_map.setdefault(platformId, {'tests': [], 'branches': []})
+                platform_id_map[platform_id]['tests'].append(test.id)
+                platform_id_map[platform_id]['branches'] += branch_ids
 
-            for branchId in branchIds:
-                branchIdMap.setdefault(branchId, {'tests': [], 'platforms': []})
-                branchIdMap[branchId]['tests'].append(test.id)
-                branchIdMap[branchId]['platforms'] += platformIds
+            for branch_id in branch_ids:
+                branch_id_map.setdefault(branchId, {'tests': [], 'platforms': []})
+                branch_id_map[branch_id]['tests'].append(test.id)
+                branch_id_map[branch_id]['platforms'] += platform_ids
 
-        platformMap = {}
+        platform_map = {}
         for platform in Platform.all():
-            if platform.id not in platformIdMap:
+            if platform.id not in platform_id_map:
                 continue
-            platformMap[platform.id] = {
+            platform_map[platform.id] = {
                 'name': platform.name,
-                'testIds': list(set(platformIdMap[platform.id]['tests'])),
-                'branchIds': list(set(platformIdMap[platform.id]['branches'])),
+                'testIds': list(set(platform_id_map[platform.id]['tests'])),
+                'branchIds': list(set(platform_id_map[platform.id]['branches'])),
             }
 
-        branchMap = {}
+        branch_map = {}
         for branch in Branch.all():
-            if branch.id not in branchIdMap:
+            if branch.id not in branch_id_map:
                 continue
-            branchMap[branch.id] = {
+            branch_map[branch.id] = {
                 'name': branch.name,
-                'testIds': list(set(branchIdMap[branch.id]['tests'])),
-                'platformIds': list(set(branchIdMap[branch.id]['platforms'])),
+                'testIds': list(set(branch_id_map[branch.id]['tests'])),
+                'platformIds': list(set(branch_id_map[branch.id]['platforms'])),
             }
 
-        result = json.dumps({'testMap': testMap, 'platformMap': platformMap, 'branchMap': branchMap})
+        result = json.dumps({'testMap': test_map, 'platformMap': platform_map, 'branchMap': branch_map})
         self.response.out.write(result)
         memcache.add('manifest', result)
index 5fb8bba..8160574 100644 (file)
@@ -35,7 +35,7 @@ import os
 
 from models import Test
 from models import TestResult
-from models import deleteModelWithNumericIdHolder
+from models import delete_model_with_numeric_id_holder
 
 
 class MergeTestsHandler(webapp2.RequestHandler):
@@ -51,9 +51,9 @@ class MergeTestsHandler(webapp2.RequestHandler):
             self.response.out.write('Invalid test names')
             return
 
-        mergedResults = TestResult.all()
-        mergedResults.filter('name =', merge.name)
-        for result in mergedResults:
+        merged_results = TestResult.all()
+        merged_results.filter('name =', merge.name)
+        for result in merged_results:
             result.name = into.name
             result.put()
 
@@ -61,6 +61,6 @@ class MergeTestsHandler(webapp2.RequestHandler):
         # dashboard, manifest, and all runs for this test here.
         memcache.flush_all()
 
-        deleteModelWithNumericIdHolder(merge)
+        delete_model_with_numeric_id_holder(merge)
 
         self.response.out.write('OK')
index cf90ff2..26b4f03 100644 (file)
@@ -38,27 +38,28 @@ class NumericIdHolder(db.Model):
     # Dummy class whose sole purpose is to generate key().id()
 
 
-def createInTransactionWithNumericIdHolder(callback):
-    idHolder = NumericIdHolder()
-    idHolder.put()
-    idHolder = NumericIdHolder.get(idHolder.key())
-    owner = db.run_in_transaction(callback, idHolder.key().id())
+def create_in_transaction_with_numeric_id_holder(callback):
+    id_holder = NumericIdHolder()
+    id_holder.put()
+    id_holder = NumericIdHolder.get(id_holder.key())
+    owner = db.run_in_transaction(callback, id_holder.key().id())
     if owner:
-        idHolder.owner = owner
-        idHolder.put()
+        id_holder.owner = owner
+        id_holder.put()
     else:
-        idHolder.delete()
+        id_holder.delete()
     return owner
 
-def deleteModelWithNumericIdHolder(model):
-    idHolder = NumericIdHolder.get_by_id(model.id)
+
+def delete_model_with_numeric_id_holder(model):
+    id_holder = NumericIdHolder.get_by_id(model.id)
     model.delete()
-    idHolder.delete()
+    id_holder.delete()
 
 
-def modelFromNumericId(id, expectedKind):
-    idHolder = NumericIdHolder.get_by_id(id)
-    return idHolder.owner if idHolder and idHolder.owner and isinstance(idHolder.owner, expectedKind) else None
+def modelFromNumericId(id, expected_kind):
+    id_holder = NumericIdHolder.get_by_id(id)
+    return id_holder.owner if id_holder and id_holder.owner and isinstance(id_holder.owner, expected_kind) else None
 
 
 class Branch(db.Model):
@@ -75,12 +76,12 @@ class Builder(db.Model):
     name = db.StringProperty(required=True)
     password = db.StringProperty(required=True)
 
-    def authenticate(self, rawPassword):
-        return self.password == hashlib.sha256(rawPassword).hexdigest()
+    def authenticate(self, raw_password):
+        return self.password == hashlib.sha256(raw_password).hexdigest()
 
     @staticmethod
-    def hashedPassword(rawPassword):
-        return hashlib.sha256(rawPassword).hexdigest()
+    def hashed_password(raw_password):
+        return hashlib.sha256(raw_password).hexdigest()
 
 
 class Build(db.Model):
@@ -100,8 +101,8 @@ class Test(db.Model):
     platforms = db.ListProperty(db.Key)
 
     @staticmethod
-    def cacheKey(testId, branchId, platformId):
-        return 'runs:%d,%d,%d' % (testId, branchId, platformId)
+    def cache_key(test_id, branch_id, platform_id):
+        return 'runs:%d,%d,%d' % (test_id, branch_id, platform_id)
 
 
 class TestResult(db.Model):
index a7277e2..5deb9b8 100644 (file)
@@ -44,7 +44,7 @@ from models import Platform
 from models import ReportLog
 from models import Test
 from models import TestResult
-from models import createInTransactionWithNumericIdHolder
+from models import create_in_transaction_with_numeric_id_holder
 
 
 class ReportHandler(webapp2.RequestHandler):
@@ -63,37 +63,37 @@ class ReportHandler(webapp2.RequestHandler):
         except ValueError:
             return self._output('Failed to parse the payload as a json. Report key: %d' % log.key().id())
 
-        builder = self._modelByKeyNameInBodyOrError(Builder, 'builder-name')
-        branch = self._modelByKeyNameInBodyOrError(Branch, 'branch')
-        platform = self._modelByKeyNameInBodyOrError(Platform, 'platform')
-        buildNumber = self._integerInBody('build-number')
-        revision = self._integerInBody('revision')
-        timestamp = self._timestampInBody()
+        builder = self._model_by_key_name_in_body_or_error(Builder, 'builder-name')
+        branch = self._model_by_key_name_in_body_or_error(Branch, 'branch')
+        platform = self._model_by_key_name_in_body_or_error(Platform, 'platform')
+        build_number = self._integer_in_body('build-number')
+        revision = self._integer_in_body('revision')
+        timestamp = self._timestamp_in_body()
 
         failed = False
-        if builder and not (self.bypassAuthentication() or builder.authenticate(self._body.get('password', ''))):
+        if builder and not (self.bypass_authentication() or builder.authenticate(self._body.get('password', ''))):
             self._output('Authentication failed')
             failed = True
 
-        if not self._resultsAreValid():
+        if not self._results_are_valid():
             self._output("The payload doesn't contain results or results are malformed")
             failed = True
 
-        if not (builder and branch and platform and buildNumber and revision and timestamp) or failed:
+        if not (builder and branch and platform and build_number and revision and timestamp) or failed:
             return
 
-        build = self._createBuildIfPossible(builder, buildNumber, branch, platform, revision, timestamp)
+        build = self._create_build_if_possible(builder, build_number, branch, platform, revision, timestamp)
         if not build:
             return
 
-        for testName, result in self._body['results'].iteritems():
-            test = self._addTestIfNeeded(testName, branch, platform)
-            memcache.delete(Test.cacheKey(test.id, branch.id, platform.id))
+        for test_name, result in self._body['results'].iteritems():
+            test = self._add_test_if_needed(test_name, branch, platform)
+            memcache.delete(Test.cache_key(test.id, branch.id, platform.id))
             if isinstance(result, dict):
-                TestResult(name=testName, build=build, value=float(result.get('avg', 0)), valueMedian=float(result.get('median', 0)),
+                TestResult(name=test_name, build=build, value=float(result.get('avg', 0)), valueMedian=float(result.get('median', 0)),
                     valueStdev=float(result.get('stdev', 0)), valueMin=float(result.get('min', 0)), valueMax=float(result.get('max', 0))).put()
             else:
-                TestResult(name=testName, build=build, value=float(result)).put()
+                TestResult(name=test_name, build=build, value=float(result)).put()
 
         log = ReportLog.get(log.key())
         log.delete()
@@ -104,21 +104,21 @@ class ReportHandler(webapp2.RequestHandler):
 
         return self._output('OK')
 
-    def _modelByKeyNameInBodyOrError(self, model, keyName):
+    def _model_by_key_name_in_body_or_error(self, model, keyName):
         key = self._body.get(keyName, '')
         instance = key and model.get_by_key_name(key)
         if not instance:
             self._output('There are no %s named "%s"' % (model.__name__.lower(), key))
         return instance
 
-    def _integerInBody(self, key):
+    def _integer_in_body(self, key):
         value = self._body.get(key, '')
         try:
             return int(value)
         except:
             return self._output('Invalid %s: "%s"' % (key.replace('-', ' '), value))
 
-    def _timestampInBody(self):
+    def _timestamp_in_body(self):
         value = self._body.get('timestamp', '')
         try:
             return datetime.fromtimestamp(int(value))
@@ -128,12 +128,12 @@ class ReportHandler(webapp2.RequestHandler):
     def _output(self, message):
         self.response.out.write(message + '\n')
 
-    def bypassAuthentication(self):
+    def bypass_authentication(self):
         return False
 
-    def _resultsAreValid(self):
+    def _results_are_valid(self):
 
-        def _isFloatConvertible(value):
+        def _is_float_convertible(value):
             try:
                 float(value)
                 return True
@@ -146,17 +146,17 @@ class ReportHandler(webapp2.RequestHandler):
         for testResult in self._body['results'].values():
             if isinstance(testResult, dict):
                 for value in testResult.values():
-                    if not _isFloatConvertible(value):
+                    if not _is_float_convertible(value):
                         return False
                 if 'avg' not in testResult:
                     return False
                 continue
-            if not _isFloatConvertible(testResult):
+            if not _is_float_convertible(testResult):
                 return False
 
         return True
 
-    def _createBuildIfPossible(self, builder, buildNumber, branch, platform, revision, timestamp):
+    def _create_build_if_possible(self, builder, build_number, branch, platform, revision, timestamp):
         key_name = builder.name + ':' + str(int(time.mktime(timestamp.timetuple())))
 
         def execute():
@@ -164,17 +164,17 @@ class ReportHandler(webapp2.RequestHandler):
             if build:
                 return self._output('The build at %s already exists for %s' % (str(timestamp), builder.name))
 
-            return Build(branch=branch, platform=platform, builder=builder, buildNumber=buildNumber,
-                timestamp=timestamp, revision=revision, key_name=key_name).put()
+            return Build(branch=branch, platform=platform, builder=builder, buildNumber=build_number,
+                timestamp=timestamp, revision=revision, keyName=key_name).put()
         return db.run_in_transaction(execute)
 
-    def _addTestIfNeeded(self, testName, branch, platform):
+    def _add_test_if_needed(self, test_name, branch, platform):
 
         def execute(id):
-            test = Test.get_by_key_name(testName)
+            test = Test.get_by_key_name(test_name)
             returnValue = None
             if not test:
-                test = Test(id=id, name=testName, key_name=testName)
+                test = Test(id=id, name=test_name, key_name=test_name)
                 returnValue = test
             if branch.key() not in test.branches:
                 test.branches.append(branch.key())
@@ -182,9 +182,9 @@ class ReportHandler(webapp2.RequestHandler):
                 test.platforms.append(platform.key())
             test.put()
             return returnValue
-        return createInTransactionWithNumericIdHolder(execute) or Test.get_by_key_name(testName)
+        return create_in_transaction_with_numeric_id_holder(execute) or Test.get_by_key_name(test_name)
 
 
 class AdminReportHandler(ReportHandler):
-    def bypassAuthentication(self):
+    def bypass_authentication(self):
         return True
index d3bc64a..c73ec42 100644 (file)
@@ -49,30 +49,30 @@ class RunsHandler(webapp2.RequestHandler):
         self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
 
         try:
-            testId = int(self.request.get('id', 0))
-            branchId = int(self.request.get('branchid', 0))
-            platformId = int(self.request.get('platformid', 0))
+            test_id = int(self.request.get('id', 0))
+            branch_id = int(self.request.get('branchid', 0))
+            platform_id = int(self.request.get('platformid', 0))
         except TypeError:
             # FIXME: Output an error here
-            testId = 0
-            branchId = 0
-            platformId = 0
+            test_id = 0
+            branch_id = 0
+            platform_id = 0
 
         # FIXME: Just fetch builds specified by "days"
         # days = self.request.get('days', 365)
 
-        cacheKey = Test.cacheKey(testId, branchId, platformId)
-        cache = memcache.get(cacheKey)
+        cache_key = Test.cache_key(test_id, branch_id, platform_id)
+        cache = memcache.get(cache_key)
         if cache:
             self.response.out.write(cache)
             return
 
         builds = Build.all()
-        builds.filter('branch =', modelFromNumericId(branchId, Branch))
-        builds.filter('platform =', modelFromNumericId(platformId, Platform))
+        builds.filter('branch =', modelFromNumericId(branch_id, Branch))
+        builds.filter('platform =', modelFromNumericId(platform_id, Platform))
 
-        test = modelFromNumericId(testId, Test)
-        testName = test.name if test else None
+        test = modelFromNumericId(test_id, Test)
+        test_name = test.name if test else None
         test_runs = []
         averages = {}
         values = []
@@ -80,7 +80,7 @@ class RunsHandler(webapp2.RequestHandler):
 
         for build in builds:
             results = TestResult.all()
-            results.filter('name =', testName)
+            results.filter('name =', test_name)
             results.filter('build =', build)
             for result in results:
                 builderId = build.builder.key().id()
@@ -101,4 +101,4 @@ class RunsHandler(webapp2.RequestHandler):
             'date_range': [min(timestamps), max(timestamps)] if timestamps else None,
             'stat': 'ok'})
         self.response.out.write(result)
-        memcache.add(cacheKey, result)
+        memcache.add(cache_key, result)