mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 13:41:15 -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
|
@ -246,6 +246,8 @@ def main():
|
|||
plexpy.shutdown()
|
||||
elif plexpy.SIGNAL == 'restart':
|
||||
plexpy.shutdown(restart=True)
|
||||
elif plexpy.SIGNAL == 'checkout':
|
||||
plexpy.shutdown(restart=True, checkout=True)
|
||||
else:
|
||||
plexpy.shutdown(restart=True, update=True)
|
||||
|
||||
|
|
|
@ -60,6 +60,28 @@ select[multiple] option {
|
|||
-moz-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
select.form-control {
|
||||
margin: 5px 0 5px 0;
|
||||
color: #fff;
|
||||
border: 0px solid #444;
|
||||
background: #555;
|
||||
height: 32px;
|
||||
padding: 6px 12px;
|
||||
background-color: #555;
|
||||
border-radius: 3px;
|
||||
transition: background-color .3s;
|
||||
}
|
||||
select.form-control:focus {
|
||||
outline: 0;
|
||||
outline: thin dotted \9;
|
||||
color: #555;
|
||||
background-color: #fff;
|
||||
transition: background-color .3s;
|
||||
}
|
||||
select.form-control option {
|
||||
color: #555;
|
||||
background-color: #fff;
|
||||
}
|
||||
img {
|
||||
-webkit-box-sizing: content-box;
|
||||
-moz-box-sizing: content-box;
|
||||
|
@ -3118,3 +3140,9 @@ a:hover .overlay-refresh-image:hover {
|
|||
border: 1px solid #444;
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
.git-group input.form-control {
|
||||
width: 40%;
|
||||
}
|
||||
.git-group select.form-control {
|
||||
width: 60%;
|
||||
}
|
|
@ -82,7 +82,7 @@
|
|||
<label>
|
||||
<input type="checkbox" id="check_github" name="check_github" value="1" ${config['check_github']}> Enable Updates
|
||||
</label>
|
||||
<p class="help-block">If you have Git installed, allow periodic checks for updates.</p>
|
||||
<p class="help-block">Check for PlexPy updates periodically.</p>
|
||||
</div>
|
||||
<div id="git_update_options">
|
||||
<div class="checkbox">
|
||||
|
@ -101,6 +101,44 @@
|
|||
<p class="help-block">Optional: Use your own GitHub API token when checking for updates.
|
||||
</div>
|
||||
</div>
|
||||
% if plexpy.INSTALL_TYPE == 'git':
|
||||
<div class="form-group">
|
||||
<label for="git_branch">Git Remote / Branch</label>
|
||||
<div class="row">
|
||||
<div class="col-md-7">
|
||||
<div class="input-group git-group">
|
||||
<input type="text" class="form-control" id="git_remote" name="git_remote" value="${config['git_remote']}" data-parsley-trigger="change">
|
||||
<select class="form-control" id="git_branch" name="git_branch">
|
||||
% if config['git_branch'] == 'master':
|
||||
<option value="master" selected>master</option>
|
||||
<option value="dev">dev</option>
|
||||
% elif config['git_branch'] == 'dev':
|
||||
<option value="master">master</option>
|
||||
<option value="dev" selected>dev</option>
|
||||
% else:
|
||||
<option value="master">master</option>
|
||||
<option value="dev">dev</option>
|
||||
<option value="${config['git_branch']}" selected>${config['git_branch']}</option>
|
||||
% endif
|
||||
</select>
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-form" type="button" id="switch_git_branch">Checkout Branch</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">The git tracking remote (default "origin") and branch (default "master"). Select to switch the git branch (requires restart).</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="git_path">Git Path</label>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<input type="text" class="form-control" id="git_path" name="git_path" value="${config['git_path']}" size="30">
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">The path to your git environment variable. Leave blank for default.</p>
|
||||
</div>
|
||||
% endif
|
||||
|
||||
<div class="padded-header">
|
||||
<h3>Display Settings</h3>
|
||||
|
@ -2033,32 +2071,32 @@ $(document).ready(function() {
|
|||
initConfigCheckbox('#notify_upload_posters');
|
||||
initConfigCheckbox('#monitor_pms_updates');
|
||||
|
||||
$("#menu_link_shutdown").click(function() {
|
||||
$("#confirm-message").text("Are you sure you want to shutdown PlexPy?");
|
||||
$('#menu_link_shutdown').click(function() {
|
||||
$('#confirm-message').text("Are you sure you want to shutdown PlexPy?");
|
||||
$('#confirm-modal').modal();
|
||||
$('#confirm-modal').one('click', '#confirm-button', function () {
|
||||
window.location.href = "shutdown";
|
||||
window.location.href = 'shutdown';
|
||||
});
|
||||
});
|
||||
|
||||
$("#menu_link_restart").click(function() {
|
||||
$('#menu_link_restart').click(function() {
|
||||
$("#confirm-message").text("Are you sure you want to restart PlexPy?");
|
||||
$('#confirm-modal').modal();
|
||||
$('#confirm-modal').one('click', '#confirm-button', function () {
|
||||
window.location.href = "restart";
|
||||
window.location.href = 'restart';
|
||||
});
|
||||
});
|
||||
|
||||
$("#menu_link_update_check").click(function() {
|
||||
$('#menu_link_update_check').click(function() {
|
||||
// Allow the update bar to show again if previously dismissed.
|
||||
setCookie('updateDismiss', 'true', 0);
|
||||
$(this).html('<i class="fa fa-spin fa-refresh"></i> Checking');
|
||||
$(this).prop('disabled', true);
|
||||
window.location.href = "checkGithub";
|
||||
window.location.href = 'checkGithub';
|
||||
});
|
||||
|
||||
$("#modal_link_restart").click(function() {
|
||||
window.location.href = "restart";
|
||||
$('#modal_link_restart').click(function() {
|
||||
window.location.href = 'restart';
|
||||
});
|
||||
|
||||
getConfigurationTable();
|
||||
|
@ -2114,6 +2152,26 @@ $(document).ready(function() {
|
|||
confirmAjaxCall(url, msg);
|
||||
});
|
||||
|
||||
$("#switch_git_branch").click(function () {
|
||||
var current_remote = "${config['git_remote']}";
|
||||
var current_branch = "${config['git_branch']}";
|
||||
var new_remote = $("#git_remote").val();
|
||||
var new_branch = $("#git_branch option:selected").val();
|
||||
|
||||
if (new_remote === current_remote && new_branch === current_branch) {
|
||||
showMsg('<i class="fa fa-exclamation-circle"></i> Already on the ' + current_remote + ' ' + current_branch + ' branch.', false, true, 5000, true)
|
||||
} else {
|
||||
var msg = 'Are you sure you want to switch to the <strong>' + new_remote + ' ' + new_branch + '</strong> branch?' +
|
||||
'<br />This may cause PlexPy to become unstable.<br />PlexPy will restart.';
|
||||
$('#confirm-message').html(msg);
|
||||
$('#confirm-modal').modal();
|
||||
$('#confirm-modal').one('click', '#confirm-button', function () {
|
||||
settingsChanged = false;
|
||||
window.location.href = 'checkout_git_branch?git_remote=' + new_remote + '&git_branch=' + new_branch;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#api_key').click(function(){ $('#api_key').select() });
|
||||
$("#generate_api").click(function() {
|
||||
$.get('generateAPI',
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">${message}</h4>
|
||||
<h4 class="modal-title">${title}</h4>
|
||||
</div>
|
||||
<div class="modal-body" id="modal-text">
|
||||
<div align="center">
|
||||
|
|
|
@ -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