예제 #1
0
    def download_binary(self, replace=False):
        binary = self.get_asset_from_release_data()

        if binary:
            final_size = binary["size"]
            increment = (BINARY_DOWNLOAD_PROGRESS_SIZE / (final_size / 1024))

            r = requests.get(binary["browser_download_url"], stream=True)

            binary_name, binary_ext = os.path.splitext(binary["name"])
            path = f"{self.PROJECT}{binary_ext}"

            if r.status_code == 200:

                if replace and os.path.isfile(path):
                    try:
                        os.remove(path)
                    except OSError as e:
                        logging.error(f"Can't remove old version binary : {e}")

                with open(path, 'wb') as f:
                    for chunk in r.iter_content(1024):
                        f.write(chunk)
                        inc_progress(increment)

            return path
        else:
            logging.error("Release not found on server")
            return None
예제 #2
0
    def get_local_version_or_download(self,
                                      github_instance,
                                      binary_path,
                                      latest_release_data=None,
                                      force_binary=FORCE_BINARY):
        last_release_version = github_instance.get_current_server_version(
            latest_release_data=latest_release_data)
        current_version = self.get_current_version(binary_path,
                                                   force_binary=force_binary)

        try:
            if current_version == self.NOT_INSTALLED_VERSION:
                check_new_version = True
            else:
                check_new_version = LooseVersion(
                    current_version) < LooseVersion(last_release_version)
        except AttributeError:
            check_new_version = False

        if check_new_version:
            logging.info(
                f"Upgrading {self.PROJECT} : from {current_version} to {last_release_version}..."
            )
            return github_instance.download_binary(replace=True)
        else:
            logging.info(f"Nothing to do : {self.PROJECT} is up to date")
            if launcher_instance:
                inc_progress(BINARY_DOWNLOAD_PROGRESS_SIZE)
            return binary_path
예제 #3
0
def create_environment():
    inc_progress(0, to_min=True)
    logging.info(f"{OCTOBOT_NAME} is checking your environment...")

    inc_progress(1)
    ensure_file_environment(INSTALL_DOWNLOAD)

    inc_progress(LIB_FILES_DOWNLOAD_PROGRESS_SIZE - 1)
    inc_progress(CREATE_FOLDERS_PROGRESS_SIZE)

    logging.info(f"Your {OCTOBOT_NAME} environment is ready !")