示例#1
0
    def check_mycodo_upgrade_exists(self, now):
        """Check for any new Mycodo releases on github"""
        releases = []
        upgrade_available = False
        try:
            maj_version = int(MYCODO_VERSION.split('.')[0])
            releases = github_releases(maj_version)
        except Exception:
            self.logger.error("Could not determine local mycodo version or "
                              "online release versions. Upgrade checks can "
                              "be disabled in the Mycodo configuration.")

        try:
            if len(releases):
                if parse_version(releases[0]) > parse_version(MYCODO_VERSION):
                    upgrade_available = True
                    if now > self.timer_upgrade_message:
                        # Only display message in log every 10 days
                        self.timer_upgrade_message = time.time() + 864000
                        self.logger.info(
                            "A new version of Mycodo is available. Upgrade "
                            "through the web interface under Config -> Upgrade. "
                            "This message will repeat every 10 days unless "
                            "Mycodo is upgraded or upgrade checks are disabled."
                        )

            with session_scope(MYCODO_DB_PATH) as new_session:
                mod_misc = new_session.query(Misc).first()
                if mod_misc.mycodo_upgrade_available != upgrade_available:
                    mod_misc.mycodo_upgrade_available = upgrade_available
                    new_session.commit()
        except Exception:
            self.logger.exception("Mycodo Upgrade Check ERROR")
示例#2
0
    def check_mycodo_upgrade_exists(self, now):
        """Check for any new Mycodo releases on github"""
        releases = []
        upgrade_available = False
        try:
            maj_version = int(MYCODO_VERSION.split('.')[0])
            releases = github_releases(maj_version)
        except Exception:
            self.logger.error("Could not determine local mycodo version or "
                              "online release versions. Upgrade checks can "
                              "be disabled in the Mycodo configuration.")

        try:
            if len(releases):
                if parse_version(releases[0]) > parse_version(MYCODO_VERSION):
                    upgrade_available = True
                    if now > self.timer_upgrade_message:
                        # Only display message in log every 10 days
                        self.timer_upgrade_message = time.time() + 864000
                        self.logger.info(
                            "A new version of Mycodo is available. Upgrade "
                            "through the web interface under Config -> Upgrade. "
                            "This message will repeat every 10 days unless "
                            "Mycodo is upgraded or upgrade checks are disabled.")

            with session_scope(MYCODO_DB_PATH) as new_session:
                mod_misc = new_session.query(Misc).first()
                if mod_misc.mycodo_upgrade_available != upgrade_available:
                    mod_misc.mycodo_upgrade_available = upgrade_available
                    new_session.commit()
        except Exception:
            self.logger.exception("Mycodo Upgrade Check ERROR")
示例#3
0
    def get_measurement(self):
        """ Gets the measurement in units by reading resource """
        self.return_dict = copy.deepcopy(measurements_dict)

        try:
            version = MYCODO_VERSION.split('.')
            self.value_set(0, int(version[0]))
            self.value_set(1, int(version[1]))
            self.value_set(2, int(version[2]))

            return self.return_dict
        except Exception:
            pass
示例#4
0
    def get_measurement(self):
        """ Gets the measurement in units by reading resource """
        self.return_dict = measurements_dict.copy()

        try:
            version = MYCODO_VERSION.split('.')

            if self.is_enabled(0):
                self.value_set(0, int(version[0]))

            if self.is_enabled(1):
                self.value_set(1, int(version[1]))

            if self.is_enabled(2):
                self.value_set(2, int(version[2]))

            return self.return_dict
        except Exception:
            pass
示例#5
0
    def github_upgrade_exists(self):
        errors = []
        upgrade_exists = False
        releases = []
        current_latest_release = '0.0.0'
        try:
            current_latest_release = self.github_latest_release(
                self.mycodo_releases)
            current_maj_version = int(MYCODO_VERSION.split('.')[0])
            releases = self.github_releases(self.mycodo_releases,
                                            current_maj_version)

            if releases:
                if (parse_version(releases[0]) > parse_version(MYCODO_VERSION)
                        or parse_version(current_latest_release[0]) >
                        parse_version(MYCODO_VERSION)):
                    upgrade_exists = True
        except Exception:
            logger.exception("github_upgrade_exists()")
            errors.append("Could not determine local mycodo version or "
                          "online release versions. Upgrade checks can "
                          "be disabled in the Mycodo configuration.")
        return upgrade_exists, releases, self.mycodo_releases, current_latest_release, errors
