Commit eb5b81b5 authored by kalman@chromium.org's avatar kalman@chromium.org

Docserver: Update app version parsing since AppEngine started including '/'

separators.

R=rockot@chromium.org

Review URL: https://codereview.chromium.org/297963004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272653 0039d316-1c4b-4281-b951-d872f2087c98
parent 023a90ac
application: chrome-apps-doc
version: 3-22-1
version: 3-23-1
runtime: python27
api_version: 1
threadsafe: false
......
......@@ -5,7 +5,8 @@
import base64
import posixpath
from appengine_wrappers import GetAppVersion, urlfetch
from appengine_wrappers import urlfetch
from environment import GetAppVersion
from future import Future
......
......@@ -2,19 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
from app_yaml_helper import AppYamlHelper
def GetAppVersion():
if 'CURRENT_VERSION_ID' in os.environ:
# The version ID looks like 2-0-25.36712548, we only want the 2-0-25.
return os.environ['CURRENT_VERSION_ID'].split('.', 1)[0]
# Not running on appengine, get it from the app.yaml file ourselves.
app_yaml_path = os.path.join(os.path.split(__file__)[0], 'app.yaml')
with open(app_yaml_path, 'r') as app_yaml:
return AppYamlHelper.ExtractVersion(app_yaml.read())
def IsDeadlineExceededError(error):
'''A general way of determining whether |error| is a DeadlineExceededError,
since there are 3 different types thrown by AppEngine and we might as well
......@@ -23,9 +10,11 @@ def IsDeadlineExceededError(error):
'''
return type(error).__name__ == 'DeadlineExceededError'
def IsDownloadError(error):
return type(error).__name__ == 'DownloadError'
# This will attempt to import the actual App Engine modules, and if it fails,
# they will be replaced with fake modules. This is useful during testing.
try:
......
......@@ -6,9 +6,9 @@
import functools
import os
from appengine_wrappers import GetAppVersion
from compiled_file_system import CompiledFileSystem
from copy import deepcopy
from environment import GetAppVersion
from file_system import FileNotFoundError
from mock_file_system import MockFileSystem
from object_store_creator import ObjectStoreCreator
......
......@@ -2,4 +2,4 @@ cron:
- description: Repopulates all cached data.
url: /_cron
schedule: every 5 minutes
target: 3-22-1
target: 3-23-1
......@@ -7,12 +7,11 @@ import posixpath
import traceback
from app_yaml_helper import AppYamlHelper
from appengine_wrappers import (
GetAppVersion, IsDeadlineExceededError, logservice)
from appengine_wrappers import IsDeadlineExceededError, logservice
from branch_utility import BranchUtility
from compiled_file_system import CompiledFileSystem
from data_source_registry import CreateDataSources
from environment import IsDevServer
from environment import GetAppVersion, IsDevServer
from extensions_paths import EXAMPLES, PUBLIC_TEMPLATES, STATIC_DOCS
from file_system_util import CreateURLsFromPaths
from future import Future
......
......@@ -5,11 +5,11 @@
import unittest
from appengine_wrappers import GetAppVersion
from app_yaml_helper import AppYamlHelper
from content_providers import IgnoreMissingContentProviders
from cron_servlet import CronServlet
from empty_dir_file_system import EmptyDirFileSystem
from environment import GetAppVersion
from extensions_paths import (
APP_YAML, CONTENT_PROVIDERS, CHROME_EXTENSIONS, PUBLIC_TEMPLATES, SERVER2,
STATIC_DOCS)
......
......@@ -2,9 +2,30 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import re
import os
import sys
from app_yaml_helper import AppYamlHelper
from third_party.json_schema_compiler.memoize import memoize
@memoize
def GetAppVersion():
return GetAppVersionNonMemoized()
# This one is for running from tests, which memoization messes up.
def GetAppVersionNonMemoized():
if 'CURRENT_VERSION_ID' in os.environ:
# The version ID looks like 2-0-25.36712548 or 2-0-25.23/223; we only
# want the 2-0-25.
return re.compile('[./]').split(os.environ['CURRENT_VERSION_ID'])[0]
# Not running on appengine, get it from the app.yaml file ourselves.
app_yaml_path = os.path.join(os.path.split(__file__)[0], 'app.yaml')
with open(app_yaml_path, 'r') as app_yaml:
return AppYamlHelper.ExtractVersion(app_yaml.read())
def _IsServerSoftware(name):
return os.environ.get('SERVER_SOFTWARE', '').find(name) == 0
......
#!/usr/bin/env python
# Copyright 2014 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 os
import unittest
from environment import GetAppVersionNonMemoized
class EnvironmentTest(unittest.TestCase):
def testGetAppVersion(self):
# GetAppVersion uses 2 heuristics: the CURRENT_VERSION_ID environment
# variable that AppEngine sets, or the version extracted from app.yaml
# if no such variable exists (e.g. preview.py). The latter, we assume,
# is already tested because AppYamlHelper.ExtractVersion is already
# tested. So, for this test, we fake a CURRENT_VERSION_ID.
def test_single(expected, current_version_id):
key = 'CURRENT_VERSION_ID'
old_value = os.environ.get(key)
os.environ[key] = current_version_id
try:
self.assertEqual(expected, GetAppVersionNonMemoized())
finally:
if old_value is None:
del os.environ[key]
else:
os.environ[key] = old_value
def test_all(expected):
test_single(expected, expected)
test_single(expected, expected + '.48w7dl48wl')
test_single(expected, expected + '/48w7dl48wl')
test_single(expected, expected + '.48w7dl48wl.w847lw83')
test_single(expected, expected + '.48w7dl48wl/w847lw83')
test_single(expected, expected + '/48w7dl48wl.w847lw83')
test_single(expected, expected + '/48w7dl48wl/w847lw83')
test_all('2')
test_all('2-0')
test_all('2-0-25')
test_all('2-0-25-b')
if __name__ == '__main__':
unittest.main()
......@@ -2,8 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from appengine_wrappers import GetAppVersion
from cache_chain_object_store import CacheChainObjectStore
from environment import GetAppVersion
from memcache_object_store import MemcacheObjectStore
from test_object_store import TestObjectStore
from persistent_object_store import PersistentObjectStore
......
......@@ -5,7 +5,7 @@
import unittest
from appengine_wrappers import GetAppVersion
from environment import GetAppVersion
from test_object_store import TestObjectStore
from object_store_creator import ObjectStoreCreator
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment