示例#1
0
def verify_cloudfront(config, root, files):
    ret = True
    tree = SimpleTree(config)
    md5sums = ChecksumFile(
        config, os.path.join(tree.directory, ".pool"), "MD5SUMS", None)
    md5sums.read()
    opener = build_opener(HTTPHeadRedirectHandler())
    if not root.endswith("/"):
        root += "/"
    for f in files:
        if f not in md5sums.entries:
            # There are lots of miscellaneous boring files with no local
            # checksums.  Silently ignore these for convenience.
            continue
        url = urljoin(root, f.replace("+", "%2B"))
        try:
            response = opener.open(HeadRequest(url))
        except HTTPError as e:
            print("%s: %s" % (url, e), file=sys.stderr)
            continue
        try:
            etag = response.info()["ETag"].strip('"')
            if md5sums.entries[f] == etag:
                print("%s matches %s" % (f, url))
            else:
                print("%s DOES NOT MATCH %s" % (f, url), file=sys.stderr)
                print("  Local:  %s" % md5sums.entries[f], file=sys.stderr)
                print("  Remote: %s" % etag, file=sys.stderr)
                ret = False
        except KeyError:
            print("No remote ETag for %s; skipping." % url, file=sys.stderr)
    return ret
示例#2
0
def verify_cloudfront(config, root, files):
    ret = True
    tree = SimpleReleaseTree(config)
    md5sums = ChecksumFile(config, os.path.join(tree.directory, ".pool"),
                           "MD5SUMS", None)
    md5sums.read()
    opener = build_opener(HTTPHeadRedirectHandler())
    if not root.endswith("/"):
        root += "/"
    for f in files:
        if f not in md5sums.entries:
            # There are lots of miscellaneous boring files with no local
            # checksums.  Silently ignore these for convenience.
            continue
        url = urljoin(root, f.replace("+", "%2B"))
        try:
            response = opener.open(HeadRequest(url))
        except HTTPError as e:
            print("%s: %s" % (url, e), file=sys.stderr)
            continue
        try:
            etag = response.info()["ETag"].strip('"')
            if md5sums.entries[f] == etag:
                print("%s matches %s" % (f, url))
            else:
                print("%s DOES NOT MATCH %s" % (f, url), file=sys.stderr)
                print("  Local:  %s" % md5sums.entries[f], file=sys.stderr)
                print("  Remote: %s" % etag, file=sys.stderr)
                ret = False
        except KeyError:
            print("No remote ETag for %s; skipping." % url, file=sys.stderr)
    return ret
示例#3
0
 def test_read(self):
     with open(os.path.join(self.temp_dir, "MD5SUMS"), "w") as md5sums:
         print(dedent("""\
             checksum  one-path
             checksum *another-path
             """), file=md5sums)
     checksum_file = ChecksumFile(
         self.config, self.temp_dir, "MD5SUMS", hashlib.md5)
     checksum_file.read()
     self.assertEqual(
         {"one-path": "checksum", "another-path": "checksum"},
         checksum_file.entries)
示例#4
0
 def test_read(self):
     with mkfile(os.path.join(self.temp_dir, "MD5SUMS")) as md5sums:
         print(dedent("""\
             checksum  one-path
             checksum *another-path
             """),
               file=md5sums)
     checksum_file = ChecksumFile(self.config, self.temp_dir, "MD5SUMS",
                                  hashlib.md5)
     checksum_file.read()
     self.assertEqual({
         "one-path": "checksum",
         "another-path": "checksum"
     }, checksum_file.entries)
示例#5
0
 def test_read_missing(self):
     checksum_file = ChecksumFile(
         self.config, self.temp_dir, "MD5SUMS", hashlib.md5)
     checksum_file.read()
     self.assertEqual({}, checksum_file.entries)
示例#6
0
 def test_read_missing(self):
     checksum_file = ChecksumFile(self.config, self.temp_dir, "MD5SUMS",
                                  hashlib.md5)
     checksum_file.read()
     self.assertEqual({}, checksum_file.entries)