def update(self): """Call git pull origin <branch> in order to update the application. 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 self._is_hard_reset_allowed(): self.reset() # Executing git clean before updating self.clean() if self.branch == self._find_installed_branch(): _, _, exit_status = self._run_git(self._git_path, 'pull -f %s %s' % (app.GIT_REMOTE, self.branch)) else: _, _, exit_status = self._run_git(self._git_path, 'checkout -f ' + self.branch) # Executing git clean after updating self.clean() if exit_status == 0: self.update_commit_hash() # Notify update successful if app.NOTIFY_ON_UPDATE: try: notifiers.notify_git_update(app.CUR_COMMIT_HASH or '') except Exception: log.debug(u'Unable to send update notification. Continuing the update process') return True return False
def update(self): """Call git pull origin <branch> in order to update the application. 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 self._is_hard_reset_allowed(): self.reset() # Executing git clean before updating self.clean() if self.branch == self._find_installed_branch(): _, _, exit_status = self._run_git(self._git_path, 'pull -f %s %s' % (app.GIT_REMOTE, self.branch)) else: _, _, exit_status = self._run_git(self._git_path, 'checkout -f ' + self.branch) # Executing git clean after updating self.clean() if exit_status == 0: self.update_commit_hash() # Notify update successful if app.NOTIFY_ON_UPDATE: try: notifiers.notify_git_update(app.CUR_COMMIT_HASH or '') except Exception: log.debug(u'Unable to send update notification. Continuing the update process') return True return False
def update(self): """Call git pull origin <branch> in order to update the application. 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 self._is_hard_reset_allowed(): self.reset() # Executing git clean before updating self.clean() current_branch = self._find_installed_branch() if self.branch == current_branch: _, _, exit_status = self._run_git( self._git_path, 'pull -f {0} {1}'.format(app.GIT_REMOTE, self.branch)) else: log.warning( u"Couldn't determine current branch or current branch {current}" u" doesn't match desired branch {desired}.\n" u'Checkout the desired branch or try again later.', { 'current': current_branch, 'desired': self.branch }) return False # Executing git clean after updating self.clean() if exit_status == 0: self.update_commit_hash() # Notify update successful if app.NOTIFY_ON_UPDATE: try: notifiers.notify_git_update(app.CUR_COMMIT_HASH or '') except Exception: log.debug( u'Unable to send update notification. Continuing the update process' ) return True return False
def update(self): """Download the latest source tarball from github and installs it over the existing version.""" tar_download_url = 'http://github.com/' + self.github_org + '/' + self.github_repo + '/tarball/' + self.branch try: # prepare the update dir app_update_dir = os.path.join(app.PROG_DIR, u'medusa-update') if os.path.isdir(app_update_dir): log.info(u'Clearing out update folder {0!r} before extracting', app_update_dir) shutil.rmtree(app_update_dir) log.info(u'Clearing update folder {0!r} before extracting', app_update_dir) os.makedirs(app_update_dir) # retrieve file log.info(u'Downloading update from {0!r}', tar_download_url) tar_download_path = os.path.join(app_update_dir, u'medusa-update.tar') helpers.download_file(tar_download_url, tar_download_path, session=self.session) if not os.path.isfile(tar_download_path): log.warning( u"Unable to retrieve new version from {0!r}, can't update", tar_download_url) return False if not tarfile.is_tarfile(tar_download_path): log.warning( u"Retrieved version from {0!r} is corrupt, can't update", tar_download_url) return False # extract to medusa-update dir log.info(u'Extracting file {0}', tar_download_path) tar = tarfile.open(tar_download_path) tar.extractall(app_update_dir) tar.close() # delete .tar.gz log.info(u'Deleting file {0}', tar_download_path) os.remove(tar_download_path) # find update dir name update_dir_contents = [ x for x in os.listdir(app_update_dir) if os.path.isdir(os.path.join(app_update_dir, x)) ] if len(update_dir_contents) != 1: log.warning(u'Invalid update data, update failed: {0}', update_dir_contents) return False content_dir = os.path.join(app_update_dir, update_dir_contents[0]) # walk temp folder and move files to main folder log.info(u'Moving files from {0} to {1}', content_dir, app.PROG_DIR) for dirname, _, filenames in os.walk( content_dir): # @UnusedVariable dirname = dirname[len(content_dir) + 1:] for curfile in filenames: old_path = os.path.join(content_dir, dirname, curfile) new_path = os.path.join(app.PROG_DIR, dirname, curfile) # Avoid DLL access problem on WIN32/64 # These files needing to be updated manually # or find a way to kill the access from memory extension = os.path.splitext(curfile)[1] if extension == '.dll': try: log.debug(u'Special handling for {0}', curfile) os.chmod(new_path, stat.S_IWRITE) os.remove(new_path) os.renames(old_path, new_path) except Exception as e: log.debug(u'Unable to update {0}: {1!r}', new_path, e) os.remove( old_path ) # Trash the updated file without moving in new path continue if os.path.isfile(new_path): os.remove(new_path) os.renames(old_path, new_path) app.CUR_COMMIT_HASH = self._newest_commit_hash app.CUR_COMMIT_BRANCH = self.branch except Exception as e: log.exception(u'Error while trying to update: {0}', e) return False # Notify update successful try: notifiers.notify_git_update(app.CUR_COMMIT_HASH or '') except Exception: log.debug( u'Unable to send update notification. Continuing the update process' ) return True
def update(self): """Download the latest source tarball from github and installs it over the existing version.""" tar_download_url = 'http://github.com/' + self.github_org + '/' + self.github_repo + '/tarball/' + self.branch try: # prepare the update dir app_update_dir = os.path.join(app.PROG_DIR, u'medusa-update') if os.path.isdir(app_update_dir): log.info(u'Clearing out update folder {0!r} before extracting', app_update_dir) shutil.rmtree(app_update_dir) log.info(u'Clearing update folder {0!r} before extracting', app_update_dir) os.makedirs(app_update_dir) # retrieve file log.info(u'Downloading update from {0!r}', tar_download_url) tar_download_path = os.path.join(app_update_dir, u'medusa-update.tar') helpers.download_file(tar_download_url, tar_download_path, session=self.session) if not os.path.isfile(tar_download_path): log.warning(u"Unable to retrieve new version from {0!r}, can't update", tar_download_url) return False if not tarfile.is_tarfile(tar_download_path): log.warning(u"Retrieved version from {0!r} is corrupt, can't update", tar_download_url) return False # extract to medusa-update dir log.info(u'Extracting file {0}', tar_download_path) tar = tarfile.open(tar_download_path) tar.extractall(app_update_dir) tar.close() # delete .tar.gz log.info(u'Deleting file {0}', tar_download_path) os.remove(tar_download_path) # find update dir name update_dir_contents = [x for x in os.listdir(app_update_dir) if os.path.isdir(os.path.join(app_update_dir, x))] if len(update_dir_contents) != 1: log.warning(u'Invalid update data, update failed: {0}', update_dir_contents) return False content_dir = os.path.join(app_update_dir, update_dir_contents[0]) # walk temp folder and move files to main folder log.info(u'Moving files from {0} to {1}', content_dir, app.PROG_DIR) for dirname, _, filenames in os.walk(content_dir): # @UnusedVariable dirname = dirname[len(content_dir) + 1:] for curfile in filenames: old_path = os.path.join(content_dir, dirname, curfile) new_path = os.path.join(app.PROG_DIR, dirname, curfile) # Avoid DLL access problem on WIN32/64 # These files needing to be updated manually # or find a way to kill the access from memory extension = os.path.splitext(curfile)[1] if extension == '.dll': try: log.debug(u'Special handling for {0}', curfile) os.chmod(new_path, stat.S_IWRITE) os.remove(new_path) os.renames(old_path, new_path) except Exception as e: log.debug(u'Unable to update {0}: {1!r}', new_path, e) os.remove(old_path) # Trash the updated file without moving in new path continue if os.path.isfile(new_path): os.remove(new_path) os.renames(old_path, new_path) app.CUR_COMMIT_HASH = self._newest_commit_hash app.CUR_COMMIT_BRANCH = self.branch except Exception as e: log.exception(u'Error while trying to update: {0}', e) return False # Notify update successful try: notifiers.notify_git_update(app.CUR_COMMIT_HASH or '') except Exception: log.debug(u'Unable to send update notification. Continuing the update process') return True