Пример #1
0
    def initialize():
        # set stdout as non-buffered
        if hasattr(sys.stdout, 'fileno'):
            fileno = sys.stdout.fileno()
            tmp_fd = os.dup(fileno)
            sys.stdout.close()
            os.dup2(tmp_fd, fileno)
            os.close(tmp_fd)
            sys.stdout = os.fdopen(fileno, "w", 0)
        ctx = utils.FormattedDict()
        # Add environment variables
        for key, val in os.environ.iteritems():
            ctx[key] = wrap(val)
        # Convert JSON env variables
        ctx['VCAP_APPLICATION'] = json.loads(
            ctx.get('VCAP_APPLICATION', wrap('{}')))
        ctx['VCAP_SERVICES'] = json.loads(ctx.get('VCAP_SERVICES', wrap('{}')))
        # Build Pack Location
        ctx['BP_DIR'] = os.path.dirname(os.path.dirname(sys.argv[0]))
        # User's Application Files, build droplet here
        ctx['BUILD_DIR'] = sys.argv[1]
        # Cache space for the build pack
        ctx['CACHE_DIR'] = (len(sys.argv) == 3) and sys.argv[2] or None
        # Temp space
        if 'TMPDIR' not in ctx.keys():
            ctx['TMPDIR'] = tempfile.gettempdir()
        # Make sure cache & build directories exist
        if not os.path.exists(ctx['BUILD_DIR']):
            os.makedirs(ctx['BUILD_DIR'])
        if ctx['CACHE_DIR'] and not os.path.exists(ctx['CACHE_DIR']):
            os.makedirs(ctx['CACHE_DIR'])
        # Add place holder for extensions
        ctx['EXTENSIONS'] = []
        # Init Logging
        CloudFoundryUtil.init_logging(ctx)
        _log.info('CloudFoundry Initialized.')
        _log.debug("CloudFoundry Context Setup [%s]", ctx)

        # get default PHP, httpd, and nginx versions from manifest
        manifest_file = os.path.join(ctx['BP_DIR'], 'manifest.yml')
        for dependency in ["php", "nginx", "httpd"]:
            ctx = CloudFoundryUtil.update_default_version(
                dependency, manifest_file, ctx)

        # Git URL, if one exists
        ctx['BP_GIT_URL'] = find_git_url(ctx['BP_DIR'])
        _log.info('Build Pack Version: %s', ctx['BP_GIT_URL'])
        return ctx
 def initialize():
     # Open stdout unbuffered
     if hasattr(sys.stdout, 'fileno'):
         sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
     ctx = utils.FormattedDict()
     # Add environment variables
     ctx.update(os.environ)
     # Convert JSON env variables
     ctx['VCAP_APPLICATION'] = json.loads(ctx.get('VCAP_APPLICATION',
                                                  '{}',
                                                  format=False))
     ctx['VCAP_SERVICES'] = json.loads(ctx.get('VCAP_SERVICES',
                                               '{}',
                                               format=False))
     # Build Pack Location
     ctx['BP_DIR'] = os.path.dirname(os.path.dirname(sys.argv[0]))
     # User's Application Files, build droplet here
     ctx['BUILD_DIR'] = sys.argv[1]
     # Cache space for the build pack
     ctx['CACHE_DIR'] = (len(sys.argv) == 3) and sys.argv[2] or None
     # Temp space
     if 'TMPDIR' not in ctx.keys():
         ctx['TMPDIR'] = tempfile.gettempdir()
     # Make sure cache & build directories exist
     if not os.path.exists(ctx['BUILD_DIR']):
         os.makedirs(ctx['BUILD_DIR'])
     if ctx['CACHE_DIR'] and not os.path.exists(ctx['CACHE_DIR']):
         os.makedirs(ctx['CACHE_DIR'])
     # Add place holder for extensions
     ctx['EXTENSIONS'] = []
     # Init Logging
     CloudFoundryUtil.init_logging(ctx)
     _log.info('CloudFoundry Initialized.')
     _log.debug("CloudFoundry Context Setup [%s]", ctx)
     # Git URL, if one exists
     ctx['BP_GIT_URL'] = find_git_url(ctx['BP_DIR'])
     _log.info('Build Pack Version: %s', ctx['BP_GIT_URL'])
     return ctx