示例#6
0
def admin_upgrade():
    """ Display any available upgrades and option to upgrade """
    if not utils_general.user_has_permission('edit_settings'):
        return redirect(url_for('routes_general.home'))

    if not internet():
        flash(
            gettext("Upgrade functionality is disabled because an internet "
                    "connection was unable to be detected"), "error")
        return render_template('admin/upgrade.html', is_internet=False)

    # Read from the upgrade status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(UPGRADE_INIT_FILE) as f:
            upgrade = int(f.read(1))
    except IOError:
        try:
            with open(UPGRADE_INIT_FILE, 'w') as f:
                f.write('0')
        finally:
            upgrade = 0

    if upgrade:
        if upgrade == 2:
            flash(
                gettext("There was an error encountered during the upgrade"
                        " process. Check the upgrade log for details."),
                "error")
        return render_template('admin/upgrade.html', upgrade=upgrade)

    form_backup = forms_misc.Backup()
    form_upgrade = forms_misc.Upgrade()

    is_internet = True
    upgrade_available = False

    # Check for any new Mycodo releases on github
    releases = []
    try:
        current_maj_version = int(MYCODO_VERSION.split('.')[0])
        releases = github_releases(current_maj_version)
    except Exception as err:
        flash(
            gettext("Could not determine local mycodo version or "
                    "online release versions: {err}".format(err=err)), "error")
    if len(releases):
        current_latest_release = github_latest_release()
        current_latest_major_version = current_latest_release.split('.')[0]
        current_major_release = releases[0]
        current_releases = []
        releases_behind = None
        for index, each_release in enumerate(releases):
            if parse_version(each_release) >= parse_version(MYCODO_VERSION):
                current_releases.append(each_release)
            if parse_version(each_release) == parse_version(MYCODO_VERSION):
                releases_behind = index
        if (parse_version(releases[0]) > parse_version(MYCODO_VERSION)
                or parse_version(current_latest_release[0]) >
                parse_version(MYCODO_VERSION)):
            upgrade_available = True
    else:
        current_releases = []
        current_latest_release = '0.0.0'
        current_latest_major_version = '0'
        current_major_release = '0.0.0'
        releases_behind = 0

    # Update database to reflect the current upgrade status
    mod_misc = Misc.query.first()
    if mod_misc.mycodo_upgrade_available != upgrade_available:
        mod_misc.mycodo_upgrade_available = upgrade_available
        db.session.commit()

    def not_enough_space_upgrade():
        backup_size, free_before, free_after = can_perform_backup()
        if free_after / 1000000 < 50:
            flash(
                "A backup must be performed during an upgrade and there is "
                "not enough free space to perform a backup. A backup "
                "requires {size_bu:.1f} MB but there is only {size_free:.1f} "
                "MB available, which would leave {size_after:.1f} MB after "
                "the backup. If the free space after a backup is less than 50"
                " MB, the backup cannot proceed. Free up space by deleting "
                "current backups.".format(size_bu=backup_size / 1000000,
                                          size_free=free_before / 1000000,
                                          size_after=free_after / 1000000),
                'error')
            return True
        else:
            return False

    if request.method == 'POST':
        if (form_upgrade.upgrade.data
                and (upgrade_available or FORCE_UPGRADE_MASTER)):
            if not_enough_space_upgrade():
                pass
            elif FORCE_UPGRADE_MASTER:
                cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade-master" \
                      " | ts '[%Y-%m-%d %H:%M:%S]'" \
                      " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                              log=UPGRADE_LOG_FILE)
                subprocess.Popen(cmd, shell=True)

                upgrade = 1
                flash(gettext("The upgrade (from master branch) has started"),
                      "success")
            else:
                cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade" \
                      " | ts '[%Y-%m-%d %H:%M:%S]'" \
                      " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                              log=UPGRADE_LOG_FILE)
                subprocess.Popen(cmd, shell=True)

                upgrade = 1
                mod_misc = Misc.query.first()
                mod_misc.mycodo_upgrade_available = False
                db.session.commit()
                flash(gettext("The upgrade has started"), "success")
        elif (form_upgrade.upgrade_next_major_version.data
              and upgrade_available):
            if not not_enough_space_upgrade():
                cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade-release-major {ver}" \
                      " | ts '[%Y-%m-%d %H:%M:%S]'" \
                      " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                              ver=current_latest_major_version,
                                              log=UPGRADE_LOG_FILE)
                subprocess.Popen(cmd, shell=True)

                upgrade = 1
                mod_misc = Misc.query.first()
                mod_misc.mycodo_upgrade_available = False
                db.session.commit()
            flash(gettext("The major version upgrade has started"), "success")
        else:
            flash(gettext("You cannot upgrade if an upgrade is not available"),
                  "error")

    return render_template(
        'admin/upgrade.html',
        final_releases=FINAL_RELEASES,
        force_upgrade_master=FORCE_UPGRADE_MASTER,
        form_backup=form_backup,
        form_upgrade=form_upgrade,
        current_release=MYCODO_VERSION,
        current_releases=current_releases,
        current_major_release=current_major_release,
        current_latest_release=current_latest_release,
        current_latest_major_version=current_latest_major_version,
        releases_behind=releases_behind,
        upgrade_available=upgrade_available,
        upgrade=upgrade,
        is_internet=is_internet)
