app/soc/logic/system.py
author Mario Ferraro <fadinlight@gmail.com>
Sun, 15 Nov 2009 22:12:20 +0100
changeset 3093 d1be59b6b627
parent 2879 cb0f9b4646aa
permissions -rw-r--r--
GMaps related JS changed to use new google namespace. Google is going to change permanently in the future the way to load its services, so better stay safe. Also this commit shows uses of the new melange.js module. Fixes Issue 634.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
114
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
114
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Basic system information functions.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
578
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    25
import os
114
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
import settings
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
2879
cb0f9b4646aa Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2871
diff changeset
    29
def getHostname():
cb0f9b4646aa Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2871
diff changeset
    30
  """Returns the hostname
cb0f9b4646aa Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2871
diff changeset
    31
  """
cb0f9b4646aa Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2871
diff changeset
    32
cb0f9b4646aa Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2871
diff changeset
    33
  return os.environ.get('HTTP_HOST')
cb0f9b4646aa Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2871
diff changeset
    34
578
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    35
def getAppVersion():
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    36
  """Returns the Google App Engine "version" of the running instance.
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    37
  """
1592
4465cda55182 Add a maintenance end date
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    38
578
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    39
  return os.environ.get('CURRENT_VERSION_ID')
1797
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    40
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    41
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    42
def getMelangeVersion():
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    43
  """Returns the Melange part of the GAE version.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    44
  """
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    45
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    46
  return getAppVersion().split('.', 1)[0]
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    47
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    48
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    49
def isLocal():
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    50
  """Returns True if Melange application is running locally.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    51
  
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    52
  "Local mode" is currently determined from settings.DEBUG but may become
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    53
  more sophisticated in the future.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    54
  """
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    55
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    56
  return settings.DEBUG
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    57
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    58
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    59
def isDebug():
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    60
  """Returns True if Melange application is running in "debug mode".
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    61
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    62
  "Debug mode" is currently enabled if running locally or if the
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    63
  current Melange version is 'devvin'.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    64
  """
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    65
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    66
  return isLocal() or getMelangeVersion() == 'devvin'