a method to deploy a static html page to heroku using php

def deploy_app(self, site_folder, runtime_type=''):

        ''' a method to deploy a static html page to heroku using php '''

        title = '%s.deploy_php' % self.__class__.__name__

    # validate inputs
        input_fields = {
            'site_folder': site_folder,
            'runtime_type': runtime_type
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)

    # verify app subdomain
        if not self.subdomain:
            raise Exception('You must access a subdomain before you can deploy to heroku. Try: %s.access()' % self.__class__.__name__)
                    
    # validate existence of site folder
        from os import path
        if not path.exists(site_folder):
            raise ValueError('%s is not a valid path on localhost.' % site_folder)
    
    # validate existence of proper runtime file
        runtime_file = 'index.html'
        static_build = False
        if runtime_type == 'php':
            runtime_file = 'index.php'
        elif runtime_type in ('ruby', 'java', 'python', 'jingo'):
            runtime_file = 'Procfile'
        elif runtime_type == 'node':
            runtime_file = 'package.json'
        else:
            runtime_type = 'html'
            static_build = True
        build_file = path.join(site_folder, runtime_file)
        if not path.exists(build_file):
            raise Exception('%s must contain an %s file to build a %s app.' % (site_folder, runtime_file, runtime_type))
        if runtime_type == 'python':
            req_file = path.join(site_folder, 'requirements.txt')
            if not path.exists(req_file):
                raise Exception('%s must contain a requirements.txt file to build a python app.' % site_folder)
        if runtime_type == 'jingo':
            req_file = path.join(site_folder, 'package.json')
            if not path.exists(req_file):
                raise Exception('%s must contain a package.json file to build a jingo app.' % site_folder)

    # validate container plugin
        from os import devnull
        from subprocess import check_output
        self.printer('Checking heroku plugin requirements ... ', flush=True)
        sys_command = 'heroku plugins'
        heroku_plugins = check_output(sys_command, shell=True, stderr=open(devnull, 'wb')).decode('utf-8')
        if heroku_plugins.find('heroku-builds') == -1:
            self.printer('ERROR')
            raise Exception(
                'heroku builds plugin required. Try: heroku plugins:install heroku-builds')
        self.printer('done.')
    
    # construct temporary folder
        self.printer('Creating temporary files ... ', flush=True)
        from shutil import copytree, move, ignore_patterns
        from os import makedirs
        from time import time
        from labpack import __module__
        from labpack.storage.appdata import appdataClient
        client_kwargs = {
            'collection_name': 'TempFiles',
            'prod_name': __module__
        }
        tempfiles_client = appdataClient(**client_kwargs)
        temp_folder = path.join(tempfiles_client.collection_folder, 'heroku%s' % time())
    
    # define cleanup function
        def _cleanup_temp():
            self.printer('Cleaning up temporary files ... ', flush=True)
            from shutil import rmtree
            rmtree(temp_folder, ignore_errors=True)
            self.printer('done.')

    # copy site to temporary folder
        try:
            makedirs(temp_folder)
            site_root, site_name = path.split(path.abspath(site_folder))
            build_path = path.join(temp_folder, site_name)
            copytree(site_folder, build_path, ignore=ignore_patterns('*node_modules/*','*.lab/*'))
            if static_build:
                index_path = path.join(build_path, 'index.html')
                home_path = path.join(build_path, 'home.html')
                compose_path = path.join(build_path, 'compose.json')
                php_path = path.join(build_path, 'index.php')
                with open(compose_path, 'wt') as f:
                    f.write('{}')
                    f.close()
                with open(php_path, 'wt') as f:
                    f.write('<?php include_once("home.html"); ?>')
                    f.close()
                move(index_path, home_path)
        except:
            self.printer('ERROR')
            _cleanup_temp()
            raise
        self.printer('done.')

    # deploy site to heroku
        self.printer('Deploying %s to heroku ... ' % site_folder, flush=True)
        try:
            sys_command = 'cd %s; heroku builds:create -a %s' % (temp_folder, self.subdomain)
            self._handle_command(sys_command, print_pipe=True)
        except:
            self.printer('ERROR')
            raise
        finally:
            _cleanup_temp()

        self.printer('Deployment complete.')
        
        return True