当前位置: 首页>>代码示例>>Python>>正文


Python Tools.getHeaders方法代码示例

本文整理汇总了Python中libs.Tools.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.getHeaders方法的具体用法?Python Tools.getHeaders怎么用?Python Tools.getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libs.Tools的用法示例。


在下文中一共展示了Tools.getHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checkPio

# 需要导入模块: from libs import Tools [as 别名]
# 或者: from libs.Tools import getHeaders [as 别名]
    def checkPio(self):
        # defining default env paths
        os.environ['PATH'] = self.getEnvPaths()

        # checking python
        cmd = ['python', '--version']
        out = childProcess(cmd)

        # show error and link to download
        if(out[0] > 0):
            current_time = time.strftime('%H:%M:%S')
            go_to = sublime.ok_cancel_dialog(
                "deviot_need_python", "button_download_python")
            if(go_to):
                sublime.run_command(
                    'open_url', {'url': 'https://www.python.org/downloads/'})
            return

        # check if pio is installed
        self.message_queue.startPrint()
        self.message_queue.put("deviot_setup{0}", version)
        current_time = time.strftime('%H:%M:%S')

        cmd = ['pio', '--version']
        out = childProcess(cmd)

        if(out[0] == 0):
            current_time = time.strftime('%H:%M:%S')
            self.message_queue.put("pio_is_installed{0}", current_time)

            self.endSetup()
            return

        current_time = time.strftime('%H:%M:%S')
        self.message_queue.put("pio_isn_installed{0}", current_time)

        # check if virtualenv file is cached
        if(os.path.exists(self.env_file)):
            self.cached_file = True

        # download virtualenv
        if(not self.cached_file):
            current_time = time.strftime('%H:%M:%S')
            self.message_queue.put("downloading_files{0}", current_time)
            headers = Tools.getHeaders()
            url_file = 'https://pypi.python.org/packages/source/v/virtualenv/virtualenv-14.0.1.tar.gz'

            try:
                file_request = Request(url_file, headers=headers)
                file_open = urlopen(file_request)
                file = file_open.read()
            except:
                current_time = time.strftime('%H:%M:%S')
                self.message_queue.put(
                    "error_downloading_files{0}", current_time)
                print("There was an error downloading virtualenv")
                return
            # save file
            try:
                output = open(self.env_file, 'wb')
                output.write(bytearray(file))
                output.close()
            except:
                current_time = time.strftime('%H:%M:%S')
                self.message_queue.put("error_saving_files{0}", current_time)
                print("There was an error saving the virtualenv file")
                return

        # extract file
        current_time = time.strftime('%H:%M:%S')
        self.message_queue.put("extracting_files{0}", current_time)
        tmp = tempfile.mkdtemp()
        Tools.extractTar(self.env_file, tmp)

        # install virtualenv in a temp dir
        current_time = time.strftime('%H:%M:%S')
        self.message_queue.put("installing_pio{0}", current_time)

        temp_env = os.path.join(tmp, 'env-root')
        cwd = os.path.join(tmp, 'virtualenv-14.0.1')
        cmd = ['python', 'setup.py', 'install', '--root', temp_env]
        out = childProcess(cmd, cwd)

        # error
        if(out[0] > 0):
            current_time = time.strftime('%H:%M:%S')
            self.message_queue.put("error_installing_env_{0}", current_time)
            return

        # make vitualenv
        for root, dirs, files in os.walk(tmp):
            for file in files:
                if(file == 'virtualenv.py'):
                    cwd = root

        if(os.path.exists(cwd)):
            cmd = ['python', 'virtualenv.py', '\"' + self.env_dir + '\"']
            out = childProcess(cmd, cwd)

            # error
#.........这里部分代码省略.........
开发者ID:ikthap,项目名称:Deviot,代码行数:103,代码来源:Install.py


注:本文中的libs.Tools.getHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。