示例#7
0
def admin_upgrade():
    """ Display any available upgrades and option to upgrade """
    if not flaskutils.user_has_permission('edit_settings'):
        return redirect(url_for('general_routes.home'))

    if not internet():
        flash(
            gettext(u"Upgrade functionality is disabled because an internet "
                    u"connection was unable to be detected"), "error")
        return render_template('admin/upgrade.html', is_internet=False)

    # Read from the upgrade status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(INSTALL_DIRECTORY + '/.upgrade') as f:
            upgrade = int(f.read(1))
    except IOError:
        try:
            with open(INSTALL_DIRECTORY + '/.upgrade', 'w') as f:
                f.write('0')
        finally:
            upgrade = 0

    if upgrade:
        if upgrade == 1:
            flash(
                gettext(u"An upgrade is currently in progress. Please wait "
                        u"for it to finish"), "error")
        elif upgrade == 2:
            flash(
                gettext(u"There was an error encountered during the upgrade "
                        u"process. Check the upgrade log for details."),
                "error")
        return render_template('admin/upgrade.html', upgrade=upgrade)

    form_backup = flaskforms.Backup()
    form_upgrade = flaskforms.Upgrade()

    is_internet = True
    upgrade_available = False

    # Check for any new Mycodo releases on github
    releases = []
    try:
        maj_version = int(MYCODO_VERSION.split('.')[0])
        releases = github_releases(maj_version)
    except Exception:
        flash(
            gettext(u"Could not determine local mycodo version or "
                    u"online release versions"), "error")
    if len(releases):
        latest_release = releases[0]
        current_releases = []
        releases_behind = None
        for index, each_release in enumerate(releases):
            if parse_version(each_release) >= parse_version(MYCODO_VERSION):
                current_releases.append(each_release)
            if parse_version(each_release) == parse_version(MYCODO_VERSION):
                releases_behind = index
        if parse_version(releases[0]) > parse_version(MYCODO_VERSION):
            upgrade_available = True
    else:
        current_releases = []
        latest_release = '0.0.0'
        releases_behind = 0

    if request.method == 'POST':
        if form_upgrade.upgrade.data and upgrade_available:
            subprocess.Popen('{path}/mycodo/scripts/mycodo_wrapper upgrade >>'
                             ' /var/log/mycodo/mycodoupgrade.log 2>&1'.format(
                                 path=INSTALL_DIRECTORY),
                             shell=True)
            upgrade = 1
            flash(
                gettext(u"The upgrade has started. The daemon will be "
                        u"stopped during the upgrade."), "success")
        else:
            flash(
                gettext(u"You cannot upgrade if an upgrade is not available"),
                "error")

    return render_template('admin/upgrade.html',
                           form_backup=form_backup,
                           form_upgrade=form_upgrade,
                           current_release=MYCODO_VERSION,
                           current_releases=current_releases,
                           latest_release=latest_release,
                           releases_behind=releases_behind,
                           upgrade_available=upgrade_available,
                           upgrade=upgrade,
                           is_internet=is_internet)
