mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 21:03:21 -07:00
Add option to switch the git remote and branch
This commit is contained in:
parent
91716527a4
commit
d1551bd8c7
8 changed files with 169 additions and 29 deletions
|
@ -170,7 +170,7 @@ def initialize(config_file):
|
|||
|
||||
# Get the currently installed version. Returns None, 'win32' or the git
|
||||
# hash.
|
||||
CURRENT_VERSION, CONFIG.GIT_BRANCH = versioncheck.getVersion()
|
||||
CURRENT_VERSION, CONFIG.GIT_REMOTE, CONFIG.GIT_BRANCH = versioncheck.getVersion()
|
||||
|
||||
# Write current version to a file, so we know which version did work.
|
||||
# This allowes one to restore to that version. The idea is that if we
|
||||
|
@ -1028,13 +1028,13 @@ def upgrade():
|
|||
if CONFIG.UPDATE_NOTIFIERS_DB:
|
||||
notifiers.upgrade_config_to_db()
|
||||
|
||||
def shutdown(restart=False, update=False):
|
||||
def shutdown(restart=False, update=False, checkout=False):
|
||||
cherrypy.engine.exit()
|
||||
SCHED.shutdown(wait=False)
|
||||
|
||||
CONFIG.write()
|
||||
|
||||
if not restart and not update:
|
||||
if not restart and not update and not checkout:
|
||||
logger.info(u"PlexPy is shutting down...")
|
||||
|
||||
if update:
|
||||
|
@ -1044,6 +1044,13 @@ def shutdown(restart=False, update=False):
|
|||
except Exception as e:
|
||||
logger.warn(u"PlexPy failed to update: %s. Restarting." % e)
|
||||
|
||||
if checkout:
|
||||
logger.info(u"PlexPy is switching the git branch...")
|
||||
try:
|
||||
versioncheck.checkout_git_branch()
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy failed to switch git branch: %s. Restarting." % e)
|
||||
|
||||
if CREATEPID:
|
||||
logger.info(u"Removing pidfile %s", PIDFILE)
|
||||
os.remove(PIDFILE)
|
||||
|
|
|
@ -170,6 +170,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'GET_FILE_SIZES_HOLD': (dict, 'General', {'section_ids': [], 'rating_keys': []}),
|
||||
'GIT_BRANCH': (str, 'General', 'master'),
|
||||
'GIT_PATH': (str, 'General', ''),
|
||||
'GIT_REMOTE': (str, 'General', 'origin'),
|
||||
'GIT_TOKEN': (str, 'General', ''),
|
||||
'GIT_USER': (str, 'General', 'JonnyWong16'),
|
||||
'GRAPH_TYPE': (str, 'General', 'plays'),
|
||||
|
|
|
@ -69,7 +69,7 @@ def getVersion():
|
|||
plexpy.INSTALL_TYPE = 'win'
|
||||
|
||||
# Don't have a way to update exe yet, but don't want to set VERSION to None
|
||||
return 'Windows Install', 'master'
|
||||
return 'Windows Install', 'origin', 'master'
|
||||
|
||||
elif os.path.isdir(os.path.join(plexpy.PROG_DIR, '.git')):
|
||||
|
||||
|
@ -77,30 +77,41 @@ def getVersion():
|
|||
output, err = runGit('rev-parse HEAD')
|
||||
|
||||
if not output:
|
||||
logger.error('Couldn\'t find latest installed version.')
|
||||
logger.error('Could not find latest installed version.')
|
||||
cur_commit_hash = None
|
||||
|
||||
cur_commit_hash = str(output)
|
||||
|
||||
if not re.match('^[a-z0-9]+$', cur_commit_hash):
|
||||
logger.error('Output doesn\'t look like a hash, not using it')
|
||||
logger.error('Output does not look like a hash, not using it.')
|
||||
cur_commit_hash = None
|
||||
|
||||
if plexpy.CONFIG.DO_NOT_OVERRIDE_GIT_BRANCH and plexpy.CONFIG.GIT_BRANCH:
|
||||
branch_name = plexpy.CONFIG.GIT_BRANCH
|
||||
|
||||
else:
|
||||
branch_name, err = runGit('rev-parse --abbrev-ref HEAD')
|
||||
branch_name = branch_name
|
||||
remote_branch, err = runGit('rev-parse --abbrev-ref --symbolic-full-name @{u}')
|
||||
remote_branch = remote_branch.split('/')
|
||||
if len(remote_branch) == 2:
|
||||
remote_name, branch_name = remote_branch
|
||||
else:
|
||||
remote_name = branch_name = None
|
||||
|
||||
if not remote_name and plexpy.CONFIG.GIT_REMOTE:
|
||||
logger.error('Could not retrieve remote name from git. Falling back to %s.' % plexpy.CONFIG.GIT_REMOTE)
|
||||
remote_name = plexpy.CONFIG.GIT_REMOTE
|
||||
if not remote_name:
|
||||
logger.error('Could not retrieve remote name from git. Defaulting to origin.')
|
||||
branch_name = 'origin'
|
||||
|
||||
if not branch_name and plexpy.CONFIG.GIT_BRANCH:
|
||||
logger.error('Could not retrieve branch name from git. Falling back to %s' % plexpy.CONFIG.GIT_BRANCH)
|
||||
logger.error('Could not retrieve branch name from git. Falling back to %s.' % plexpy.CONFIG.GIT_BRANCH)
|
||||
branch_name = plexpy.CONFIG.GIT_BRANCH
|
||||
if not branch_name:
|
||||
logger.error('Could not retrieve branch name from git. Defaulting to master')
|
||||
logger.error('Could not retrieve branch name from git. Defaulting to master.')
|
||||
branch_name = 'master'
|
||||
|
||||
return cur_commit_hash, branch_name
|
||||
return cur_commit_hash, remote_name, branch_name
|
||||
|
||||
else:
|
||||
|
||||
|
@ -109,15 +120,15 @@ def getVersion():
|
|||
version_file = os.path.join(plexpy.PROG_DIR, 'version.txt')
|
||||
|
||||
if not os.path.isfile(version_file):
|
||||
return None, 'master'
|
||||
return None, 'origin', 'master'
|
||||
|
||||
with open(version_file, 'r') as f:
|
||||
current_version = f.read().strip(' \n\r')
|
||||
|
||||
if current_version:
|
||||
return current_version, plexpy.CONFIG.GIT_BRANCH
|
||||
return current_version, plexpy.CONFIG.GIT_REMOTE, plexpy.CONFIG.GIT_BRANCH
|
||||
else:
|
||||
return None, 'master'
|
||||
return None, 'origin', 'master'
|
||||
|
||||
|
||||
def checkGithub(auto_update=False):
|
||||
|
@ -184,17 +195,18 @@ def update():
|
|||
logger.info('Windows .exe updating not supported yet.')
|
||||
|
||||
elif plexpy.INSTALL_TYPE == 'git':
|
||||
output, err = runGit('pull origin ' + plexpy.CONFIG.GIT_BRANCH)
|
||||
output, err = runGit('pull ' + plexpy.CONFIG.GIT_REMOTE + ' ' + plexpy.CONFIG.GIT_BRANCH)
|
||||
|
||||
if not output:
|
||||
logger.error('Couldn\'t download latest version')
|
||||
logger.error('Unable to download latest version')
|
||||
return
|
||||
|
||||
for line in output.split('\n'):
|
||||
|
||||
if 'Already up-to-date.' in line:
|
||||
logger.info('No update available, not updating')
|
||||
logger.info('Output: ' + str(output))
|
||||
elif line.endswith('Aborting.'):
|
||||
elif line.endswith(('Aborting', 'Aborting.')):
|
||||
logger.error('Unable to update from git: ' + line)
|
||||
logger.info('Output: ' + str(output))
|
||||
|
||||
|
@ -256,6 +268,22 @@ def update():
|
|||
)
|
||||
return
|
||||
|
||||
|
||||
def checkout_git_branch():
|
||||
if plexpy.INSTALL_TYPE == 'git':
|
||||
output, err = runGit('fetch ' + plexpy.CONFIG.GIT_REMOTE)
|
||||
output, err = runGit('checkout ' + plexpy.CONFIG.GIT_BRANCH)
|
||||
|
||||
if not output:
|
||||
logger.error('Unable to change git branch.')
|
||||
return
|
||||
|
||||
for line in output.split('\n'):
|
||||
if line.endswith(('Aborting', 'Aborting.')):
|
||||
logger.error('Unable to checkout from git: ' + line)
|
||||
logger.info('Output: ' + str(output))
|
||||
|
||||
|
||||
def read_changelog(latest_only=False):
|
||||
|
||||
changelog_file = os.path.join(plexpy.PROG_DIR, 'CHANGELOG.md')
|
||||
|
|
|
@ -2588,7 +2588,10 @@ class WebInterface(object):
|
|||
"imgur_client_id": plexpy.CONFIG.IMGUR_CLIENT_ID,
|
||||
"cache_images": checked(plexpy.CONFIG.CACHE_IMAGES),
|
||||
"pms_version": plexpy.CONFIG.PMS_VERSION,
|
||||
"plexpy_auto_update": checked(plexpy.CONFIG.PLEXPY_AUTO_UPDATE)
|
||||
"plexpy_auto_update": checked(plexpy.CONFIG.PLEXPY_AUTO_UPDATE),
|
||||
"git_branch": plexpy.CONFIG.GIT_BRANCH,
|
||||
"git_path": plexpy.CONFIG.GIT_PATH,
|
||||
"git_remote": plexpy.CONFIG.GIT_REMOTE
|
||||
}
|
||||
|
||||
return serve_template(templatename="settings.html", title="Settings", config=config, kwargs=kwargs)
|
||||
|
@ -3342,6 +3345,19 @@ class WebInterface(object):
|
|||
plexpy.CONFIG.write()
|
||||
return self.do_state_change('update', 'Updating', 120)
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
def checkout_git_branch(self, git_remote=None, git_branch=None, **kwargs):
|
||||
if git_branch == plexpy.CONFIG.GIT_BRANCH:
|
||||
logger.error(u"Already on the %s branch" % git_branch)
|
||||
raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "home")
|
||||
|
||||
# Set the new git remote and branch
|
||||
plexpy.CONFIG.__setattr__('GIT_REMOTE', git_remote)
|
||||
plexpy.CONFIG.__setattr__('GIT_BRANCH', git_branch)
|
||||
plexpy.CONFIG.write()
|
||||
return self.do_state_change('checkout', 'Switching Git Branches', 120)
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
def get_changelog(self, latest_only=False, update_shown=False, **kwargs):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue