Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (master/develop) branch checkout from config-general #8399

Merged
merged 25 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
78aeab7
Add apiv2 config operation route, for switching branch.
p0psicles Aug 26, 2020
cb7b46b
Do not initiate a restart.
p0psicles Aug 26, 2020
12c1494
Change notification message.
p0psicles Aug 27, 2020
dda0ffa
Remove updating from log message.
p0psicles Aug 27, 2020
db87366
github_updater.py: Add set-remote, to also be able to update other br…
p0psicles Aug 27, 2020
a28340b
Fix checking out branch.
p0psicles Aug 27, 2020
1152059
Disable the actual switch branch.
p0psicles Aug 28, 2020
b423d22
Move Restart to vue component
p0psicles Aug 29, 2020
803d785
Move shutdown to apiv2.
p0psicles Aug 29, 2020
fdc2686
Remove all the commended code.
p0psicles Aug 29, 2020
b4ec23b
Add modal.css
p0psicles Aug 29, 2020
6226c1c
increase timeout.
p0psicles Aug 29, 2020
cad4b9c
Remove result, as i'm not using it "yet".
p0psicles Aug 29, 2020
9d5a9a2
remove restart.mako
p0psicles Aug 29, 2020
45600ee
Add restart.vue component.
p0psicles Aug 30, 2020
567aa0f
Move operation 'CHECKOUT_BRANCH' to system handler.
p0psicles Aug 30, 2020
1f88010
Fix remote github branches sometime not loading.
p0psicles Aug 30, 2020
f070992
Fix system handler.
p0psicles Aug 30, 2020
9e6bafb
Fix lint errors
p0psicles Aug 30, 2020
4afe53f
Revert trailing comma.
p0psicles Aug 30, 2020
c2a84c6
Fix git branches not shown when navigating from other page through ro…
p0psicles Aug 31, 2020
ecc8435
Merge branch 'develop' of https://github.com/pymedusa/Medusa into fea…
p0psicles Aug 31, 2020
1408f3d
bundle runtime
p0psicles Aug 31, 2020
24d5b96
(re)load the default page after a restart.
p0psicles Sep 1, 2020
d8c2995
fix hard browser reload on chrome
p0psicles Sep 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ConfigHandler(BaseRequestHandler):
#: path param
path_param = ('path_param', r'\w+')
#: allowed HTTP methods
allowed_methods = ('GET', 'PATCH', )
allowed_methods = ('GET', 'PATCH',)
#: patch mapping
patches = {
# Main
Expand Down Expand Up @@ -552,11 +552,10 @@ def patch(self, identifier, *args, **kwargs):
app.instance.save_config()

# Push an update to any open Web UIs through the WebSocket
msg = ws.Message('configUpdated', {
ws.Message('configUpdated', {
'section': identifier,
'config': DataGenerator.get_data(identifier)
})
msg.push()
}).push()

return self._ok(data=accepted)

Expand Down
70 changes: 70 additions & 0 deletions medusa/server/api/v2/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# coding=utf-8
"""Request handler for statistics."""
from __future__ import unicode_literals

from medusa import app, ui
from medusa.server.api.v2.base import BaseRequestHandler
from medusa.system.restart import Restart
from medusa.system.shutdown import Shutdown
from medusa.updater.version_checker import CheckVersion

from tornado.escape import json_decode


class SystemHandler(BaseRequestHandler):
"""System operation calls request handler."""

#: resource name
name = 'system'
#: identifier
identifier = ('identifier', r'\w+')
#: path param
path_param = None
#: allowed HTTP methods
allowed_methods = ('POST', )

def post(self, identifier, *args, **kwargs):
"""Perform an operation on the config."""
if identifier != 'operation':
return self._bad_request('Invalid operation')

data = json_decode(self.request.body)

if data['type'] == 'RESTART' and data['pid']:
if not Restart.restart(data['pid']):
self._not_found('Pid does not match running pid')
return self._created()

if data['type'] == 'SHUTDOWN' and data['pid']:
if not Shutdown.stop(data['pid']):
self._not_found('Pid does not match running pid')
return self._created()

if data['type'] == 'CHECKOUT_BRANCH' and data['branch']:
if app.BRANCH != data['branch']:
app.BRANCH = data['branch']
ui.notifications.message('Checking out branch: ', data['branch'])

if self._update(data['branch']):
return self._created()
else:
return self._bad_request('Update failed')
else:
ui.notifications.message('Already on branch: ', data['branch'])
return self._bad_request('Already on branch')

return self._bad_request('Invalid operation')

def _update(self, branch):
checkversion = CheckVersion()
backup = checkversion.updater and checkversion._runbackup() # pylint: disable=protected-access

if backup is True:
if branch:
checkversion.updater.branch = branch

if checkversion.updater.need_update() and checkversion.updater.update():
return True
else:
ui.notifications.message("Update wasn't successful. Check your log for more information.", branch)
return False
4 changes: 4 additions & 0 deletions medusa/server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from medusa.server.api.v2.series_legacy import SeriesLegacyHandler
from medusa.server.api.v2.series_operation import SeriesOperationHandler
from medusa.server.api.v2.stats import StatsHandler
from medusa.server.api.v2.system import SystemHandler
from medusa.server.web import (
CalendarHandler,
KeyHandler,
Expand Down Expand Up @@ -127,6 +128,9 @@ def get_apiv2_handlers(base):
# /api/v2/alias
AliasHandler.create_app_handler(base),

# /api/v2/system
SystemHandler.create_app_handler(base),

# /api/v2/authenticate
AuthHandler.create_app_handler(base),

Expand Down
28 changes: 12 additions & 16 deletions medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
WebRoot,
)
from medusa.show.show import Show
from medusa.system.restart import Restart
from medusa.system.shutdown import Shutdown
from medusa.tv.cache import Cache
from medusa.tv.series import Series, SeriesIdentifier
from medusa.updater.version_checker import CheckVersion
Expand Down Expand Up @@ -596,23 +594,21 @@ def status(self):
tvdirFree=tv_dir_free, rootDir=root_dir,
controller='home', action='status')

