Exemple #1
0
    def getDBcompare():
        checkversion = CheckVersion()  # @TODO: replace with settings var
        db_status = checkversion.getDBcompare()

        if db_status == 'upgrade':
            logger.log(u'Checkout branch has a new DB version - Upgrade',
                       logger.DEBUG)
            return json.dumps({
                'status': 'success',
                'message': 'upgrade',
            })
        elif db_status == 'equal':
            logger.log(u'Checkout branch has the same DB version - Equal',
                       logger.DEBUG)
            return json.dumps({
                'status': 'success',
                'message': 'equal',
            })
        elif db_status == 'downgrade':
            logger.log(u'Checkout branch has an old DB version - Downgrade',
                       logger.DEBUG)
            return json.dumps({
                'status': 'success',
                'message': 'downgrade',
            })
        else:
            logger.log(u"Checkout branch couldn't compare DB version.",
                       logger.WARNING)
            return json.dumps({
                'status': 'error',
                'message': 'General exception',
            })
Exemple #2
0
    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._backup():
                    if self._update(data['branch']):
                        return self._created()
                    else:
                        return self._bad_request('Update failed')
                    return self._bad_request('Backup failed')
            else:
                ui.notifications.message('Already on branch: ', data['branch'])
                return self._bad_request('Already on branch')

        if data['type'] == 'NEED_UPDATE':
            if self._need_update():
                return self._created()
            else:
                return self._bad_request('Update not needed')

        if data['type'] == 'UPDATE':
            if self._update():
                return self._created()
            else:
                return self._bad_request('Update failed')

        if data['type'] == 'BACKUP':
            if self._backup():
                return self._created()
            else:
                return self._bad_request('Backup failed')

        if data['type'] == 'CHECKFORUPDATE':
            check_version = CheckVersion()
            if check_version.check_for_new_version():
                return self._created()
            else:
                return self._bad_request('Version already up to date')

        return self._bad_request('Invalid operation')
    def _backup(self, branch=None):
        checkversion = CheckVersion()
        backup = checkversion.updater and checkversion._runbackup()  # pylint: disable=protected-access

        if backup is True:
            return True
        else:
            ui.notifications.message(
                'Update failed{branch}'.format(
                    branch=' for branch {0}'.format(branch) if branch else ''),
                'Check logs for more information.')

        return False
Exemple #4
0
def change_GIT_PATH(path):
    """
    Recreate the version_check scheduler when GIT_PATH is changed.

    Force a run to clear or set any error messages.
    """
    if app._GIT_PATH == path:
        return

    app._GIT_PATH = path

    if app.version_check_scheduler:
        app.version_check_scheduler.stop.set()
        app.version_check_scheduler.join(10)
        app.version_check_scheduler = None

    app.version_check_scheduler = scheduler.Scheduler(
        CheckVersion(),
        cycleTime=datetime.timedelta(hours=app._UPDATE_FREQUENCY),
        threadName='CHECKVERSION',
        silent=False)

    app.version_check_scheduler.enable = True
    app.version_check_scheduler.start()
    app.version_check_scheduler.forceRun()
Exemple #5
0
    def submit_errors(self):
        """Create an issue in medusa issue tracker."""
        results = self.issue_submitter.submit_github_issue(CheckVersion())
        for submitter_result, issue_id in results:
            submitter_notification = ui.notifications.error if issue_id is None else ui.notifications.message
            submitter_notification(submitter_result)

        return self.redirect('/errorlogs/')
Exemple #6
0
 def _need_update(self, branch=None):
     """Check if we need an update."""
     checkversion = CheckVersion()
     if branch:
         checkversion.updater.branch = branch
     if checkversion.updater.need_update():
         return True
     else:
         ui.notifications.message(
             'No updated needed{branch}'.format(
                 branch=' for branch {0}'.format(branch) if branch else ''),
             'Check logs for more information.')
Exemple #7
0
    def _update(self, branch=None):
        checkversion = CheckVersion()
        if branch:
            checkversion.updater.branch = branch

        if checkversion.updater.update():
            return True
        else:
            ui.notifications.message(
                'Update failed{branch}'.format(
                    branch=' for branch {0}'.format(branch) if branch else ''),
                'Check logs for more information.')

        return False
Exemple #8
0
def version_checker(monkeypatch):
    target = CheckVersion()
    monkeypatch.setattr(target, 'need_update', lambda: False)
    return target