Exemplo n.º 1
0
    def csv_row_for(i):
        filename = os.path.join(temp_dir, str(i))
        stat_info = StatInfo.for_file(filename)

        content = "This is content number {}".format(i)
        object_id = "data/{}/{}".format(sha1sum(str(i)), sha1sum(content))

        return "{}:{}:{}".format(filename, object_id, ":".join(str(field) for field in stat_info))
Exemplo n.º 2
0
def test_file_entry_as_fields():
    filename = os.path.join(temp_dir, '0')

    entry = FileEntry(filename, "data/{}/{}".format(sha1sum('0'), sha1sum("This is content number 0")))

    stat_info = StatInfo.for_file(filename)
    expected = (filename, "data/{}/{}".format(sha1sum('0'), sha1sum("This is content number 0"))) + stat_info

    assert_really_equal(expected, entry.as_fields())
Exemplo n.º 3
0
    def _checksum_for_file(cls, path):
        if not os.path.isfile(path):
            raise ValueError("{} does not name a file".format(path))

        with open(path, 'rb') as f:
            parts = iter(functools.partial(f.read, 32768), '')
            checksum = sha1sum(parts)

            logging.debug("{} --> {}".format(path, checksum))

        logging.debug("Content checksum: {}".format(checksum))

        return checksum
Exemplo n.º 4
0
 def _object_id(cls, path):
     checksum = cls._checksum_for_file(path)
     return "data/{}/{}".format(sha1sum(os.path.basename(path)), checksum)
Exemplo n.º 5
0
def expected_file_entry_for(i):
    filename = os.path.join(temp_dir, str(i))
    content = "This is content number {}".format(i)

    return FileEntry(filename, "data/{}/{}".format(sha1sum(str(i)), sha1sum(content)), StatInfo.for_file(filename))