• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5import re
6import os
7import sys
8
9from app_yaml_helper import AppYamlHelper
10from third_party.json_schema_compiler.memoize import memoize
11
12
13@memoize
14def GetAppVersion():
15  return GetAppVersionNonMemoized()
16
17
18# This one is for running from tests, which memoization messes up.
19def 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())
28
29
30def _IsServerSoftware(name):
31  return os.environ.get('SERVER_SOFTWARE', '').find(name) == 0
32
33
34def IsDevServer():
35  return _IsServerSoftware('Development')
36
37
38def IsReleaseServer():
39  return _IsServerSoftware('Google App Engine')
40
41
42def IsPreviewServer():
43  return sys.argv and os.path.basename(sys.argv[0]) == 'preview.py'
44