# Path: __pg/appids.py
# _APP_ID_TUPLES = [
#     # production environment
#     ('try-appengine', 'shared-playground', 'cloud-playground'),
#     # development environment
#     ('fredsa-bliss', 'fredsa-hr', None),
#     ('dansanderson-bliss', 'dansanderson-mimic', None),
# ]
# _APP_ID = os.environ['APPLICATION_ID'].split('~')[-1]
# PLAYGROUND_APP_ID = app_ids[0]
# MIMIC_APP_ID = app_ids[1]
# PLAYGROUND_APP_ID_ALIAS = app_ids[2]
# TWO_COLLABORATING_APP_IDS = PLAYGROUND_APP_ID != MIMIC_APP_ID
# def _GetTupleFor(app_id):
# def PrintAppIds():
# 
# Path: __pg/settings.py
# DEBUG = True
# USER_CONTENT_PREFIX = 'user-content'
# LONG_AGO = 'Mon, 01 Jan 1990 00:00:00 GMT'
# TEMPLATE_MEMCACHE_TIME = 3600
# PUBLIC_PROJECT_TEMPLATE_OWNER = 'PUBLIC_TEMPLATE'
# MANUAL_PROJECT_TEMPLATE_OWNER = 'MANUAL_TEMPLATE'
# PROJECT_TEMPLATE_OWNERS = [
#     PUBLIC_PROJECT_TEMPLATE_OWNER,
#     MANUAL_PROJECT_TEMPLATE_OWNER
# ]
# _DEV_MODE = os.environ['SERVER_SOFTWARE'].startswith('Development/')
# PLAYGROUND_NAMESPACE = '_playground'
# TEMPLATE_PROJECT_DIR = 'repos/'
# ACCESS_KEY_SET_COOKIE_PARAM_NAME = 'set_access_key_cookie'
# ACCESS_KEY_HTTP_HEADER = 'X-Cloud-Playground-Access-Key'
# ACCESS_KEY_COOKIE_NAME = 'access_key'
# ACCESS_KEY_COOKIE_ARGS = {
#     'httponly': True,
#     'secure': not _DEV_MODE,
# }
# SESSION_COOKIE_NAME = 'session'
# SESSION_COOKIE_ARGS = {
#     'httponly': True,
#     'secure': not _DEV_MODE,
# }
# XSRF_COOKIE_ARGS = {
#     'httponly': False,
#     'secure': not _DEV_MODE,
# }
# MIN_EXPIRATION_SECONDS = 3600
# DEFAULT_EXPIRATION_SECONDS = 604800
# NO_SUCH_PROJECT = 'NO_SUCH_PROJECT'
# SKIP_EXTENSIONS = ('swp', 'pyc', 'svn')
#   PLAYGROUND_HOSTS = ['localhost:8080', '127.0.0.1:8080',
#                       # port 7070 for karma e2e test
#                       'localhost:7070', '127.0.0.1:7070',
#                       app_identity.get_default_version_hostname()]
#   PLAYGROUND_USER_CONTENT_HOST = None
#   MIMIC_HOST = backends.get_hostname('exec-code-backend')
#   PLAYGROUND_HOSTS = ['{}.appspot.com'.format(appids.PLAYGROUND_APP_ID)]
#   PLAYGROUND_USER_CONTENT_HOST = None
#   MIMIC_HOST = '{0}.appspot.com'.format(appids.MIMIC_APP_ID)
# 
# Path: __pg/zip_urlfetch_tree.py
# class ZipUrlFetchTree(common.Tree):
#   def __init__(self, namespace, access_key):
#   def __repr__(self):
#   def IsMutable(self):
#   def GetFileContents(self, path):
#   def GetFileSize(self, path):
#   def GetFileLastModified(self, path):
#   def HasFile(self, path):
#   def HasDirectory(self, path):
#   def ListDirectory(self, path):


import json
import os
import re
import sys
from mimic.__mimic import common
from mimic.__mimic import datastore_tree
from __pg import appids
from __pg import settings
from __pg import zip_urlfetch_tree
from google.appengine.api import app_identity
app_id = app_identity.get_application_id()

# pylint: disable-msg=invalid-name
if common.IsDevMode() or app_id == appids.PLAYGROUND_APP_ID:
  mimic_CREATE_TREE_FUNC = datastore_tree.DatastoreTree
else:
  mimic_CREATE_TREE_FUNC = zip_urlfetch_tree.ZipUrlFetchTree

mimic_JSON_ENCODER = json.JSONEncoder()
mimic_JSON_ENCODER.indent = 4
mimic_JSON_ENCODER.sort_keys = True

mimic_NAMESPACE = '_playground'

# keep in sync with app/js/controllers.js
mimic_PROJECT_ID_QUERY_PARAM = '_mimic_project'

mimic_PROJECT_ID_FROM_PATH_INFO_RE = re.compile('/playground/p/(.+?)/')

if common.IsDevMode():
  scheme = 'http'
else:
  scheme = 'https'

if settings.PLAYGROUND_USER_CONTENT_HOST:
  mimic_ALLOWED_USER_CONTENT_HOSTS = [settings.PLAYGROUND_USER_CONTENT_HOST]
else:
  mimic_ALLOWED_USER_CONTENT_HOSTS = None

