tcex_local.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:threatconnect-developer-docs 作者: ThreatConnect-Inc 项目源码 文件源码
def gen_lib():
        """Build libs locally for app

        Using the setup.py this method will install all required python modules locally
        to be used for local testing.
        """
        lib_directory = 'lib_{}.{}.{}'.format(
            sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
        app_path = os.getcwd()
        app_name = os.path.basename(app_path)

        lib_path = os.path.join(app_path, lib_directory)
        if not os.path.isdir(lib_path):
            os.mkdir(lib_path)

        os.environ['PYTHONPATH'] = '{}'.format(lib_path)
        stdout = sys.stdout
        stderr = sys.stderr
        try:
            with open(os.path.join(app_path, '{}-libs.log'.format(app_name)), 'w') as log:
                sys.stdout = log
                sys.stderr = log
                easy_install.main(['-axZ', '-d', lib_path, str(app_path)])
        except SystemExit as e:
            raise Exception(str(e))
        finally:
            sys.stdout = stdout
            sys.stderr = stderr

        if os.listdir(lib_path):
            err = 'Encountered error running easy_install for {}.  Check log file for details.'
            raise Exception(err.format(app_name))

        build_path = os.path.join(app_path, 'build')
        if os.access(build_path, os.W_OK):
            shutil.rmtree(build_path)
        temp_path = os.path.join(app_path, 'temp')
        if os.access(temp_path, os.W_OK):
            shutil.rmtree(temp_path)
        egg_path = os.path.join(app_path, app_name + '.egg-info')
        if os.access(egg_path, os.W_OK):
            shutil.rmtree(egg_path)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号