示例#8
0
def admin_upgrade():
    """ Display any available upgrades and option to upgrade """
    if not utils_general.user_has_permission('edit_settings'):
        return redirect(url_for('routes_general.home'))

    if not internet():
        flash(gettext("Upgrade functionality is disabled because an internet "
                      "connection was unable to be detected"),
              "error")
        return render_template('admin/upgrade.html',
                               is_internet=False)

    # Read from the upgrade status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(UPGRADE_INIT_FILE) as f:
            upgrade = int(f.read(1))
    except IOError:
        try:
            with open(UPGRADE_INIT_FILE, 'w') as f:
                f.write('0')
        finally:
            upgrade = 0

    if upgrade:
        if upgrade == 2:
            flash(gettext("There was an error encountered during the upgrade"
                          " process. Check the upgrade log for details."),
                  "error")
        return render_template('admin/upgrade.html',
                               upgrade=upgrade)

    form_backup = forms_misc.Backup()
    form_upgrade = forms_misc.Upgrade()

    is_internet = True
    upgrade_available = False

    # Check for any new Mycodo releases on github
    releases = []
    try:
        current_maj_version = int(MYCODO_VERSION.split('.')[0])
        releases = github_releases(current_maj_version)
    except Exception as err:
        flash(gettext("Could not determine local mycodo version or "
                      "online release versions: {err}".format(err=err)),
              "error")
    if len(releases):
        current_latest_release = github_latest_release()
        current_latest_major_version = current_latest_release.split('.')[0]
        current_major_release = releases[0]
        current_releases = []
        releases_behind = None
        for index, each_release in enumerate(releases):
            if parse_version(each_release) >= parse_version(MYCODO_VERSION):
                current_releases.append(each_release)
            if parse_version(each_release) == parse_version(MYCODO_VERSION):
                releases_behind = index
        if (parse_version(releases[0]) > parse_version(MYCODO_VERSION) or
                parse_version(current_latest_release[0]) > parse_version(MYCODO_VERSION)):
            upgrade_available = True
    else:
        current_releases = []
        current_latest_release = '0.0.0'
        current_latest_major_version = '0'
        current_major_release = '0.0.0'
        releases_behind = 0

    # Update database to reflect the current upgrade status
    mod_misc = Misc.query.first()
    if mod_misc.mycodo_upgrade_available != upgrade_available:
        mod_misc.mycodo_upgrade_available = upgrade_available
        db.session.commit()

    def not_enough_space_upgrade():
        backup_size, free_before, free_after = can_perform_backup()
        if free_after / 1000000 < 50:
            flash(
                "A backup must be performed during an upgrade and there is "
                "not enough free space to perform a backup. A backup "
                "requires {size_bu:.1f} MB but there is only {size_free:.1f} "
                "MB available, which would leave {size_after:.1f} MB after "
                "the backup. If the free space after a backup is less than 50"
                " MB, the backup cannot proceed. Free up space by deleting "
                "current backups.".format(size_bu=backup_size / 1000000,
                                          size_free=free_before / 1000000,
                                          size_after=free_after / 1000000),
                'error')
            return True
        else:
            return False

    if request.method == 'POST':
        if (form_upgrade.upgrade.data and
                (upgrade_available or FORCE_UPGRADE_MASTER)):
            if not_enough_space_upgrade():
                pass
            elif FORCE_UPGRADE_MASTER:
                cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade-master" \
                      " | ts '[%Y-%m-%d %H:%M:%S]'" \
                      " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                              log=UPGRADE_LOG_FILE)
                subprocess.Popen(cmd, shell=True)

                upgrade = 1
                flash(gettext("The upgrade (from master branch) has started"), "success")
            else:
                cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade" \
                      " | ts '[%Y-%m-%d %H:%M:%S]'" \
                      " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                              log=UPGRADE_LOG_FILE)
                subprocess.Popen(cmd, shell=True)

                upgrade = 1
                mod_misc = Misc.query.first()
                mod_misc.mycodo_upgrade_available = False
                db.session.commit()
                flash(gettext("The upgrade has started"), "success")
        elif (form_upgrade.upgrade_next_major_version.data and
                upgrade_available):
            if not not_enough_space_upgrade():
                cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade-release-major {ver}" \
                      " | ts '[%Y-%m-%d %H:%M:%S]'" \
                      " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                              ver=current_latest_major_version,
                                              log=UPGRADE_LOG_FILE)
                subprocess.Popen(cmd, shell=True)

                upgrade = 1
                mod_misc = Misc.query.first()
                mod_misc.mycodo_upgrade_available = False
                db.session.commit()
            flash(gettext("The major version upgrade has started"), "success")
        else:
            flash(gettext("You cannot upgrade if an upgrade is not available"),
                  "error")

    return render_template('admin/upgrade.html',
                           final_releases=FINAL_RELEASES,
                           force_upgrade_master=FORCE_UPGRADE_MASTER,
                           form_backup=form_backup,
                           form_upgrade=form_upgrade,
                           current_release=MYCODO_VERSION,
                           current_releases=current_releases,
                           current_major_release=current_major_release,
                           current_latest_release=current_latest_release,
                           current_latest_major_version=current_latest_major_version,
                           releases_behind=releases_behind,
                           upgrade_available=upgrade_available,
                           upgrade=upgrade,
                           is_internet=is_internet)