mimic_CORS_ALLOWED_ORIGINS = ['{0}://{1}'.format(scheme, h)

# Path: __pg/appids.py
# _APP_ID_TUPLES = [
#     # production environment
#     ('try-appengine', 'shared-playground', 'cloud-playground'),
#     # development environment
#     ('fredsa-bliss', 'fredsa-hr', None),
#     ('dansanderson-bliss', 'dansanderson-mimic', None),
# ]
# _APP_ID = os.environ['APPLICATION_ID'].split('~')[-1]
# PLAYGROUND_APP_ID = app_ids[0]
# MIMIC_APP_ID = app_ids[1]
# PLAYGROUND_APP_ID_ALIAS = app_ids[2]
# TWO_COLLABORATING_APP_IDS = PLAYGROUND_APP_ID != MIMIC_APP_ID
# def _GetTupleFor(app_id):
# def PrintAppIds():
# 
# Path: __pg/settings.py
# DEBUG = True
# USER_CONTENT_PREFIX = 'user-content'
# LONG_AGO = 'Mon, 01 Jan 1990 00:00:00 GMT'
# TEMPLATE_MEMCACHE_TIME = 3600
# PUBLIC_PROJECT_TEMPLATE_OWNER = 'PUBLIC_TEMPLATE'
# MANUAL_PROJECT_TEMPLATE_OWNER = 'MANUAL_TEMPLATE'
# PROJECT_TEMPLATE_OWNERS = [
#     PUBLIC_PROJECT_TEMPLATE_OWNER,
#     MANUAL_PROJECT_TEMPLATE_OWNER
# ]
# _DEV_MODE = os.environ['SERVER_SOFTWARE'].startswith('Development/')
# PLAYGROUND_NAMESPACE = '_playground'
# TEMPLATE_PROJECT_DIR = 'repos/'
# ACCESS_KEY_SET_COOKIE_PARAM_NAME = 'set_access_key_cookie'
# ACCESS_KEY_HTTP_HEADER = 'X-Cloud-Playground-Access-Key'
# ACCESS_KEY_COOKIE_NAME = 'access_key'
# ACCESS_KEY_COOKIE_ARGS = {
#     'httponly': True,
#     'secure': not _DEV_MODE,
# }
# SESSION_COOKIE_NAME = 'session'
# SESSION_COOKIE_ARGS = {
#     'httponly': True,
#     'secure': not _DEV_MODE,
# }
# XSRF_COOKIE_ARGS = {
#     'httponly': False,
#     'secure': not _DEV_MODE,
# }
# MIN_EXPIRATION_SECONDS = 3600
# DEFAULT_EXPIRATION_SECONDS = 604800
# NO_SUCH_PROJECT = 'NO_SUCH_PROJECT'
# SKIP_EXTENSIONS = ('swp', 'pyc', 'svn')
#   PLAYGROUND_HOSTS = ['localhost:8080', '127.0.0.1:8080',
#                       # port 7070 for karma e2e test
#                       'localhost:7070', '127.0.0.1:7070',
#                       app_identity.get_default_version_hostname()]
#   PLAYGROUND_USER_CONTENT_HOST = None
#   MIMIC_HOST = backends.get_hostname('exec-code-backend')
#   PLAYGROUND_HOSTS = ['{}.appspot.com'.format(appids.PLAYGROUND_APP_ID)]
#   PLAYGROUND_USER_CONTENT_HOST = None
#   MIMIC_HOST = '{0}.appspot.com'.format(appids.MIMIC_APP_ID)
# 
# Path: __pg/zip_urlfetch_tree.py
# class ZipUrlFetchTree(common.Tree):
#   def __init__(self, namespace, access_key):
#   def __repr__(self):
#   def IsMutable(self):
#   def GetFileContents(self, path):
#   def GetFileSize(self, path):
#   def GetFileLastModified(self, path):
#   def HasFile(self, path):
#   def HasDirectory(self, path):
#   def ListDirectory(self, path):


# Path: appengine_config.py
import json
import os
import re
import sys
from mimic.__mimic import common
from mimic.__mimic import datastore_tree
from __pg import appids
from __pg import settings
from __pg import zip_urlfetch_tree
from google.appengine.api import app_identity

app_id = app_identity.get_application_id()

# pylint: disable-msg=invalid-name
if common.IsDevMode() or app_id == appids.PLAYGROUND_APP_ID:
  mimic_CREATE_TREE_FUNC = datastore_tree.DatastoreTree
else:
  mimic_CREATE_TREE_FUNC = zip_urlfetch_tree.ZipUrlFetchTree

mimic_JSON_ENCODER = json.JSONEncoder()
mimic_JSON_ENCODER.indent = 4
mimic_JSON_ENCODER.sort_keys = True

mimic_NAMESPACE = '_playground'

# keep in sync with app/js/controllers.js
mimic_PROJECT_ID_QUERY_PARAM = '_mimic_project'

mimic_PROJECT_ID_FROM_PATH_INFO_RE = re.compile('/playground/p/(.+?)/')

if common.IsDevMode():
  scheme = 'http'
else:
  scheme = 'https'

if settings.PLAYGROUND_USER_CONTENT_HOST:
  mimic_ALLOWED_USER_CONTENT_HOSTS = [settings.PLAYGROUND_USER_CONTENT_HOST]
else:
  mimic_ALLOWED_USER_CONTENT_HOSTS = None

mimic_CORS_ALLOWED_ORIGINS = ['{0}://{1}'.format(scheme, h)

                              for h in settings.PLAYGROUND_HOSTS]