Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / environment.py
blob85e1828d622105956b32ad98dd4f8b0f3d0b566e
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import re
6 import os
7 import sys
9 from app_yaml_helper import AppYamlHelper
10 from third_party.json_schema_compiler.memoize import memoize
13 @memoize
14 def GetAppVersion():
15 return GetAppVersionNonMemoized()
18 # This one is for running from tests, which memoization messes up.
19 def GetAppVersionNonMemoized():
20 if 'CURRENT_VERSION_ID' in os.environ:
21 # The version ID looks like 2-0-25.36712548 or 2-0-25.23/223; we only
22 # want the 2-0-25.
23 return re.compile('[./]').split(os.environ['CURRENT_VERSION_ID'])[0]
24 # Not running on appengine, get it from the app.yaml file ourselves.
25 app_yaml_path = os.path.join(os.path.split(__file__)[0], 'app.yaml')
26 with open(app_yaml_path, 'r') as app_yaml:
27 return AppYamlHelper.ExtractVersion(app_yaml.read())
30 def _IsServerSoftware(name):
31 return os.environ.get('SERVER_SOFTWARE', '').find(name) == 0
34 def IsComputeEngine():
35 return _IsServerSoftware('Compute Engine')
38 def IsDevServer():
39 return _IsServerSoftware('Development')
42 def IsReleaseServer():
43 return _IsServerSoftware('Google App Engine')
46 def IsPreviewServer():
47 return sys.argv and os.path.basename(sys.argv[0]) == 'preview.py'
50 def IsAppEngine():
51 return IsDevServer() or IsReleaseServer()
54 def IsTest():
55 return sys.argv and os.path.basename(sys.argv[0]).endswith('_test.py')
58 class UnknownEnvironmentError(Exception):
59 pass