Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/rietveld_utility.py |
| =================================================================== |
| --- chrome/common/extensions/docs/server2/rietveld_utility.py (revision 0) |
| +++ chrome/common/extensions/docs/server2/rietveld_utility.py (revision 0) |
| @@ -0,0 +1,110 @@ |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| + |
| +import svn_constants |
| +from appengine_wrappers import GetAppVersion |
| +from object_store_creator import ObjectStoreCreator |
| + |
| +PATCH_BASEURL = '_patch/' |
| +PATCH_CHANNEL_NAME = 'trunk' |
| +CHROMIUM_REPO_BASEURLS = [ |
| + 'https://src.chromium.org/svn/trunk/src/', |
| + 'http://src.chromium.org/svn/trunk/src/', |
| + 'svn://svn.chromium.org/chrome/trunk/src', |
| + 'https://chromium.googlesource.com/chromium/src.git@master', |
| + 'http://git.chromium.org/chromium/src.git@master', |
| +] |
| +DOCS_PATHS = [ |
| + svn_constants.API_PATH, |
| + svn_constants.INTRO_PATH, |
| + svn_constants.ARTICLE_PATH, |
| + svn_constants.PUBLIC_TEMPLATE_PATH, |
| + svn_constants.PRIVATE_TEMPLATE_PATH, |
| + svn_constants.JSON_PATH, |
| + svn_constants.STATIC_PATH |
| +] |
| +RIETVELD_ISSUE_JSON = 'api/%s' |
| +RIETVELD_PATCHSET_JSON = 'api/%s/%s' |
| + |
| +class RietveldUtility(object): |
|
not at google - send to devlin
2013/04/26 23:53:53
I think much of this class will transform nicely i
|
| + def __init__(self, fetcher, object_store=None): |
| + self._fetcher = fetcher |
| + if object_store is None: |
| + object_store = (ObjectStoreCreator.SharedFactory(GetAppVersion()). |
| + Create(RietveldUtility).Create()) |
| + self._object_store = object_store |
| + |
| + def GetPatchsetFromIssue(self, issue): |
| + patchset = self._object_store.Get(issue).Get() |
| + if patchset is not None: |
| + return patchset |
| + |
| + try: |
| + issue_json = json.loads(self._fetcher.Fetch( |
| + RIETVELD_ISSUE_JSON % issue).content) |
| + except Exception as e: |
| + return None |
| + |
| + if issue_json.get('closed'): |
| + return None |
| + |
| + patchsets = issue_json.get('patchsets') |
| + if not isinstance(patchsets, list) or len(patchsets) == 0: |
| + return None |
| + |
| + if not issue_json.get('base_url') in CHROMIUM_REPO_BASEURLS: |
| + return None |
| + |
| + patchset = patchsets[-1] |
| + self._object_store.Set(issue, patchset) |
| + return patchset |
| + |
| + # (docs_files, changes) |
| + def GetPatchsetDetails(self, issue, patchset): |
| + key = '%s@%s' % (issue, patchset) |
| + details = self._object_store.Get(key).Get() |
| + if details is not None: |
| + return details |
| + |
| + try: |
| + patchset_json = json.loads(self._fetcher.Fetch( |
| + RIETVELD_PATCHSET_JSON % (issue, patchset)).content) |
| + except Exception as e: |
| + return ([], {}) |
| + |
| + files = patchset_json.get('files') |
| + if files is None or not isinstance(files, dict): |
| + return ([], {}) |
| + |
| + docs_files = [] |
| + changes = {} |
| + for f in files: |
| + f = f.split(svn_constants.EXTENSIONS_PATH + '/', 1)[1] |
| + if (f.startswith(svn_constants.DOCS_PATH) or |
| + f.startswith(svn_constants.API_PATH)): |
| + docs_files.append(f) |
| + for p in DOCS_PATHS: |
| + if not changes.get(p) and f.startswith(p): |
| + changes[p] = True |
| + if len(docs_files) == 0: |
| + return ([], {}) |
| + |
| + details = (docs_files, changes) |
| + self._object_store.Set(key, details) |
| + return details |
| + |
| + @staticmethod |
| + def SplitPatchFromPath(path): |
| + if path.startswith(PATCH_BASEURL): |
| + remaining_path = path.split(PATCH_BASEURL, 1)[1] |
| + if not '/' in remaining_path: |
| + return (None, None, None) |
| + issue, real_path = remaining_path.split('/', 1) |
| + if not issue.isdigit() or len(real_path) == 0: |
| + return (None, None, None) |
| + return (PATCH_CHANNEL_NAME, issue, real_path) |
| + else: |
| + return (None, None, None) |
| Property changes on: chrome/common/extensions/docs/server2/rietveld_utility.py |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |