Example #1
0
def update_bug_data(update_anyway, cache_dir, bug_types,
        bugs_update_period_in_days, verbose=False):
    """Download bug if what's available is too old.

    ``update_anyway'' will download data regardless of how old they are

    ``cache_dir'' where to store the downloaded files

    ``bug_types'' what bug types to download data for (full names)

    ``bugs_update_period_in_days'' update bug data if the previously
        downloaded data is older than this period

    ``verbose'' whether to print diagnostic messages

    """
    assert os.path.isdir(cache_dir)
    # see which bug files are missing or have to be updated, if any
    all_files = ["%s/%s.html" % (cache_dir, bt) for bt in bug_types]
    if update_anyway:
        files_to_update = all_files
    else:
        bugs_mtime_threshold = bugs_update_period_in_days * 86400
        files_to_update = [f for f in all_files \
                if not younger_than(f, bugs_mtime_threshold)]

        if not files_to_update:
            if verbose:
                print "using previously downloaded bug data"
            return

    url_paths = ["/devel/wnpp/%s" % os.path.basename(f) for f in files_to_update]
    wget("www.debian.org", url_paths, cache_dir, verbose)
Example #2
0
def update_popcon_data(update_anyway, cache_dir, popcon_update_period_in_days,
        verbose=False):

    filename = "%s/%s" % (cache_dir, POPCON_FNAME)
    max_age = popcon_update_period_in_days * 86400
    if update_anyway or not younger_than(filename, max_age):
        url_paths = ["/%s.gz" % POPCON_FNAME]
        wget("popcon.debian.org", url_paths, cache_dir, verbose)
        decompress_gzip("%s.gz" % filename)
    elif verbose:
        print "using previously downloaded popcon data"