Private GIT

Skip to content
Snippets Groups Projects
Commit a27ef187 authored by sharkykh's avatar sharkykh Committed by miigotu
Browse files

Add --force-update argument (#3591)

* Add --force-update argument

* Add git support, fallback to source when git fails
parent 4b5f21e3
No related branches found
No related tags found
No related merge requests found
...@@ -68,6 +68,7 @@ from sickbeard import db, logger, network_timezones, failed_history, name_cache ...@@ -68,6 +68,7 @@ from sickbeard import db, logger, network_timezones, failed_history, name_cache
from sickbeard.tv import TVShow from sickbeard.tv import TVShow
from sickbeard.webserveInit import SRWebServer from sickbeard.webserveInit import SRWebServer
from sickbeard.event_queue import Events from sickbeard.event_queue import Events
from sickbeard.versionChecker import SourceUpdateManager, GitUpdateManager
from configobj import ConfigObj # pylint: disable=import-error from configobj import ConfigObj # pylint: disable=import-error
from sickrage.helper.encoding import ek from sickrage.helper.encoding import ek
...@@ -173,6 +174,10 @@ class SickRage(object): ...@@ -173,6 +174,10 @@ class SickRage(object):
args = SickRageArgumentParser(sickbeard.PROG_DIR).parse_args() args = SickRageArgumentParser(sickbeard.PROG_DIR).parse_args()
if args.force_update:
result = self.force_update()
sys.exit(int(not result)) # Ok -> 0 , Error -> 1
# Need console logging for SickBeard.py and SickBeard-console.exe # Need console logging for SickBeard.py and SickBeard-console.exe
sickbeard.NO_RESIZE = args.noresize sickbeard.NO_RESIZE = args.noresize
self.console_logging = (not hasattr(sys, 'frozen')) or (sickbeard.MY_NAME.lower().find('-console') > 0) and not args.quiet self.console_logging = (not hasattr(sys, 'frozen')) or (sickbeard.MY_NAME.lower().find('-console') > 0) and not args.quiet
...@@ -488,6 +493,52 @@ class SickRage(object): ...@@ -488,6 +493,52 @@ class SickRage(object):
logger.shutdown() logger.shutdown()
os._exit(0) # pylint: disable=protected-access os._exit(0) # pylint: disable=protected-access
@staticmethod
def force_update():
"""
Forces SickRage to update to the latest version and exit.
:return: True if successful, False otherwise
"""
def update_with_git():
def run_git(updater, cmd):
stdout_, stderr_, exit_status = updater._run_git(updater._git_path, cmd)
if not exit_status == 0:
print('Failed to run command: {0} {1}'.format(updater._git_path, cmd))
return False
else:
return True
updater = GitUpdateManager()
if not run_git(updater, 'config remote.origin.url https://github.com/SickRage/SickRage.git'):
return False
if not run_git(updater, 'fetch origin'):
return False
if not run_git(updater, 'checkout master'):
return False
if not run_git(updater, 'reset --hard origin/master'):
return False
return True
if ek(os.path.isdir, ek(os.path.join, sickbeard.PROG_DIR, '.git')): # update with git
print('Forcing SickRage to update using git...')
result = update_with_git()
if result:
print('Successfully updated to latest commit. You may now run SickRage normally.')
return True
else:
print('Error while trying to force an update using git.')
print('Forcing SickRage to update using source...')
if not SourceUpdateManager().update():
print('Failed to force an update.')
return False
print('Successfully updated to latest commit. You may now run SickRage normally.')
return True
if __name__ == '__main__': if __name__ == '__main__':
# start SickRage # start SickRage
......
...@@ -837,19 +837,6 @@ class SourceUpdateManager(UpdateManager): ...@@ -837,19 +837,6 @@ class SourceUpdateManager(UpdateManager):
old_path = ek(os.path.join, content_dir, dirname, curfile) old_path = ek(os.path.join, content_dir, dirname, curfile)
new_path = ek(os.path.join, sickbeard.PROG_DIR, dirname, curfile) new_path = ek(os.path.join, sickbeard.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
if curfile in ('unrar.dll', 'unrar64.dll'):
try:
ek(os.chmod, new_path, stat.S_IWRITE)
ek(os.remove, new_path)
ek(os.renames, old_path, new_path)
except Exception as e:
logger.log("Unable to update " + new_path + ': ' + ex(e), logger.DEBUG)
ek(os.remove, old_path) # Trash the updated file without moving in new path
continue
if ek(os.path.isfile, new_path): if ek(os.path.isfile, new_path):
ek(os.remove, new_path) ek(os.remove, new_path)
ek(os.renames, old_path, new_path) ek(os.renames, old_path, new_path)
......
...@@ -34,3 +34,6 @@ class SickRageArgumentParser(ArgumentParser): ...@@ -34,3 +34,6 @@ class SickRageArgumentParser(ArgumentParser):
if sys.platform in ['win32', 'darwin']: if sys.platform in ['win32', 'darwin']:
daemon_help = 'running as daemon is not supported on your platform. it is substituted with: --quiet --nolaunch' daemon_help = 'running as daemon is not supported on your platform. it is substituted with: --quiet --nolaunch'
self.add_argument('-d', '--daemon', action='store_true', help=daemon_help) self.add_argument('-d', '--daemon', action='store_true', help=daemon_help)
self.add_argument('--force-update', action='store_true', help='download the latest stable version and force an '
'update (use when you\'re unable to do so using '
'the web ui)')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment