from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider

HTTP = HTTPRemoteProvider()


# The plain text version and the unzipped .gz version should have the same content.
# The diff command returns exit code 0 for identical files, 1 for differing files and 2 for errors.
rule compare:
    input:
        "landsat-data.txt",
        "landsat-data-unzipped.txt"
    shell:
        "diff {input[0]} {input[1]}"


rule copy:
    input:
        HTTP.remote("bitbucket.org/snakemake/snakemake/raw/http-gzip-autodecode/tests/test_remote_http/expected-results/landsat-data.txt")
    output:
        "landsat-data.txt"
    shell:
        "cp {input} {output}"


rule copy_gz:
    input:
        HTTP.remote("bitbucket.org/snakemake/snakemake/raw/http-gzip-autodecode/tests/test_remote_http/expected-results/landsat-data.txt.gz")
    output:
        "landsat-data.txt.gz"
    shell:
        "cp {input} {output}"


# This only works if the input file is a gzipped file.
# Hence, it will fail, if the .txt.gz file is automagically decompressed by the requests module.
rule unizp:
    input:
        "landsat-data.txt.gz"
    output:
        "landsat-data-unzipped.txt"
    shell:
        "gunzip -c {input} > {output}"
