예제 #1
0
    def _parse_java_configuration(self, app_engine_web_xml_path):
        """Parse appengine-web.xml and web.xml.

    Args:
      app_engine_web_xml_path: A string containing the full path of the
          .../WEB-INF/appengine-web.xml file. The corresponding
          .../WEB-INF/web.xml file must also be present.

    Returns:
      A tuple where the first element is the parsed appinfo.AppInfoExternal
      object and the second element is a list of the paths of the files that
      were used to produce it, namely the input appengine-web.xml file and the
      corresponding web.xml file.
    """
        with open(app_engine_web_xml_path) as f:
            app_engine_web_xml_str = f.read()
        web_inf_dir = os.path.dirname(app_engine_web_xml_path)
        web_xml_path = os.path.join(web_inf_dir, 'web.xml')
        with open(web_xml_path) as f:
            web_xml_str = f.read()
        has_jsps = False
        for _, _, filenames in os.walk(self.application_root):
            if any(f.endswith('.jsp') for f in filenames):
                has_jsps = True
                break
        app_yaml_str = yaml_translator.TranslateXmlToYamlForDevAppServer(
            app_engine_web_xml_str, web_xml_str, has_jsps,
            self.application_root)
        config = appinfo.LoadSingleAppInfo(app_yaml_str)
        return config, [app_engine_web_xml_path, web_xml_path]
예제 #2
0
파일: boot.py 프로젝트: olibrook/djangae
def setup_built_in_library_paths():
    from dev_appserver import fix_sys_path
    fix_sys_path()

    from google.appengine.api import appinfo

    info = appinfo.LoadSingleAppInfo(
        open(os.path.join(find_project_root(), "app.yaml")))

    try:
        version_from_app_yaml = [
            x.version for x in info.libraries if x.name == 'django'
        ][0]
    except IndexError:
        version_from_app_yaml = 'latest'

    latest_non_deprecated = appinfo._NAME_TO_SUPPORTED_LIBRARY[
        'django'].non_deprecated_versions[-1]
    django_version = float(latest_non_deprecated if version_from_app_yaml ==
                           'latest' else version_from_app_yaml)

    if django_version < 1.5:
        raise RuntimeError("Djangae only supports Django 1.5+")

    #Remove default django
    sys.path = [x for x in sys.path if "django-1.4" not in x]

    django_folder = "django-" + str(django_version)
    sys.path.insert(
        1, os.path.join(os.environ['APP_ENGINE_SDK'], "lib", django_folder))
예제 #3
0
def ParseAndReturnIncludePaths(appinfo_file, open_fn=open):
    """Parse an AppYaml file and merge referenced includes and builtins."""
    try:
        appinfo_path = appinfo_file.name
        if not os.path.isfile(appinfo_path):
            raise Exception(
                'Name defined by appinfo_file does not appear to be a '
                'valid file: %s' % appinfo_path)
    except AttributeError:
        raise Exception('File object passed to ParseAndMerge does not define '
                        'attribute "name" as as full file path.')

    appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
    appyaml, include_paths = _MergeBuiltinsIncludes(appinfo_path, appyaml,
                                                    open_fn)

    if not appyaml.handlers:
        raise appinfo_errors.MissingURLMapping(
            'No URLMap entries found in application configuration')
    if len(appyaml.handlers) > appinfo.MAX_URL_MAPS:
        raise appinfo_errors.TooManyURLMappings(
            'Found more than %d URLMap entries in application configuration' %
            appinfo.MAX_URL_MAPS)
    if appyaml.runtime == 'python27' and appyaml.threadsafe:
        for handler in appyaml.handlers:
            if (handler.script and
                (handler.script.endswith('.py') or '/' in handler.script)):
                raise appinfo_errors.ThreadsafeWithCgiHandler(
                    'Threadsafe cannot be enabled with CGI handler: %s' %
                    handler.script)

    return appyaml, include_paths
예제 #4
0
파일: utils.py 프로젝트: casidos/pickem
 def decorated_func(*args, **kwargs):
     if not hasattr(env, 'gae'):
         # Load the app.yaml file
         yamlpath = os.path.join(PROJECT_ROOT, 'app.yaml')
         appcfg = appinfo.LoadSingleAppInfo(open(yamlpath))
         # Add the gae object
         env.gae = type('GaeInfo', (), {})
         setattr(env.gae, 'app_id', appcfg.application)
         setattr(env.gae, 'version', appcfg.version)
     return func(*args, **kwargs)
def _CopyAppInfo(app_yaml_config):
    """Deep copy of parsed YAML config.

  Casts native YAML object to string and then back again.

  Args:
    app_yaml_config: A appinfo.AppInfoExternal object. Contains parsed app.yaml.

  Returns:
    Deep copy of app_yaml_config.
  """
    as_yaml = app_yaml_config.ToYAML()
    return appinfo.LoadSingleAppInfo(as_yaml)
