Beispiel #1
0
def link(section, file_regex, curversion):
    url = 'https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/'
    utils.debug(2, 'Searching for %s' % section, utils.whoami())
    match = regex(url, file_regex)
    if match:
        isolink = combinelink(match, url)
        meta, isolink = utils.linkinfo(isolink)
        return isolink
Beispiel #2
0
def download(url, path):
    meta, url = utils.linkinfo(url)
    filename = utils.file_name(url)
    try:
        file_size = int(meta.get('Content-Length'))
        file_size = ((file_size / 1024) / 1024) / 1024
        print("Downloading %s with size %s GB" % (filename, file_size))
    except Exception as e:
        print("It was exception type: %s" % e)
        print("Downloading %s" % filename)
    urllib.request.urlretrieve(url, path + filename)
    utils.debug(1, "Download for %s finished" % filename, utils.whoami())
Beispiel #3
0
def main(dlist, path, dbglevel):
    print("Starting up. Reading Config.")
    utils.debug(1, 'Config is: %s' % utils.configfile, utils.whoami())
    if len(path) == 0:
        raise ValueError('You must specify a path in the %s configfile.' %
                         utils.configfile)
    utils.debug(1, 'Download folder is: ' + path, utils.whoami())
    utils.debug(1, 'Downloads in config are:', utils.whoami())
    utils.debug(1, '\n'.join(dlist) + '\n', utils.whoami())
    intervalsec = timecalc(intdenom, interval)
    utils.debug(3, 'Interval is %s seconds' % intervalsec, utils.whoami())
    mainloop()
    if not dbglevel >= 5:
        startscheduler(intervalsec, dbglevel)
    else:
        print('')
        print('----- We are running in one-off mode. (debuglevel >= 5) -----')
Beispiel #4
0
def link(section, file_regex, curversion):
    if str(curversion) == '0':
        utils.debug(2, 'Initial search for %s' % section, utils.whoami())
        url = 'https://distrowatch.com/index.php?distribution=' + section + '&release=all&month=all&year=all'
    else:
        utils.debug(2, 'Searching for %s' % section, utils.whoami())
        url = 'https://distrowatch.com/'
    match = regex(url, file_regex)
    if match:
        isolink = cleanuplink(match)
        try:
            meta, url = utils.linkinfo(isolink)
        except Exception as e:
            utils.debug(5, "Error %s" % e, utils.whoami())
            return
        filename = utils.file_name(url)
        if meta.get('Content-Type').split(';')[0] == 'text/html':
            print('Download link for %s is an intermediary website.' %
                  filename)
            print('Will retry getting a download link.')
            match = regex(url, file_regex)
            if len(match) == 0:
                print(
                    'Failed to get a download link from the intermediary website. Quitting.'
                )
            else:
                isolink = cleanuplink(match)
                return isolink
        else:
            return isolink
Beispiel #5
0
def mainloop():
    utils.debug(2, '-----mainloop(start)-----', utils.whoami())
    for i in dllist:
        curversion = str(utils.config.get(i, 'current_version'))
        downloadcfg = str(utils.config.get(i, 'download'))
        file_regex = str(utils.config.get(i, 'file_regex'))
        linkprovider = str(utils.config.get(i, 'link_provider'))
        chkresult = ''
        if str(downloadcfg) == '1':
            try:
                create = importlib.import_module(linkprovider)
                dllink = create.link(i, file_regex, curversion)
            except ModuleNotFoundError:
                print('No link provider %s found.' % linkprovider)
                print('Please check your config again.')
                sys.exit(2)
            except Exception as e:
                print('There was an exception in the %s module.' %
                      linkprovider)
                print(e)
                sys.exit(2)
            if dllink:
                utils.debug(2, 'Download link is %s' % dllink, utils.whoami())
                file_name = utils.file_name(dllink)
                utils.debug(2, 'Filename is %s' % file_name, utils.whoami())
                if file_name == curversion:
                    utils.debug(
                        1, 'We already have the current version for %s.' % i,
                        utils.whoami())
                else:
                    dlinfo = download.download(dllink, dlpath)
                    if hasattr(create, 'chkurl'):
                        utils.debug(
                            3, 'Starting checksum check for %s' % linkprovider,
                            utils.whoami())
                        chkresult = create.chksum(file_name, dlpath)
                    # utils.linkinfo may return an Exception with HTTP Error code. Dont update current_version then.
                    if not utils.is_number(dlinfo) and chkresult is not 'Fail':
                        utils.config.set(i, 'current_version', file_name)
                        utils.debug(
                            2, 'Current_version is: ' +
                            utils.config.get(i, 'current_version'),
                            utils.whoami())
                        with open(utils.configfile, 'w') as configfile:
                            utils.config.write(configfile)
                    elif utils.is_number(dlinfo):
                        print('Download failed with HTTP error code: %s' %
                              dlinfo)
                    else:
                        print('Download failed due to checksum mismatch.')
            else:
                utils.debug(4, 'No download link found for %s' % i,
                            utils.whoami())
        else:
            utils.debug(2, 'Download for %s is set to off.' % i,
                        utils.whoami())
    utils.debug(2, '-----mainloop(stop)-----', utils.whoami())
Beispiel #6
0
        scheduler.shutdown()


if __name__ == '__main__':
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
                        'modules'))
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'd:c:h',
                                   ['debug=', 'config=', 'help'])
        debuglevel = ''
    except getopt.error:
        printhelp(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            printhelp(0)
        elif opt in ("-c", "--config"):
            utils.configfile = arg
        elif opt in ("-d", "--debug"):
            debuglevel = int(arg)
    if len(utils.configfile) < 10:
        print("Something's missing in the Configfile")
        printhelp(2)
    dllist, dlpath, interval, intdenom, debuglevel = utils.readconfig(
        utils.configfile, debuglevel)
    utils.debug(4, (str(
        os.path.join(os.path.dirname(os.path.realpath(__file__)), 'modules'))),
                'mainscript')
    utils.debug(4, ('Path is:' + str(sys.path)), 'mainscript')
    main(dllist, dlpath, debuglevel)