Esempio n. 1
0
 def getDiffs(self, inner_path, limit=30 * 1024, update_files=True):
     if inner_path not in self.contents:
         return None
     diffs = {}
     content_inner_path_dir = helper.getDirname(inner_path)
     for file_relative_path in self.contents[inner_path].get("files", {}):
         file_inner_path = content_inner_path_dir + file_relative_path
         if self.site.storage.isFile(file_inner_path + "-new"):  # New version present
             diffs[file_relative_path] = Diff.diff(
                 list(self.site.storage.open(file_inner_path)),
                 list(self.site.storage.open(file_inner_path + "-new")),
                 limit=limit
             )
             if update_files:
                 self.site.storage.delete(file_inner_path)
                 self.site.storage.rename(file_inner_path + "-new", file_inner_path)
         if self.site.storage.isFile(file_inner_path + "-old"):  # Old version present
             diffs[file_relative_path] = Diff.diff(
                 list(self.site.storage.open(file_inner_path + "-old")),
                 list(self.site.storage.open(file_inner_path)),
                 limit=limit
             )
             if update_files:
                 self.site.storage.delete(file_inner_path + "-old")
     return diffs
Esempio n. 2
0
 def getDiffs(self, inner_path, limit=30 * 1024, update_files=True):
     if inner_path not in self.contents:
         return {}
     diffs = {}
     content_inner_path_dir = helper.getDirname(inner_path)
     for file_relative_path in self.contents[inner_path].get("files", {}):
         file_inner_path = content_inner_path_dir + file_relative_path
         if self.site.storage.isFile(file_inner_path + "-new"):  # New version present
             diffs[file_relative_path] = Diff.diff(
                 list(self.site.storage.open(file_inner_path)),
                 list(self.site.storage.open(file_inner_path + "-new")),
                 limit=limit
             )
             if update_files:
                 self.site.storage.delete(file_inner_path)
                 self.site.storage.rename(file_inner_path + "-new", file_inner_path)
         if self.site.storage.isFile(file_inner_path + "-old"):  # Old version present
             diffs[file_relative_path] = Diff.diff(
                 list(self.site.storage.open(file_inner_path + "-old")),
                 list(self.site.storage.open(file_inner_path)),
                 limit=limit
             )
             if update_files:
                 self.site.storage.delete(file_inner_path + "-old")
     return diffs
Esempio n. 3
0
    def testDiff(self):
        assert Diff.diff(
            [],
            ["one", "two", "three"]
        ) == [("+", ["one", "two","three"])]

        assert Diff.diff(
            ["one", "two", "three"],
            ["one", "two", "three", "four", "five"]
        ) == [("=", 11), ("+", ["four", "five"])]

        assert Diff.diff(
            ["one", "two", "three", "six"],
            ["one", "two", "three", "four", "five", "six"]
        ) == [("=", 11), ("+", ["four", "five"]), ("=", 3)]

        assert Diff.diff(
            ["one", "two", "three", "hmm", "six"],
            ["one", "two", "three", "four", "five", "six"]
        ) == [("=", 11), ("-", 3), ("+", ["four", "five"]), ("=", 3)]

        assert Diff.diff(
            ["one", "two", "three"],
            []
        ) == [("-", 11)]
Esempio n. 4
0
    def testDiff(self):
        assert Diff.diff(
            [],
            ["one", "two", "three"]
        ) == [("+", ["one", "two","three"])]

        assert Diff.diff(
            ["one", "two", "three"],
            ["one", "two", "three", "four", "five"]
        ) == [("=", 11), ("+", ["four", "five"])]

        assert Diff.diff(
            ["one", "two", "three", "six"],
            ["one", "two", "three", "four", "five", "six"]
        ) == [("=", 11), ("+", ["four", "five"]), ("=", 3)]

        assert Diff.diff(
            ["one", "two", "three", "hmm", "six"],
            ["one", "two", "three", "four", "five", "six"]
        ) == [("=", 11), ("-", 3), ("+", ["four", "five"]), ("=", 3)]

        assert Diff.diff(
            ["one", "two", "three"],
            []
        ) == [("-", 11)]
Esempio n. 5
0
    def testDiffLimit(self):
        old_f = io.BytesIO(b"one\ntwo\nthree\nhmm\nsix")
        new_f = io.BytesIO(b"one\ntwo\nthree\nfour\nfive\nsix")
        actions = Diff.diff(list(old_f), list(new_f), limit=1024)
        assert actions

        old_f = io.BytesIO(b"one\ntwo\nthree\nhmm\nsix")
        new_f = io.BytesIO(b"one\ntwo\nthree\nfour\nfive\nsix" * 1024)
        actions = Diff.diff(list(old_f), list(new_f), limit=1024)
        assert actions is False
Esempio n. 6
0
    def testDiffLimit(self):
        old_f = StringIO.StringIO("one\ntwo\nthree\nhmm\nsix")
        new_f = StringIO.StringIO("one\ntwo\nthree\nfour\nfive\nsix")
        actions = Diff.diff(list(old_f), list(new_f), limit=1024)
        assert actions

        old_f = StringIO.StringIO("one\ntwo\nthree\nhmm\nsix")
        new_f = StringIO.StringIO("one\ntwo\nthree\nfour\nfive\nsix"*1024)
        actions = Diff.diff(list(old_f), list(new_f), limit=1024)
        assert actions is False
Esempio n. 7
0
 def testPatch(self):
     old_f = StringIO.StringIO("one\ntwo\nthree\nhmm\nsix")
     new_f = StringIO.StringIO("one\ntwo\nthree\nfour\nfive\nsix")
     actions = Diff.diff(
         list(old_f),
         list(new_f)
     )
     old_f.seek(0)
     assert Diff.patch(old_f, actions).getvalue() == new_f.getvalue()
Esempio n. 8
0
 def testPatch(self):
     old_f = io.BytesIO(b"one\ntwo\nthree\nhmm\nsix")
     new_f = io.BytesIO(b"one\ntwo\nthree\nfour\nfive\nsix")
     actions = Diff.diff(
         list(old_f),
         list(new_f)
     )
     old_f.seek(0)
     assert Diff.patch(old_f, actions).getvalue() == new_f.getvalue()
Esempio n. 9
0
 def testUtf8(self):
     assert Diff.diff(
         ["one", "\xe5\xad\xa6\xe4\xb9\xa0\xe4\xb8\x8b", "two", "three"], [
             "one", "\xe5\xad\xa6\xe4\xb9\xa0\xe4\xb8\x8b", "two", "three",
             "four", "five"
         ]) == [("=", 20), ("+", ["four", "five"])]