Example #1
0
def run():
    for item in sys.argv[1:]:
            progress = ProgressBar()
            result = download.get(item, os.getcwd(), handlers={"status": progress.download_update, "bitrate": progress.set_bitrate, "time": progress.set_time}, segmented = True)
            progress.download_end()
            if not result:
                sys.exit(-1)
Example #2
0
def run():
    for item in sys.argv[1:]:
        progress = ProgressBar()
        result = download.get(item,
                              os.getcwd(),
                              handlers={
                                  "status": progress.download_update,
                                  "bitrate": progress.set_bitrate,
                                  "time": progress.set_time
                              },
                              segmented=True)
        progress.download_end()
        if not result:
            sys.exit(-1)
Example #3
0
def run(args):
    for item in args:
        progress = ProgressBar()
        result = download.get(
            item,
            os.getcwd(),
            handlers={
                "status": progress.download_update,
                "bitrate": progress.set_bitrate,
                "time": progress.set_time,
            },
            segmented=True,
        )
        progress.download_end()
        if not result:
            return -1
    return 0
    def test_wcs_simplified_categories(self):
        client = client_for(
            Service(processes=[NALCMSZonalStatisticsRasterProcess()],
                    cfgfiles=CFG_FILE))
        fields = [
            "select_all_touching={touches}",
            "simple_categories={simple_categories}",
            "band={band}",
            "shape=file@xlink:href=file://{shape}",
        ]

        datainputs = ";".join(fields).format(
            touches=True,
            simple_categories=True,
            band=1,
            shape=get_local_testdata("watershed_vector/Basin_test.zip"),
        )
        resp = client.get(
            service="WPS",
            request="Execute",
            version="1.0.0",
            identifier="nalcms-zonal-stats-raster",
            datainputs=datainputs,
        )

        assert_response_success(resp)
        out = get_output(resp.xml)
        stats = json.loads(out["statistics"])[0]
        assert not {"count", "nodata", "nan"}.issubset(stats)

        geometry = json.loads(out["features"])
        assert isinstance(type(geometry), type(MultiPolygon))

        category_counts = count_pixels(stats)
        assert category_counts == geometry["features"][0]["properties"][
            "count"]
        assert sum(
            stats.values()) == geometry["features"][0]["properties"]["count"]

        assert {"raster"}.issubset([*out])
        d = md.get(out["raster"], path="/tmp", segmented=False)
        assert d[0] == "/tmp/subset_1.tiff"
    def test_multiple_features_metalink(self):
        client = client_for(
            Service(processes=[RasterSubsetProcess()], cfgfiles=CFG_FILE))

        fields = [
            "shape=file@xlink:href=file://{shape}",
            "raster=file@xlink:href=file://{raster}",
            "band={band}",
            "select_all_touching={touches}",
        ]

        datainputs = ";".join(fields).format(
            shape=get_local_testdata("donneesqc_mrc_poly/mrc_subset.gml"),
            raster=get_local_testdata(
                "earthenv_dem_90m/earthenv_dem90_southernQuebec.tiff"),
            band=1,
            touches=True,
        )

        resp = client.get(
            service="WPS",
            request="Execute",
            version="1.0.0",
            identifier="raster-subset",
            datainputs=datainputs,
        )

        assert_response_success(resp)
        out = get_output(resp.xml)
        assert {"raster"}.issubset([*out])

        raster_dir = md.get(out["raster"], path=tempfile.mkdtemp())
        assert len(raster_dir) == 6

        bounds = list()
        for f in raster_dir:
            raster = rio.open(f)
            assert raster.bounds
            bounds.append(raster.bounds)
        assert len(set(bounds)) == len(raster_dir)
Example #6
0
    def convert(self):  # noqa: D102
        from metalink import download as md

        files = md.get(self.url, path=self.path, segmented=False)
        return files
Example #7
0
 def convert(self):
     import metalink.download as md
     files = md.get(self.url, path=self.path)
     return files
Example #8
0
 def convert(self):
     import metalink.download as md
     files = md.get(self.url, path=self.path, segmented=False)
     return files
Example #9
0
def run():
    '''
    Start a console version of this application.
    '''
    # Command line parser options.
    usage = "usage: %prog [-c|-d|-j|--convert|--rconvert] [options] arg1 arg2 ..."
    parser = optparse.OptionParser(version=metalinkc.ABOUT, usage=usage)
    parser.add_option("--download", "-d", action="store_true", dest="download", help=_("Actually download the file(s) in the metalink"))
    parser.add_option("--check", "-c", action="store_true", dest="check", help=_("Check the metalink file URLs"))
    #parser.add_option("--file", "-f", dest="filevar", metavar="FILE", help=_("Metalink file to check or file to download"))
    parser.add_option("--timeout", "-t", dest="timeout", metavar="TIMEOUT", help=_("Set timeout in seconds to wait for response (default=10)"))
    parser.add_option("--os", "-o", dest="os", metavar="OS", help=_("Operating System preference"))
    parser.add_option("--no-segmented", "-s", action="store_true", dest="nosegmented", help=_("Do not use the segmented download method"))
    parser.add_option("--lang", "-l", dest="language", metavar="LANG", help=_("Language preference (ISO-639/3166)"))
    parser.add_option("--country", dest="country", metavar="LOC", help=_("Two letter country preference (ISO 3166-1 alpha-2)"))
    parser.add_option("--pgp-keys", "-k", dest="pgpdir", metavar="DIR", help=_("Directory with the PGP keys that you trust (default: working directory)"))
    parser.add_option("--pgp-store", "-p", dest="pgpstore", metavar="FILE", help=_("File with the PGP keys that you trust (default: ~/.gnupg/pubring.gpg)"))
    parser.add_option("--gpg-binary", "-g", dest="gpg", help=_("(optional) Location of gpg binary path if not in the default search path"))
    parser.add_option("--convert-jigdo", "-j", action="store_true", dest="jigdo", help=_("Convert Jigdo format file to Metalink"))
    parser.add_option("--port", dest="port", help=_("Streaming server port to use (default: No streaming server)"))
    parser.add_option("--html", dest="html", help=_("Extract links from HTML webpage"))
    parser.add_option("--convert", dest="convert", action="store_true", help="Conversion from 3 to 4 (IETF RFC)")
    parser.add_option("--rconvert", dest="rev", action="store_true", help="Reverses conversion from 4 (IETF RFC) to 3")
    parser.add_option("--output", dest="output", metavar="OUTFILE", help=_("Output conversion result to this file instead of screen"))
    parser.add_option("--rss", "-r", action="store_true", dest="rss", help=_("RSS/Atom Feed Mode, implies -d"))
    parser.add_option("--testable", action="store_true", dest="only_testable", help=_("Limit tests to only the URL types we can test (HTTP/HTTPS/FTP)"))
    parser.add_option("-w", dest="writedir", default=os.getcwd(), help=_("Directory to write output files to (default: current directory)"))
    (options, args) = parser.parse_args()
    
    #if options.filevar != None:
    #   args.append(options.filevar)

    if len(args) == 0:
        parser.print_help()
        return

    socket.setdefaulttimeout(10)
    proxy.set_proxies()
    if options.os != None:
        download.OS = options.os
    if options.language != None:
        download.LANG = [].extend(options.language.lower().split(","))
    if options.country != None:
        download.COUNTRY = options.country
    if options.pgpdir != None:
        download.PGP_KEY_DIR = options.pgpdir
    if options.pgpstore != None:
        download.PGP_KEY_STORE = options.pgpstore
    if options.port != None:
        download.PORT = int(options.port)
    if options.gpg != None:
        GPG.DEFAULT_PATH.insert(0, options.gpg)
        
    if options.timeout != None:
        socket.setdefaulttimeout(int(options.timeout))

    if options.country != None and len(options.country) != 2:
        print _("Invalid country length, must be 2 letter code")
        return

    if options.jigdo:
        print download.convert_jigdo(args[0])
        return
        
    if options.convert:
        text = download.parse_metalink(args[0], ver=4).generate()
        if options.output:
            handle = open(options.output, "w")
            handle.write(text)
            handle.close()
        else:
            print text
        return
        
    if options.rev:
        text = download.parse_metalink(args[0], ver=3).generate()
        if options.output:
            handle = open(options.output, "w")
            handle.write(text)
            handle.close()
        else:
            print text
        return

    if options.html:
        handle = download.urlopen(options.html)
        text = handle.read()
        handle.close()

        page = metalinkc.Webpage()
        page.set_url(options.html)
        page.feed(text)
        
        for item in page.urls:
            if item.endswith(".metalink"):
                print "=" * 79
                print item
                mcheck = metalinkc.Checker()
                mcheck.check_metalink(item)
                results = mcheck.get_results()
                print_totals(results)
        return

    if options.check:
        failure = False
        for item in args:
            print "=" * 79
            print item
            mcheck = metalinkc.Checker(options.only_testable)
            mcheck.check_metalink(item)
            results = mcheck.get_results()
            result = print_totals(results)
            failure |= result
        sys.exit(int(failure))
            
    if options.download:
        for item in args:
            progress = ProgressBar()
            result = download.get(item, options.writedir, handlers={"status": progress.download_update, "bitrate": progress.set_bitrate, "time": progress.set_time}, segmented = not options.nosegmented)
            progress.download_end()
            if not result:
                sys.exit(-1)
                
    if options.rss:
        for feed in args:
            progress = ProgressBar()
            result = download.download_rss(feed, options.writedir, handlers={"status": progress.download_update, "bitrate": progress.set_bitrate, "time": progress.set_time}, segmented = not options.nosegmented)
            progress.download_end()
            if not result:
                sys.exit(-1)
                        
    sys.exit(0)