예제 #1
0
    def update(self):
        """
        Calls git pull origin <branch> in order to update SickChill. Returns a bool depending
        on the call's success.
        """

        # update remote origin url
        self._update_remote_origin()

        # remove untracked files and performs a hard reset on git branch to avoid update issues
        if settings.GIT_RESET:
            # self._clean() # This is removing user data and backups
            self._reset()

        if self.branch == self._find_installed_branch():
            stdout_, stderr_, exit_status = self._run_git(
                self._git_path,
                'pull -f {0} {1}'.format(settings.GIT_REMOTE, self.branch))
        else:
            stdout_, stderr_, exit_status = self._run_git(
                self._git_path, 'checkout -f ' + self.branch)

        if exit_status == 0:
            self._find_installed_version()
            self._clean_libs()

            # Notify update successful
            notifiers.notify_git_update(settings.CUR_COMMIT_HASH or "")
            return True
        else:
            return False
예제 #2
0
    def update(self):
        if not pip_install("sickchill"):
            return False

        settings.CUR_COMMIT_HASH = self._newest_version
        notifiers.notify_git_update(f"{settings.CUR_COMMIT_HASH or ''}")
        return True
예제 #3
0
파일: source.py 프로젝트: BKSteve/SickChill
    def update(self):
        """
        Downloads the latest source tarball from github and installs it over the existing version.
        """

        tar_download_url = f"https://github.com/{settings.GIT_ORG}/{settings.GIT_REPO}/tarball/{self.branch}"

        try:
            # prepare the update dir
            sc_update_dir = Path(settings.DATA_DIR) / "sc-update"

            if sc_update_dir.is_dir():
                logger.info(
                    f"Clearing out update folder {sc_update_dir} before extracting"
                )
                shutil.rmtree(sc_update_dir)

            logger.info(
                f"Creating update folder {sc_update_dir} before extracting")
            sc_update_dir.mkdir()

            # retrieve file
            logger.info(f"Downloading update from {tar_download_url}")
            tar_download_path = sc_update_dir / "sc-update.tar"
            tar_download_path = tar_download_path.resolve()

            helpers.download_file(str(tar_download_url),
                                  str(tar_download_path),
                                  session=self.session)

            if not tar_download_path.is_file():
                logger.warning(
                    f"Unable to retrieve new version from {tar_download_url}, can't update"
                )
                return False

            if not tarfile.is_tarfile(tar_download_path):
                logger.exception(
                    f"Retrieved version from {tar_download_url} is corrupt, can't update"
                )
                return False

            # extract to sc-update dir
            logger.info(f"Extracting file {tar_download_path}")
            tar = tarfile.open(tar_download_path)
            tar.extractall(sc_update_dir)
            tar.close()

            # delete .tar.gz
            logger.info(f"Deleting file {tar_download_path}")
            tar_download_path.unlink()

            # find update dir name
            update_dir_contents = [
                x for x in sc_update_dir.iterdir() if x.is_dir()
            ]

            if len(update_dir_contents) != 1:
                logger.exception(
                    f"Invalid update data, update failed: {str(update_dir_contents)}"
                )
                return False

            # walk temp folder and move files to main folder
            content_dir = sc_update_dir / update_dir_contents[0]
            logger.info(
                f"Moving files from {content_dir} to {os.path.dirname(settings.PROG_DIR)}"
            )

            for dirname, stderr_, filenames in os.walk(content_dir):
                dirname = dirname[len(str(content_dir)) + 1:]
                for curfile in filenames:
                    old_path = content_dir / dirname / curfile
                    new_path = os.path.join(os.path.dirname(settings.PROG_DIR),
                                            dirname, curfile)

                    if os.path.isfile(new_path):
                        os.remove(new_path)
                    os.renames(old_path, new_path)

            settings.CUR_COMMIT_HASH = self._newest_commit_hash
            settings.CUR_COMMIT_BRANCH = self.branch

        except Exception as error:
            logger.exception(f"Error while trying to update: {error}")
            logger.debug(f"Traceback: {traceback.format_exc()}")
            return False

        # Notify update successful
        notifiers.notify_git_update(settings.CUR_COMMIT_HASH or "")
        return True
예제 #4
0
    def update(self):
        """
        Downloads the latest source tarball from github and installs it over the existing version.
        """

        tar_download_url = 'https://github.com/' + settings.GIT_ORG + '/' + settings.GIT_REPO + '/tarball/' + self.branch

        try:
            # prepare the update dir
            sr_update_dir = os.path.join(settings.DATA_DIR, 'sr-update')

            if os.path.isdir(sr_update_dir):
                logger.info("Clearing out update folder " + sr_update_dir +
                            " before extracting")
                shutil.rmtree(sr_update_dir)

            logger.info("Creating update folder " + sr_update_dir +
                        " before extracting")
            os.makedirs(sr_update_dir)

            # retrieve file
            logger.info(
                "Downloading update from {url}".format(url=tar_download_url))
            tar_download_path = os.path.join(sr_update_dir, 'sr-update.tar')
            helpers.download_file(tar_download_url,
                                  tar_download_path,
                                  session=self.session)

            if not os.path.isfile(tar_download_path):
                logger.warning("Unable to retrieve new version from " +
                               tar_download_url + ", can't update")
                return False

            if not tarfile.is_tarfile(tar_download_path):
                logger.exception("Retrieved version from " + tar_download_url +
                                 " is corrupt, can't update")
                return False

            # extract to sr-update dir
            logger.info("Extracting file " + tar_download_path)
            tar = tarfile.open(tar_download_path)
            tar.extractall(sr_update_dir)
            tar.close()

            # delete .tar.gz
            logger.info("Deleting file " + tar_download_path)
            os.remove(tar_download_path)

            # find update dir name
            update_dir_contents = [
                x for x in os.listdir(sr_update_dir)
                if os.path.isdir(os.path.join(sr_update_dir, x))
            ]

            if len(update_dir_contents) != 1:
                logger.exception("Invalid update data, update failed: " +
                                 str(update_dir_contents))
                return False

            # walk temp folder and move files to main folder
            content_dir = os.path.join(sr_update_dir, update_dir_contents[0])
            logger.info("Moving files from " + content_dir + " to " +
                        os.path.dirname(settings.PROG_DIR))
            for dirname, stderr_, filenames in os.walk(content_dir):
                dirname = dirname[len(content_dir) + 1:]
                for curfile in filenames:
                    old_path = os.path.join(content_dir, dirname, curfile)
                    new_path = os.path.join(os.path.dirname(settings.PROG_DIR),
                                            dirname, curfile)

                    if os.path.isfile(new_path):
                        os.remove(new_path)
                    os.renames(old_path, new_path)

            settings.CUR_COMMIT_HASH = self._newest_commit_hash
            settings.CUR_COMMIT_BRANCH = self.branch

        except Exception as error:
            logger.exception("Error while trying to update: {}".format(error))
            logger.debug("Traceback: {}".format(traceback.format_exc()))
            return False

        self._clean_libs()

        # Notify update successful
        notifiers.notify_git_update(settings.CUR_COMMIT_HASH or "")
        return True