Ejemplo n.º 1
0
 def _assertWorkdirEqualsTree(self, workdir, randtree):
     all_files = get_tree(os.path.abspath(workdir), skip = [".boar"], sep = "/")
     all_files.remove("manifest-md5.txt")
     self.assertEqual(set(all_files), set(map(backslashes_to_slashes, randtree.files)))
     for fn in all_files:
         path = os.path.join(workdir, fn)
         self.assertEqual(md5sum(randtree.get_file_data(fn)), md5sum_file(path))
Ejemplo n.º 2
0
def mkrandfile_deterministic(path, filesize_bytes, seed=0):
    import math
    assert not os.path.exists(path)
    random.seed(seed)
    md5 = hashlib.md5()
    f = open(path, "wb")
    filesize_kbytes = int(math.ceil(1.0 * filesize_bytes / 1024))
    for n in xrange(0, filesize_kbytes * 128):
        byte_val = random.randint(0, 2**32 - 1)
        buf = struct.pack("Q", byte_val)
        f.write(buf)
        md5.update(buf)
    f.flush()
    assert md5sum_file(path) == md5.hexdigest()
    f.seek(filesize_bytes)
    f.truncate()
    f.close()
    assert os.path.getsize(path) == filesize_bytes
    return md5sum_file(path)
Ejemplo n.º 3
0
def mkrandfile_deterministic(path, filesize_bytes, seed=0):
    import math
    assert not os.path.exists(path)
    random.seed(seed)
    md5 = hashlib.md5()
    f = open(path, "wb")
    filesize_kbytes = int(math.ceil(1.0 * filesize_bytes / 1024))
    for n in xrange(0, filesize_kbytes*128):
        byte_val = random.randint(0, 2**32-1)
        buf = struct.pack("Q", byte_val)
        f.write(buf)
        md5.update(buf)
    f.flush()
    assert md5sum_file(path) == md5.hexdigest()
    f.seek(filesize_bytes)
    f.truncate()
    f.close()
    assert os.path.getsize(path) == filesize_bytes
    return md5sum_file(path)
Ejemplo n.º 4
0
def main():
    args = sys.argv[1:]
    if len(args) == 0:
        args = ["--help"]
    parser = OptionParser(usage="usage: treecheck.py [-f <md5file>] <path>")
    parser.add_option(
        "-f",
        "--filename",
        action="store",
        dest="filename",
        type="string",
        help=
        "A file describing the expected directory contents (md5sum.exe file format)"
    )
    (options, args) = parser.parse_args(args)
    path = tounicode(args[0])
    if not os.path.isabs(path):
        path = tounicode(os.getcwd()) + u"/" + path
    assert os.path.exists(path), "Path does not exist: " + path

    if options.filename == "-":
        fo = sys.stdin
    else:
        fo = open(tounicode(options.filename))
    expected = {}
    for line in fo:
        expected[line[34:].strip()] = line[0:32]

    tree = get_tree(path)

    extra_files = []
    diff_files = []
    missing_files = []

    for fn in tree:
        md5 = md5sum_file(fn)
        if fn not in expected:
            extra_files.append(fn)
            print "?", fn
        else:
            if expected[fn] != md5:
                diff_files.append(fn)
                print "M", fn
    for fn in expected.keys():
        if fn not in tree:
            missing_files.append(fn)
            print "D", fn

    if extra_files or diff_files or missing_files:
        print >> sys.stderr, "*** Content does not match"
        sys.exit(1)
Ejemplo n.º 5
0
def main():
    args = sys.argv[1:]
    if len(args) == 0:
        args = ["--help"]
    parser = OptionParser(usage="usage: treecheck.py [-f <md5file>] <path>")
    parser.add_option("-f", "--filename", action="store", dest = "filename", type="string",
                      help="A file describing the expected directory contents (md5sum.exe file format)")
    (options, args) = parser.parse_args(args)
    path = tounicode(args[0])
    if not os.path.isabs(path):
        path = tounicode(os.getcwd()) + u"/" + path
    assert os.path.exists(path), "Path does not exist: " + path

    if options.filename == "-":
        fo = sys.stdin
    else:
        fo = open(tounicode(options.filename))
    expected = {}
    for line in fo:
        expected[line[34:].strip()] = line[0:32]

    tree = get_tree(path)

    extra_files = []
    diff_files = []
    missing_files = []

    for fn in tree:
        md5 = md5sum_file(fn)
        if fn not in expected:
            extra_files.append(fn)
            print "?", fn
        else:
            if expected[fn] != md5:
                diff_files.append(fn)
                print "M", fn
    for fn in expected.keys():
        if fn not in tree:
            missing_files.append(fn)
            print "D", fn

    if extra_files or diff_files or missing_files:
        print >>sys.stderr, "*** Content does not match"
        sys.exit(1)