imp_developer.py 文件源码

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

项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码
def on_model_selected(self, index):
        # Selection was canceled, nothing to do here
        if index == -1:
            return

        model_id, model_name = self.__tmp_all_models[index]

        self.__tmp_all_models = None  # We don't need it anymore
        log_debug("Model selected id: " + model_id)

        # Save newly created model to the project settings
        settings = self.load_settings()
        settings[EI_MODEL_ID] = model_id
        settings[EI_MODEL_NAME] = model_name
        self.env.project_manager.save_settings(PR_SETTINGS_FILE, settings)

        # Reset the logs
        self.env.log_manager.reset()

        # Update the Model name in the status bar
        self.update_model_name_in_status(query_model_name=False)

        if not sublime.ok_cancel_dialog(STR_MODEL_CONFIRM_PULLING_MODEL_CODE):
            return

        # Pull the latest code from the Model
        source_dir = self.env.project_manager.get_source_directory_path()
        agent_file = os.path.join(source_dir, PR_AGENT_FILE_NAME)
        device_file = os.path.join(source_dir, PR_DEVICE_FILE_NAME)

        revisions, code = HTTP.get(self.env.project_manager.get_build_api_key(),
                                   PL_BUILD_API_URL_V4 + "models/" + model_id + "/revisions")
        if len(revisions["revisions"]) > 0:
            latest_revision_url = PL_BUILD_API_URL_V4 + "models/" + model_id + "/revisions/" + \
                                  str(revisions["revisions"][0]["version"])
            source, code = HTTP.get(self.env.project_manager.get_build_api_key(), latest_revision_url)
            with open(agent_file, "w", encoding="utf-8") as file:
                file.write(source["revision"]["agent_code"])
            with open(device_file, "w", encoding="utf-8") as file:
                file.write(source["revision"]["device_code"])
        else:
            # Create initial source files
            with open(agent_file, "w", encoding="utf-8") as file:
                file.write(STR_INITIAL_SRC_CONTENT.format("Agent"))
            with open(device_file, "w", encoding="utf-8") as file:
                file.write(STR_INITIAL_SRC_CONTENT.format("Device"))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号