示例#9
0
def admin_upgrade():
    """ Display any available upgrades and option to upgrade """
    if not utils_general.user_has_permission('edit_settings'):
        return redirect(url_for('general_routes.home'))

    if not internet():
        flash(
            gettext(u"Upgrade functionality is disabled because an internet "
                    u"connection was unable to be detected"), "error")
        return render_template('admin/upgrade.html', is_internet=False)

    # Read from the upgrade status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(UPGRADE_INIT_FILE) as f:
            upgrade = int(f.read(1))
    except IOError:
        try:
            with open(UPGRADE_INIT_FILE, 'w') as f:
                f.write('0')
        finally:
            upgrade = 0

    if upgrade:
        if upgrade == 2:
            flash(
                gettext(u"There was an error encountered during the upgrade "
                        u"process. Check the upgrade log for details."),
                "error")
        return render_template('admin/upgrade.html', upgrade=upgrade)

    form_backup = forms_misc.Backup()
    form_upgrade = forms_misc.Upgrade()

    is_internet = True
    upgrade_available = False

    # Check for any new Mycodo releases on github
    releases = []
    try:
        maj_version = int(MYCODO_VERSION.split('.')[0])
        releases = github_releases(maj_version)
    except Exception:
        flash(
            gettext(u"Could not determine local mycodo version or "
                    u"online release versions"), "error")
    if len(releases):
        latest_release = releases[0]
        current_releases = []
        releases_behind = None
        for index, each_release in enumerate(releases):
            if parse_version(each_release) >= parse_version(MYCODO_VERSION):
                current_releases.append(each_release)
            if parse_version(each_release) == parse_version(MYCODO_VERSION):
                releases_behind = index
        if parse_version(releases[0]) > parse_version(MYCODO_VERSION):
            upgrade_available = True
    else:
        current_releases = []
        latest_release = '0.0.0'
        releases_behind = 0

    # Update database to reflect the current upgrade status
    mod_misc = Misc.query.first()
    if mod_misc.mycodo_upgrade_available != upgrade_available:
        mod_misc.mycodo_upgrade_available = upgrade_available
        db.session.commit()

    if request.method == 'POST':
        if form_upgrade.upgrade.data and upgrade_available:
            cmd = "{pth}/mycodo/scripts/mycodo_wrapper upgrade" \
                  " | ts '[%Y-%m-%d %H:%M:%S]'" \
                  " >> {log} 2>&1".format(pth=INSTALL_DIRECTORY,
                                          log=UPGRADE_LOG_FILE)
            subprocess.Popen(cmd, shell=True)
            upgrade = 1
            mod_misc = Misc.query.first()
            mod_misc.mycodo_upgrade_available = False
            db.session.commit()
            flash(gettext(u"The upgrade has started"), "success")
        else:
            flash(
                gettext(u"You cannot upgrade if an upgrade is not available"),
                "error")

    return render_template('admin/upgrade.html',
                           form_backup=form_backup,
                           form_upgrade=form_upgrade,
                           current_release=MYCODO_VERSION,
                           current_releases=current_releases,
                           latest_release=latest_release,
                           releases_behind=releases_behind,
                           upgrade_available=upgrade_available,
                           upgrade=upgrade,
                           is_internet=is_internet)