def shutdown(self, pid=None):
if not Shutdown.stop(pid):
return self.redirect('/{page}/'.format(page=app.DEFAULT_PAGE))

title = 'Shutting down'
message = 'Medusa is shutting down...'

return self._genericMessage(title, message)
def restart(self):
"""
Render the restart page.

def restart(self, pid=None):
if not Restart.restart(pid):
return self.redirect('/{page}/'.format(page=app.DEFAULT_PAGE))
[Converted to VueRouter]
"""
return PageTemplate(rh=self, filename='index.mako').render()

t = PageTemplate(rh=self, filename='restart.mako')
def shutdown(self):
"""
Render the shutdown page.

return t.render(title='Home', header='Restarting Medusa',
controller='home', action='restart')
[Converted to VueRouter]
"""
return PageTemplate(rh=self, filename='index.mako').render()

def updateCheck(self, pid=None):
if text_type(pid) != text_type(app.PID):
Expand Down
16 changes: 11 additions & 5 deletions medusa/updater/github_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@ def update_newest_commit_hash(self):
# update remote origin url
self.update_remote_origin()

# Configure local branch with upstream
self.set_upstream_branch()

# get all new info from github
output, _, exit_status = self._run_git(self._git_path, 'fetch --prune %s' % app.GIT_REMOTE)
output, _, exit_status = self._run_git(self._git_path, 'fetch --prune {0}'.format(app.GIT_REMOTE))
if not exit_status == 0:
log.warning(u"Unable to contact github, can't check for update")
return False
Expand Down Expand Up @@ -308,7 +311,7 @@ def update(self):
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))
_, _, exit_status = self._run_git(self._git_path, 'pull -f {0} {1}'.format(app.GIT_REMOTE, self.branch))
else:
_, _, exit_status = self._run_git(self._git_path, 'checkout -f ' + self.branch)

