Exemple #1
0
def license_from_copying_hash(copying):
    """Add licenses based on the hash of the copying file"""
    licenses_list = []
    hash_sum = tarball.get_sha1sum(copying)

    licenses_dict = dict()

    if config.license_fetch:
        with open(copying, "r", encoding="latin-1") as myfile:
            data = myfile.read()
            url = config.license_fetch
            values = {'hash': hash_sum, 'text': data, 'package': tarball.name}
            data = urllib.parse.urlencode(values)
            data = data.encode('utf-8')
            req = urllib.request.Request(url, data)
            response = urllib.request.urlopen(req)
            the_page = response.read().decode('utf-8')
            if len(the_page.strip()) > 0:
                print("License     : ", the_page.strip(), " (server) (", hash_sum, ")")
                add_license(the_page.strip())
                return
    else:
        with open(LICENSE_HASH_FILE, "r") as file:
            licenses_list = file.readlines()
        licenses_dict = dict(license.split(" | ") for license in licenses_list)

    if hash_sum in licenses_dict:
        add_license(licenses_dict[hash_sum])
    else:
        if not config.license_show:
            return
        print("Unknown license {0} with hash {1}".format(copying, hash_sum))
        hashUrl = config.license_show % {'HASH': hash_sum}
        print("Visit {0} to enter".format(hashUrl))
Exemple #2
0
def license_from_copying_hash(copying, srcdir):
    """Add licenses based on the hash of the copying file"""
    hash_sum = tarball.get_sha1sum(copying)

    if config.license_fetch:
        with open(copying, "r", encoding="latin-1") as myfile:
            data = myfile.read()

        values = {'hash': hash_sum, 'text': data, 'package': tarball.name}
        data = urllib.parse.urlencode(values)
        data = data.encode('utf-8')

        buffer = BytesIO()
        c = pycurl.Curl()
        c.setopt(c.URL, config.license_fetch)
        c.setopt(c.WRITEDATA, buffer)
        c.setopt(c.POSTFIELDS, data)
        c.setopt(c.FOLLOWLOCATION, 1)
        try:
            c.perform()
        except Exception as excep:
            print_fatal("Failed to fetch license from {}: {}"
                        .format(config.license_fetch, excep))
            c.close()
            sys.exit(1)

        c.close()

        response = buffer.getvalue()
        page = response.decode('utf-8').strip()
        if page:
            print("License     : ", page, " (server) (", hash_sum, ")")
            add_license(page)
            if page != "none":
                license_files.append(copying[len(srcdir) + 1:])

            return

    if hash_sum in config.license_hashes:
        add_license(config.license_hashes[hash_sum])
    else:
        if not config.license_show:
            return
        print_warning("Unknown license {0} with hash {1}".format(copying, hash_sum))
        hash_url = config.license_show % {'HASH': hash_sum}
        print_warning("Visit {0} to enter".format(hash_url))
Exemple #3
0
def license_from_copying_hash(copying):
    """Add licenses based on the hash of the copying file"""
    licenses_list = []
    hash_sum = tarball.get_sha1sum(copying)

    licenses_dict = dict()

    if config.license_fetch:
        with open(copying, "r", encoding="latin-1") as myfile:
            data = myfile.read()
            values = {'hash': hash_sum, 'text': data, 'package': tarball.name}
            data = urllib.parse.urlencode(values)
            data = data.encode('utf-8')

            buffer = BytesIO()
            c = pycurl.Curl()
            c.setopt(c.URL, config.license_fetch)
            c.setopt(c.WRITEDATA, buffer)
            c.setopt(c.POSTFIELDS, data)
            c.perform()
            c.close()

            response = buffer.getvalue()
            the_page = response.decode('utf-8')

            if len(the_page.strip()) > 0:
                print("License     : ", the_page.strip(), " (server) (", hash_sum, ")")
                add_license(the_page.strip())
                return
    else:
        if os.path.exists(LICENSE_HASH_FILE):
            with open(LICENSE_HASH_FILE, "r") as file:
                licenses_list = file.readlines()
        licenses_dict = dict(license.split(" | ") for license in licenses_list)

    if hash_sum in licenses_dict:
        add_license(licenses_dict[hash_sum])
    else:
        if not config.license_show:
            return
        print("Unknown license {0} with hash {1}".format(copying, hash_sum))
        hashUrl = config.license_show % {'HASH': hash_sum}
        print("Visit {0} to enter".format(hashUrl))