def new_build_check():
    log.log("Checking for a new build")

    check_official = addon.get_bool_setting('check_official')
    check_interval = addon.get_int_setting('check_interval')

    autoclose_ms = check_interval * 3540000  # check interval in ms - 1 min

    try:
        installed_build = builds.get_installed_build()
    except:
        log.log("Unable to get installed build so exiting")
        sys.exit(1)

    source = addon.get_setting('source_name')
    if (isinstance(installed_build, builds.Release)
            and source == "Official Releases" and not check_official):
        # Don't do the job of the official auto-update system.
        log.log("Skipping build check - official release")
    else:
        builds.arch = utils.get_arch()

        if addon.get_bool_setting('set_timeout'):
            builds.timeout = float(addon.get_setting('timeout'))

        build_sources = builds.sources()
        try:
            build_url = build_sources[source]
        except KeyError:
            log.log("{} is not a valid source".format(source))
            return

        log.log("Checking {}".format(build_url.url))

        latest = builds.latest_build(source)
        if latest and latest > installed_build:
            if utils.do_show_dialog():
                log.log("New build {} is available, "
                        "prompting to show build list".format(latest))

                if utils.yesno(addon.name,
                               line1=L10n(32027).format(
                                   utils.format_build(latest)),
                               line2=L10n(32028).format(
                                   utils.format_build(installed_build)),
                               line3=L10n(32029),
                               autoclose=autoclose_ms):
                    with Main() as main:
                        main.start()
            else:
                utils.notify(
                    L10n(32030).format(utils.format_build(latest)), 4000)
def new_build_check():
    log.log("Checking for a new build")
    
    check_official = addon.get_bool_setting('check_official')
    check_interval = addon.get_int_setting('check_interval')

    autoclose_ms = check_interval * 3540000 # check interval in ms - 1 min
    
    try:
        installed_build = builds.get_installed_build()
    except:
        log.log("Unable to get installed build so exiting")
        sys.exit(1)

    source = addon.get_setting('source_name')
    if (isinstance(installed_build, builds.Release) and source == "Official Releases"
        and not check_official):
        # Don't do the job of the official auto-update system.
        log.log("Skipping build check - official release")
    else:
        builds.arch = utils.get_arch()

        if addon.get_bool_setting('set_timeout'):
            builds.timeout = float(addon.get_setting('timeout'))

        build_sources = builds.sources()
        try:
            build_url = build_sources[source]
        except KeyError:
            log.log("{} is not a valid source".format(source))
            return

        log.log("Checking {}".format(build_url.url))

        latest = builds.latest_build(source)
        if latest and latest > installed_build:
            if utils.do_show_dialog():
                log.log("New build {} is available, "
                        "prompting to show build list".format(latest))

                if utils.yesno(
                        addon.name,
                        line1=L10n(32027).format(utils.format_build(latest)),
                        line2=L10n(32028).format(utils.format_build(installed_build)),
                        line3=L10n(32029),
                        autoclose=autoclose_ms):
                    with Main() as main:
                        main.start()
            else:
                utils.notify(L10n(32030).format(utils.format_build(latest)),
                             4000)
    def start(self):
        if utils.is_running():
            raise script_exceptions.AlreadyRunning

        utils.set_running()
        log.log("Starting")

        builds.arch = utils.get_arch()
        log.log("Set arch to {}".format(builds.arch))

        if addon.get_bool_setting('set_timeout'):
            builds.timeout = float(addon.get_setting('timeout'))

        self.background = addon.get_bool_setting('background')
        self.verify_files = addon.get_bool_setting('verify_files')

        funcs.create_directory(openelec.UPDATE_DIR)

        utils.check_update_files(builds.get_build_from_notify_file(),
                                 force_dialog=True)

        self.installed_build = self.get_installed_build()

        self.select_build()

        utils.remove_update_files()

        self.check_archive()

        self.maybe_download()

        self.maybe_verify()

        rpi.maybe_disable_overclock()

        utils.maybe_schedule_extlinux_update()

        utils.maybe_run_backup()

        self.confirm()
    def start(self):
        if utils.is_running():
            raise script_exceptions.AlreadyRunning

        utils.set_running()
        log.log("Starting")

        builds.arch = utils.get_arch()
        log.log("Set arch to {}".format(builds.arch))

        if addon.get_bool_setting('set_timeout'):
            builds.timeout = float(addon.get_setting('timeout'))

        self.background = addon.get_bool_setting('background')
        self.verify_files = addon.get_bool_setting('verify_files')
        
        funcs.create_directory(openelec.UPDATE_DIR)

        utils.check_update_files(builds.get_build_from_notify_file(),
                                 force_dialog=True)

        self.installed_build = self.get_installed_build()

        self.select_build()

        utils.remove_update_files()

        self.check_archive()

        self.maybe_download()

        self.maybe_verify()

        rpi.maybe_disable_overclock()

        utils.maybe_schedule_extlinux_update()

        utils.maybe_run_backup()

        self.confirm()