Expand Down Expand Up @@ -363,12 +366,15 @@ def list_remote_branches(self):
self.update_remote_origin()
app.BRANCH = self._find_installed_branch()

branches, _, exit_status = self._run_git(self._git_path, 'ls-remote --heads %s' % app.GIT_REMOTE)
branches, _, exit_status = self._run_git(self._git_path, 'ls-remote --heads {0}'.format(app.GIT_REMOTE))
if exit_status == 0 and branches:
if branches:
return re.findall(r'refs/heads/(.*)', branches)
return []

def update_remote_origin(self):
self._run_git(self._git_path, 'config remote.%s.url %s' % (app.GIT_REMOTE, app.GIT_REMOTE_URL))
self._run_git(self._git_path, 'config remote.%s.pushurl %s' % (app.GIT_REMOTE, app.GIT_REMOTE_URL))
self._run_git(self._git_path, 'config remote.{0}.url {1}'.format(app.GIT_REMOTE, app.GIT_REMOTE_URL))
self._run_git(self._git_path, 'config remote.{0}.pushurl {1}'.format(app.GIT_REMOTE, app.GIT_REMOTE_URL))

def set_upstream_branch(self):
self._run_git(self._git_path, 'branch {0} --set-upstream-to origin/{1}'.format(app.BRANCH, app.BRANCH))
10 changes: 5 additions & 5 deletions medusa/updater/version_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ def _runbackup(self):
os.mkdir(backupDir)

if self._keeplatestbackup(backupDir) and self._backup(backupDir):
log.info(u'Config backup successful, updating...')
ui.notifications.message('Backup', 'Config backup successful, updating...')
log.info(u'Config backup successful')
ui.notifications.message('Backup', 'Config backup successful')
return True
else:
log.warning(u'Config backup failed, aborting update')
ui.notifications.message('Backup', 'Config backup failed, aborting update')
log.warning(u'Config backup failed')
ui.notifications.message('Backup', 'Config backup failed')
return False
except Exception as e:
log.error(u'Update: Config backup failed. Error: {0!r}', e)
ui.notifications.message('Backup', 'Config backup failed, aborting update')
ui.notifications.message('Backup', 'Config backup failed')
return False

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions themes-default/slim/src/components/app-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
<li><app-link href="errorlogs/viewlog/"><i class="menu-icon-viewlog" />&nbsp;View Log</app-link></li>
<li role="separator" class="divider" />
<li><app-link :href="`home/updateCheck?pid=${system.pid}`"><i class="menu-icon-update" />&nbsp;Check For Updates</app-link></li>
<li><app-link :href="`home/restart/?pid=${system.pid}`" @click.native.prevent="confirmDialog($event, 'restart')"><i class="menu-icon-restart" />&nbsp;Restart</app-link></li>
<li><app-link :href="`home/shutdown/?pid=${system.pid}`" @click.native.prevent="confirmDialog($event, 'shutdown')"><i class="menu-icon-shutdown" />&nbsp;Shutdown</app-link></li>
<li><app-link :href="'home/restart'"><i class="menu-icon-restart" />&nbsp;Restart</app-link></li>
<li><app-link :href="'home/shutdown'" @click.prevent="$router.push({ name: 'shutdown' });"><i class="menu-icon-shutdown" />&nbsp;Shutdown</app-link></li>
<li v-if="username"><app-link href="logout" @click.native.prevent="confirmDialog($event, 'logout')"><i class="menu-icon-shutdown" />&nbsp;Logout</app-link></li>
<li role="separator" class="divider" />
<li><app-link href="home/status/"><i class="menu-icon-info" />&nbsp;Server Status</app-link></li>
Expand Down
Loading