Skip to content

Commit

Permalink
Initial version_checker refactor (#6018)
Browse files Browse the repository at this point in the history
* Initial version_checker refactor

* Final changes

* Implement __str__

* Improve code

* Fix git detection

* Improve docs

* Update Docker update msg

* Update exceptions

* Fix test

* Use self.is_latest_version() only if branch is master

* Revert unnecessary change

* Review

* Update CHANGELOG.md
  • Loading branch information
medariox authored Jan 24, 2019
1 parent 967332c commit 64c35d7
Show file tree
Hide file tree
Showing 16 changed files with 1,138 additions and 1,061 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#### Improvements

#### Fixes
- Fixed saving newznab provider api key ([#5918](https://github.com/pymedusa/Medusa/pull/5918))
- Fixed saving newznab provider API key ([#5918](https://github.com/pymedusa/Medusa/pull/5918))
- Fixed permanent Docker update message ([#6018](https://github.com/pymedusa/Medusa/pull/6018))

-----

Expand Down
9 changes: 5 additions & 4 deletions medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from medusa import (
app, auto_post_processor, cache, db, event_queue, exception_handler,
helpers, logger as app_logger, metadata, name_cache, naming, network_timezones, providers,
scheduler, show_queue, show_updater, subtitles, torrent_checker, trakt_checker, version_checker
scheduler, show_queue, show_updater, subtitles, torrent_checker, trakt_checker
)
from medusa.common import SD, SKIPPED, WANTED
from medusa.config import (
Expand All @@ -90,6 +90,7 @@
from medusa.system.shutdown import Shutdown
from medusa.themes import read_themes
from medusa.tv import Series
from medusa.updater.version_checker import CheckVersion


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -987,9 +988,9 @@ def initialize(self, console_logging=True):
pass

if app.VERSION_NOTIFY:
updater = version_checker.CheckVersion().updater
updater = CheckVersion().updater
if updater:
app.APP_VERSION = updater.get_cur_version()
app.APP_VERSION = updater.current_version

app.MAJOR_DB_VERSION, app.MINOR_DB_VERSION = db.DBConnection().checkDBVersion()

Expand Down Expand Up @@ -1128,7 +1129,7 @@ def initialize(self, console_logging=True):

# initialize schedulers
# updaters
app.version_check_scheduler = scheduler.Scheduler(version_checker.CheckVersion(),
app.version_check_scheduler = scheduler.Scheduler(CheckVersion(),
cycleTime=datetime.timedelta(hours=app.UPDATE_FREQUENCY),
threadName='CHECKVERSION', silent=False)

Expand Down
2 changes: 1 addition & 1 deletion medusa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from medusa.helper.common import try_int
from medusa.helpers.utils import split_and_strip
from medusa.logger.adapters.style import BraceAdapter
from medusa.version_checker import CheckVersion
from medusa.updater.version_checker import CheckVersion

from requests.compat import urlsplit

Expand Down
18 changes: 18 additions & 0 deletions medusa/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,21 @@ def get_github_repo(organization, repo, gh=None):
except github.GithubException as e:
logger.debug('Unable to contact Github: {ex!r}', ex=e)
raise


def get_latest_release(organization, repo, gh=None):
"""Return the latest release of a repository.
:param repo:
:type repo: string
:param gh:
:type gh: Github
:return:
:rtype github.GitRelease.GitRelease
"""
try:
gh = gh or github.MainClass.Github(**OPTIONS)
return gh.get_organization(organization).get_repo(repo).get_latest_release()
except github.GithubException as e:
logger.debug('Unable to contact Github: {ex!r}', ex=e)
raise
4 changes: 2 additions & 2 deletions medusa/server/api/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from medusa.show.show import Show
from medusa.system.restart import Restart
from medusa.system.shutdown import Shutdown
from medusa.version_checker import CheckVersion
from medusa.updater.version_checker import CheckVersion

from requests.compat import unquote_plus

Expand Down Expand Up @@ -1421,7 +1421,7 @@ def run(self):
'commit': check_version.updater.get_newest_commit_hash(),
'version': check_version.updater.get_newest_version(),
},
'commits_offset': check_version.updater.get_num_commits_behind(),
'commits_offset': check_version.updater.commits_behind,
'needs_update': needs_update,
}

Expand Down
2 changes: 1 addition & 1 deletion medusa/server/web/core/error_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from medusa.issue_submitter import IssueSubmitter
from medusa.logger import filter_logline, read_loglines
from medusa.server.web.core.base import PageTemplate, WebRoot
from medusa.version_checker import CheckVersion
from medusa.updater.version_checker import CheckVersion

from six import text_type

Expand Down
2 changes: 1 addition & 1 deletion medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
from medusa.system.restart import Restart
from medusa.system.shutdown import Shutdown
from medusa.tv.series import Series, SeriesIdentifier
from medusa.version_checker import CheckVersion
from medusa.updater.version_checker import CheckVersion

from requests.compat import (
quote_plus,
Expand Down
1 change: 1 addition & 0 deletions medusa/updater/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# coding=utf-8
54 changes: 54 additions & 0 deletions medusa/updater/docker_updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# coding=utf-8

from __future__ import unicode_literals

import logging

from medusa import app
from medusa.logger.adapters.style import BraceAdapter
from medusa.updater.source_updater import SourceUpdateManager


log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())


class DockerUpdateManager(SourceUpdateManager):
def __init__(self):
super(DockerUpdateManager, self).__init__()

def __str__(self):
return 'Docker Updater'

def need_update(self):
if self.branch != self._find_installed_branch():
log.debug(u'Branch checkout: {0}->{1}', self._find_installed_branch(), self.branch)
return True

if self.branch == 'master' and not self.is_latest_version():
self._set_update_text()
return True

return False

def can_update(self):
"""Whether or not the update can be performed.
:return:
:rtype: bool
"""
return False

def _set_update_text(self):
"""Set an update text, when running in a Docker container."""
log.debug('There is an update available, Medusa is running in a Docker container,'
' so auto updating is disabled.')

url = 'http://github.com/' + self.github_org + '/' + self.github_repo + '/releases'
newest_text = 'There is a <a href="' + url + '" onclick="window.open(this.href); return false;">newer version available</a>'
newest_text += ' (' + self.newest_version + ') &mdash; Pull the latest Docker image and rebuild your container to update'
app.NEWEST_VERSION_STRING = newest_text

def update(self):
"""Download the latest version."""
return False
Loading

0 comments on commit 64c35d7

Please sign in to comment.