예제 #1
0
파일: randtree.py 프로젝트: salotz/boar
 def write_md5sum(self, destination, prefix = ""):
     with open(destination, "wb") as f:
         for fn in sorted(self.files):
             f.write(bytes(md5sum(self.get_file_data(fn)), "ascii"))
             f.write(b" *")
             f.write(os.path.join(str2bytes(prefix), fn.encode("utf-8")))
             f.write(str2bytes(os.linesep))
예제 #2
0
 def addWorkdirFile(self, path, content):
     assert not os.path.isabs(path)
     if type(content) != bytes:
         content = str2bytes(content)
     filepath = os.path.join(self.workdir, path)
     md5 = md5sum(content)
     with open(filepath, "wb") as f:
         f.write(content)
     return md5
예제 #3
0
def write_file(directory, path, content):
    assert not os.path.isabs(path)
    if type(content) != bytes:
        content = str2bytes(content)
    filepath = os.path.join(directory, path)
    md5 = md5sum(content)
    with open(filepath, "wb") as f:
        f.write(content)
    return md5
예제 #4
0
def add_file_simple(front, filename, contents):
    """Adds a file with contents to a new snapshot. The front instance
    "create_session()" must have been called before this function is
    used, or an exception will be thrown."""
    contents = str2bytes(contents)
    content_checksum = md5sum(contents)
    if not front.has_blob(content_checksum) and not front.new_snapshot_has_blob(content_checksum):
        front.init_new_blob(content_checksum, len(contents))
        front.add_blob_data(content_checksum, base64.b64encode(contents))
        front.blob_finished(content_checksum)
    now = int(time())
    front.add({'filename': filename,
               'md5sum': content_checksum,
               'ctime': now,
               'mtime': now,
               'size': len(contents)})
예제 #5
0
def write_tree(path, filemap, create_root=True, overwrite=False):
    """Accepts a mapping {filename: content, ...} and writes it to the
    tree starting at the given """
    if create_root:
        os.mkdir(path)
    else:
        assert os.path.exists(path) and os.path.isdir(path)
    for filename in list(filemap.keys()):
        assert not os.path.isabs(filename)
        fullpath = os.path.join(path, filename)
        if not overwrite:
            assert not os.path.exists(fullpath)
        dirpath = os.path.dirname(fullpath)
        try:
            os.makedirs(dirpath)
        except:
            pass
        with open(fullpath, "wb") as f:
            if (type(filemap[filename]) == str):
                f.write(str2bytes(filemap[filename]))
            else:
                f.write(filemap[filename])
예제 #6
0
def write_file(path, contents):
    with open(path, "wb") as f:
        f.write(str2bytes(contents))