Exemple #1
0
def test_split(path, parts):
    split = split_path(path)

    assert len(split) == len(parts)

    for index, part in enumerate(parts):
        assert split[index] == part
Exemple #2
0
    def update(self, file_path=""):
        Snapshot.update(self)

        parts = split_path(file_path)

        if parts[0] in self.snapshots.keys():
            self.snapshots[allparts[0]].update(file_path)
Exemple #3
0
def test_split(path, parts):
    split = split_path(path)

    # Make sure we have the right number of parts
    assert len(split) == len(parts)

    # Make sure each part is the same
    for index, part in enumerate(parts):
        assert split[index] == part
    def update(self, file_path=""):

        parts = split_path(file_path)

        for index, part in enumerate(parts):
            if part == "." or part == "/":
                continue

            if part in self.snapshots.keys():
                if isinstance(self.snapshots[part], DirectorySnapshot):
                    self.snapshots[part].update(os.path.join(*parts[index:]))
                else:
                    self.snapshots[part].update()
                return

        # We are supposed to update this directory
        self.fetch_directory_info()
    def to_json(self, path="./", recursive=True):
        snapshots = self.snapshots

        # Split path into parts
        path_parts = split_path(path)

        # Loop through parts till we find a useful one
        for index, part in enumerate(path_parts):

            # Skip useless parts
            if part == "." or part == "":
                continue

            # Pass the job to a child snapshot
            return snapshots[part].to_json("/".join(path_parts[index:]))

        string = '{"type": ' + str(
            self.get_type()
        ) + ', "file_name": "' + self.file_name + '", "full_path": "' + self.rel_path + '", "last_modified": ' + str(
            self.last_modified) + ', "snapshots": ['

        # Recursively convert child snapshots to JSON
        for index, key in enumerate(snapshots.keys()):
            snapshot = snapshots[key]

            if not recursive and isinstance(snapshot, DirectorySnapshot):

                # Convert the DirectorySnapshot to JSON using FileSnapshot if not recursive
                string += FileSnapshot.__str__(snapshot)

            else:

                # Convert the snapshot to JSON using default method
                string += str(snapshot)

            # Add a comma if this isn't the last snapshot
            if index != len(snapshots) - 1:
                string += ","

        string += "]}"

        return string
Exemple #6
0
    def to_json(self, path="./", recursive=True):
        string = '{"type": ' + str(self.get_type().value) + ', "file_name": "' +  self.file_name + '", "full_path": "' + self.rel_path + '", "last_modified": ' + str(self.last_modified) + ', "snapshots": ['

        snapshots = self.snapshots

        path_parts = split_path(path)
        for index, part in enumerate(path_parts):
            if part == "." or part == "":
                continue
            if part in snapshots:
                return snapshots[part].to_json("/".join(path_parts[index:]))

        for index, key in enumerate(snapshots.keys()):
            snapshot = snapshots[key]
            if not recursive and isinstance(snapshot, DirectorySnapshot):
                string += Snapshot.__str__(snapshot)
            else:
                string += str(snapshot)
            if index != len(snapshots) - 1:
                string +=  ","
        string += "]}"
        return string