Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
        if parsed.scheme in ('http', 'https') and parsed.netloc:
            if args.releases:
                build_url = builds.BuildsURL(source,
                                             extractor=builds.ReleaseLinkExtractor)
            else:
                build_url = builds.BuildsURL(source)
        else:
            print ('"{}" is not in the list of available sources '
                   'and is not a valid HTTP URL').format(args.source)
            print 'Valid options are:\n\t{}'.format("\n\t".join(urls.keys()))
            sys.exit(1)
else:
    source = get_choice(urls.keys())
    build_url = urls[source]

installed_build = builds.get_installed_build()

def build_suffix(build):
    if build > installed_build:
        symbol = '+'
    elif build < installed_build:
        symbol = '-'
    else:
        symbol = '='
    return symbol

print
print "Arch: {}".format(builds.arch)
print "Installed build: {}".format(installed_build)

Exemplo n.º 4
0
            if args.releases:
                build_url = builds.BuildsURL(
                    source, extractor=builds.ReleaseLinkExtractor)
            else:
                build_url = builds.BuildsURL(source)
        else:
            print(
                '"{}" is not in the list of available sources '
                'and is not a valid HTTP URL').format(args.source)
            print 'Valid options are:\n\t{}'.format("\n\t".join(urls.keys()))
            sys.exit(1)
else:
    source = get_choice(urls.keys())
    build_url = urls[source]

installed_build = builds.get_installed_build()


def build_suffix(build):
    if build > installed_build:
        symbol = '+'
    elif build < installed_build:
        symbol = '-'
    else:
        symbol = '='
    return symbol


print
print "Arch: {}".format(builds.arch)
print "Installed build: {}".format(installed_build)
Exemplo n.º 5
0
 def get_installed_build(self):
     try:
         return builds.get_installed_build()
     except requests.ConnectionError as e:
         utils.connection_error(str(e))
         sys.exit(1)
Exemplo n.º 6
0
    def create(self):
        import requests2 as requests

        from resources.lib import builds

        try:
            self.installed_build = builds.get_installed_build()
        except requests.ConnectionError as e:
            utils.connection_error(str(e))
            sys.exit(1)
           
        subdir = __addon__.getSetting('subdir')
    
        # Get the url from the settings.
        source = __addon__.getSetting('source')
        utils.log("Source = " +  source)
        if source == "Other":
            # Custom URL
            url = __addon__.getSetting('custom_url')
            scheme, netloc = urlparse.urlparse(url)[:2]
            if not (scheme and netloc):
                utils.bad_url(url, "Invalid URL")
                sys.exit(1)
            
            build_url = builds.BuildsURL(url, subdir)
        else:
            # Defined URL
            try:
                build_url = builds.sources(self._arch)[source]
            except KeyError:
                utils.bad_source(source)
                sys.exit(1)
            url = build_url.url
        
        utils.log("Full URL = " + url)

        if __addon__.getSetting('set_timeout') == 'true':
            timeout = int(__addon__.getSetting('timeout'))
        else:
            timeout = None
    
        try:
            # Get the list of build links.
            with build_url.extractor() as extractor:
                links = sorted(set(extractor.get_links(self._arch, timeout)), reverse=True)
        except requests.ConnectionError as e:
            utils.connection_error(str(e))
            sys.exit(1)
        except builds.BuildURLError as e:
            utils.bad_url(url, str(e))
            sys.exit(1)
        except requests.RequestException as e:
            utils.url_error(url, str(e))
            sys.exit(1)
        
        if __addon__.getSetting('archive') == "true":
            # Look in archive area for local build files.
            archive_root = __addon__.getSetting('archive_root')
            archive_dir = os.path.join(archive_root, source)
            if not xbmcvfs.mkdirs(archive_dir):
                xbmcgui.Dialog().ok("Directory Error", "{} is not accessible.".format(archive_root),
                                    "Check the archive directory in the addon settings.")
                __addon__.openSettings()
                sys.exit(1)

            files = xbmcvfs.listdir(archive_dir)[1]
            for link in links:
                if link.tar_name in files:
                    link.set_archive(archive_dir)

        if not links:
            utils.bad_url(url, "No builds were found for {}.".format(self._arch))
            sys.exit(1)
            
        return source, links
Exemplo n.º 7
0
 def get_installed_build(self):        
     try:
         return builds.get_installed_build()
     except requests.ConnectionError as e:
         utils.connection_error(str(e))
         sys.exit(1)
Exemplo n.º 8
0
def download(args):
    if args.arch:
        config.arch = args.arch

    installed_build = builds.get_installed_build()

    def build_suffix(build):
        if build > installed_build:
            symbol = '+'
        elif build < installed_build:
            symbol = '-'
        else:
            symbol = '='
        return symbol

    build_sources = sources.build_sources()

    if args.source:
        source_name = args.source
        try:
            build_source = build_sources[source_name]
        except KeyError:
            parsed = urlparse(source_name)
            if parsed.scheme in ('http', 'https') and parsed.netloc:
                if args.releases:
                    build_url = builds.BuildsURL(
                        source_name, extractor=builds.ReleaseLinkExtractor)
                else:
                    build_url = builds.BuildsURL(source_name)
            else:
                print(
                    '"{}" is not in the list of available sources '
                    'and is not a valid HTTP URL').format(args.source)
                print 'Valid options are:\n\t{}'.format("\n\t".join(
                    build_sources.keys()))
                sys.exit(1)
    else:
        source_name = get_choice(build_sources.keys())
        build_source = build_sources[source_name]

    print
    print "Arch: {}".format(config.arch)
    print "Installed build: {}".format(installed_build)

    try:
        links = build_source.builds()
    except requests.RequestException as e:
        print str(e)
    except builds.BuildURLError as e:
        print str(e)
    else:
        if links:
            build = get_choice(links, build_suffix, reverse=True)
            remote = build.remote_file()
            file_path = os.path.join(libreelec.UPDATE_DIR, build.filename)
            print
            print "Downloading {0} ...".format(build.url)
            try:
                with open(file_path, 'w') as out:
                    process(remote, out, build.size)
            except KeyboardInterrupt:
                os.remove(file_path)
                print
                print "Download cancelled"
                sys.exit()

            if build.compressed:
                tar_path = os.path.join(libreelec.UPDATE_DIR, build.tar_name)
                size = os.path.getsize(file_path)
                print
                print "Decompressing {0} ...".format(file_path)
                with open(file_path, 'r') as fin, open(tar_path, 'w') as fout:
                    process(fin, fout, size, decompress)
                os.remove(file_path)

            funcs.create_notify_file(source_name, build)

            print
            print "The update is ready to be installed. Please reboot."
        else:
            print
            print "No builds available"