예제 #6
0
    def _parse_java_configuration(self, app_engine_web_xml_path):
        """Parse appengine-web.xml and web.xml.

    Args:
      app_engine_web_xml_path: A string containing the full path of the
          .../WEB-INF/appengine-web.xml file. The corresponding
          .../WEB-INF/web.xml file must also be present.

    Returns:
      A tuple where the first element is the parsed appinfo.AppInfoExternal
      object and the second element is a list of the paths of the files that
      were used to produce it, namely the input appengine-web.xml file and the
      corresponding web.xml file.
    """
        with open(app_engine_web_xml_path) as f:
            app_engine_web_xml_str = f.read()
        app_engine_web_xml = (app_engine_web_xml_parser.AppEngineWebXmlParser(
        ).ProcessXml(app_engine_web_xml_str))

        quickstart = xml_parser_utils.BooleanValue(
            app_engine_web_xml.beta_settings.get('java_quickstart', 'false'))

        web_inf_dir = os.path.dirname(app_engine_web_xml_path)
        if quickstart:
            app_dir = os.path.dirname(web_inf_dir)
            web_xml_str, web_xml_path = java_quickstart.quickstart_generator(
                app_dir)
            webdefault_xml_str = java_quickstart.get_webdefault_xml()
            web_xml_str = java_quickstart.remove_mappings(
                web_xml_str, webdefault_xml_str)
        else:
            web_xml_path = os.path.join(web_inf_dir, 'web.xml')
            with open(web_xml_path) as f:
                web_xml_str = f.read()

        has_jsps = False
        for _, _, filenames in os.walk(self.application_root):
            if any(f.endswith('.jsp') for f in filenames):
                has_jsps = True
                break

        web_xml = web_xml_parser.WebXmlParser().ProcessXml(
            web_xml_str, has_jsps)
        app_yaml_str = yaml_translator.TranslateXmlToYamlForDevAppServer(
            app_engine_web_xml, web_xml, self.application_root)
        config = appinfo.LoadSingleAppInfo(app_yaml_str)
        return config, [app_engine_web_xml_path, web_xml_path]
예제 #7
0
def ParseAndReturnIncludePaths(appinfo_file, open_fn=open):
    """Parse an AppYaml file and merge referenced includes and builtins.

  Args:
    appinfo_file: an opened file, for example the result of open('app.yaml').
    open_fn: a function to open included files.

  Returns:
    A tuple where the first element is the parsed appinfo.AppInfoExternal
    object and the second element is a list of the absolute paths of the
    included files, in no particular order.
  """
    try:
        appinfo_path = appinfo_file.name
        if not os.path.isfile(appinfo_path):
            raise Exception(
                'Name defined by appinfo_file does not appear to be a '
                'valid file: %s' % appinfo_path)
    except AttributeError:
        raise Exception('File object passed to ParseAndMerge does not define '
                        'attribute "name" as as full file path.')

    appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
    appyaml, include_paths = _MergeBuiltinsIncludes(appinfo_path, appyaml,
                                                    open_fn)

    if not appyaml.handlers:

        if appyaml.vm:
            appyaml.handlers = [appinfo.URLMap(url='.*', script='PLACEHOLDER')]
        else:
            raise appinfo_errors.MissingURLMapping(
                'No URLMap entries found in application configuration')
    if len(appyaml.handlers) > appinfo.MAX_URL_MAPS:
        raise appinfo_errors.TooManyURLMappings(
            'Found more than %d URLMap entries in application configuration' %
            appinfo.MAX_URL_MAPS)
    if appyaml.runtime == 'python27' and appyaml.threadsafe:
        for handler in appyaml.handlers:
            if (handler.script and
                (handler.script.endswith('.py') or '/' in handler.script)):
                raise appinfo_errors.ThreadsafeWithCgiHandler(
                    'Threadsafe cannot be enabled with CGI handler: %s' %
                    handler.script)

    return appyaml, include_paths
def application_id():
    from google.appengine.api import app_identity

    try:
        result = app_identity.get_application_id()
    except AttributeError:
        result = None

    if not result:
        # Apparently we aren't running live, probably inside a management command
        from google.appengine.api import appinfo

        info = appinfo.LoadSingleAppInfo(open(os.path.join(find_project_root(), "app.yaml")))

        result = "dev~" + info.application
        os.environ['APPLICATION_ID'] = result
        result = app_identity.get_application_id()

    return result
def _ConvertBackendToModules(backend_config, app_config):
    """Creates Modules configuration using app and backend config.

  Parses the app.yaml and backend.yaml contents into native AppInfoExternal
  and BackendInfoExternal objects and then creates an AppInfoExternal
  for each backend defined in backend_config.

  Args:
    backend_config: String, the contents of backend.yaml.
    app_config: String, the contents of app.yaml.

  Returns:
    A list of AppInfoExternal objects for each module.
  """
    backend_info = backendinfo.LoadBackendInfo(backend_config)
    app_yaml_config = appinfo.LoadSingleAppInfo(app_config)
    return [
        _ConvertBackendToModule(backend, app_yaml_config)
        for backend in backend_info.backends
    ]
def Parse(appinfo_file):
  """Parse an AppYaml file and merge referenced includes and builtins."""
  try:
    appinfo_path = appinfo_file.name
    if not os.path.isfile(appinfo_path):
      raise Exception('Name defined by appinfo_file does not appear to be a '
                      'valid file: %s' % appinfo_path)
  except AttributeError:
    raise Exception('File object passed to ParseAndMerge does not define '
                    'attribute "name" as as full file path.')

  appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
  appyaml = _MergeBuiltinsIncludes(appinfo_path, appyaml)


  if not appyaml.handlers:
    raise appinfo_errors.MissingURLMapping(
        'No URLMap entries found in application configuration')
  if len(appyaml.handlers) > appinfo.MAX_URL_MAPS:
    raise appinfo_errors.TooManyURLMappings(
        'Found more than %d URLMap entries in application configuration' %
        appinfo.MAX_URL_MAPS)

  return appyaml
예제 #11
0
 def decorated_func(*args, **kwargs):
     if not hasattr(env, 'app'):
         appcfg = appinfo.LoadSingleAppInfo(open(env.gae_src + 'app.yaml'))
         env.app = appcfg
     return func(*args, **kwargs)
예제 #12
0
 def config(self):
     return appinfo.LoadSingleAppInfo(cStringIO.StringIO(self.app_yaml))