Example #1
0
def sync_files(conn1, nodeid1, conn2, nodeid2, path1="/", path2="/"):
    """Sync files from conn1.nodeid1 to conn2.nodeid2"""
    files = list(conn1.list_dir(nodeid1, path1))

    # ensure target path exists
    if not conn2.has_file(nodeid2, path2):
        conn2.create_dir(nodeid2, path2)

    # remove files in node2 that don't exist in node1
    for f in list(conn2.list_dir(nodeid2, path2)):
        f2 = path_join(path2, f)
        if not conn1.has_file(nodeid1, f2):
            conn2.delete_file(nodeid2, f2)

    # copy files from node1 to node2
    for f in files:
        file1 = f
        file2 = path_join(path2, f[len(path1):])

        if f.endswith("/"):
            # recurse into directories
            sync_files(conn1, nodeid1, conn2, nodeid2, file1, file2)
            continue

        copy_file(conn1, nodeid1, file1, conn2, nodeid2, file2)
Example #2
0
def sync_files(conn1, nodeid1, conn2, nodeid2, path1="", path2=""):
    """Sync files from conn1.nodeid1 to conn2.nodeid2"""

    files = list(conn1.list_files(nodeid1, path1))

    # ensure target path exists
    if not conn2.file_exists(nodeid2, path2):
        conn2.create_dir(nodeid2, path2)

    # remove files in node2 that don't exist in node1
    for f in list(conn2.list_files(nodeid2, path2)):
        f2 = path_join(path2, f)
        if not conn1.file_exists(nodeid1, f2):
            conn2.delete_file(nodeid2, f2)

    # copy files from node1 to node2
    for f in files:
        file1 = path_join(path1, f)
        file2 = path_join(path2, f)

        if f.endswith("/"):
            # recurse into directories
            sync_files(conn1, nodeid1, conn2, nodeid2, file1, file2)
            continue
        
        copy_files(conn1, nodeid1, file1, conn2, nodeid2, file2)
Example #3
0
    def list_dir(self, nodeid, filename="/", _path=None):
        """List data files in node."""
        if not filename.endswith("/"):
            raise FileError("filename '%s' does not end with '/'" % filename)

        path = self.get_node_path(nodeid) if _path is None else _path
        path = get_node_filename(path, filename)

        try:
            filenames = os.listdir(path)
        except:
            raise UnknownFile("cannot file file '%s' '%s'" %
                              (nodeid, filename))

        for name in filenames:
            # TODO: extract this as a documented method.
            if (name != NODE_META_FILE and not name.startswith("__")):
                fullname = os.path.join(path, name)
                node_fullname = path_join(filename, name)
                if not os.path.exists(get_node_meta_file(fullname)):
                    # ensure directory is not a node
                    if os.path.isdir(fullname):
                        yield node_fullname + "/"
                    else:
                        yield node_fullname
Example #4
0
    def list_dir(self, nodeid, filename="/", _path=None):
        """List data files in node."""
        if not filename.endswith("/"):
            raise FileError("filename '%s' does not end with '/'" % filename)

        path = self.get_node_path(nodeid) if _path is None else _path
        path = get_node_filename(path, filename)

        try:
            filenames = os.listdir(path)
        except:
            raise UnknownFile("cannot file file '%s' '%s'" %
                              (nodeid, filename))

        for name in filenames:
            # TODO: extract this as a documented method.
            if (name != NODE_META_FILE and
                    not name.startswith("__")):
                fullname = os.path.join(path, name)
                node_fullname = path_join(filename, name)
                if not os.path.exists(get_node_meta_file(fullname)):
                    # ensure directory is not a node
                    if os.path.isdir(fullname):
                        yield node_fullname + "/"
                    else:
                        yield node_fullname