Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6355)

Unified Diff: chrome/common/extensions/docs/server2/chrome_version_utility.py

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing up Offline/Online Access - Attempting to rework availability algorithm Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/chrome_version_utility.py
diff --git a/chrome/common/extensions/docs/server2/chrome_version_utility.py b/chrome/common/extensions/docs/server2/chrome_version_utility.py
new file mode 100644
index 0000000000000000000000000000000000000000..fc672cf609d698e6a6d56536a67edf1bef57bab4
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/chrome_version_utility.py
@@ -0,0 +1,51 @@
+# Copyright (c) 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 logging
+import os
+
+class ChromeVersionUtility(object):
+ '''Generates and stores API data sources corresponding to the latest branch
+ number for a given version of Chrome.
+
+ Accesses data found on omahaproxy in order to link branch numbers to version
+ numbers.
+ '''
+
+ def __init__(self, base_path, fetcher, object_store_creator):
+ self._base_path = base_path
+ self._fetcher = fetcher
+ self._object_store = object_store_creator.Create(ChromeVersionUtility,
+ channel=None)
+
+ def GetBranchNumberForVersion(self, version):
+ '''Returns the most recent branch number for a given chrome version number
+ using data stored on omahaproxy (see url_constants)
+ '''
+ if version == 'trunk':
+ return 'trunk'
+
+ branch = self._object_store.Get(str(version)).Get()
+ if branch is not None:
+ return branch
+ version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
+ for entry in version_json['events']:
+ # Here, entry['title'] looks like: 'title - version#.#.branch#.#'
+ version_title = entry['title'].split(' - ')[1].split('.')
+ if version_title[0] == str(version):
+ self._object_store.Set(str(version), version_title[2])
+ return int(version_title[2])
+ raise ValueError(
+ 'A branch number for the given version could not be determined')
+
+ def GetLatestVersionNumber(self):
+ version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
+ latest_version = 0
+ for entry in version_json['events']:
+ version_title = entry['title'].split(' - ')[1].split('.')
+ version = int(version_title[0])
+ if version > latest_version:
+ latest_version = version
+ return latest_version

Powered by Google App Engine
This is Rietveld 408576698