From f38ef1bfff02f2d89b7ca982f87ac677e1f03ea2 Mon Sep 17 00:00:00 2001 From: Amber Date: Mon, 18 Nov 2024 10:27:53 +0100 Subject: [PATCH] rawdiff --- src/lib/snapshot/diff.py | 18 +++++++++++------- src/testing/rawdiff.py | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/lib/snapshot/diff.py b/src/lib/snapshot/diff.py index 9832068..a7f8b9c 100644 --- a/src/lib/snapshot/diff.py +++ b/src/lib/snapshot/diff.py @@ -1,15 +1,16 @@ import os def recursive_raw_diff(tree_a, tree_b, tree_a_tag, tree_b_tag, path, res): - a_keys_not_in_b = set(tree_a.keys()) - set(tree_b.keys()) + # a_keys_not_in_b = set(tree_a.keys()) - set(tree_b.keys()) # b_keys_not_in_a = set(tree_b.keys()) - set(tree_a.keys()) ## name last is a dir - if a_keys_not_in_b: - for key in a_keys_not_in_b: - print(f'node {path}{key} subtree added in {tree_a_tag}') - res[f'{path}{key}'] = { - tree_a_tag : 'x', - } + # manage below + # if a_keys_not_in_b: + # for key in a_keys_not_in_b: + # print(f'node {path}{key} subtree added in {tree_a_tag}') + # res[f'{path}{key}'] = { + # tree_a_tag : 'x', + # } for key_a, hsh_a in tree_a.items(): hsh_b = tree_b.get(key_a) @@ -18,6 +19,9 @@ def recursive_raw_diff(tree_a, tree_b, tree_a_tag, tree_b_tag, path, res): ''' already in `a_keys_not_in_b` ''' + res[f'{path}{key_a}'] = { + tree_a_tag : 'x', + } continue diff --git a/src/testing/rawdiff.py b/src/testing/rawdiff.py index 65db63b..373eea1 100644 --- a/src/testing/rawdiff.py +++ b/src/testing/rawdiff.py @@ -2,10 +2,43 @@ from lib.snapshot import diff -tree_a = {'taglioCapelli4.jpg': '5af62402ec7716e8d729b0683061f0c4', 'taglioCapelli5.jpg': '9c42961af589a279c4c828925291153b', 'pino.txt': 'd41d8cd98f00b204e9800998ecf8427e', 'taglioCapelli6.jpg': '4059905eab817c33ee48f912af80fdb7', 'spartiti_sepu': {'amber.py': 'a6ef147511264ecdc7d6061979892c44', 'bo.txt': 'd7aa6cbc6aa0ace3225ee1738b2d5c6b', 'ciao': {'amber.py': 'a6ef147511264ecdc7d6061979892c44', 'bo.txt': 'd7aa6cbc6aa0ace3225ee1738b2d5c6b'},'added_folder': {}}, 'preferiti.txt': 'af45981ef2be534dbb37f96833d3fd04'} - -tree_b = {'taglioCapelli4.jpg': '5af62402ec7716e8d729b0683061f0c4', 'taglioCapelli5.jpg': '9c42961af589a279c4c828925291153b', 'pino.txt': 'd41d8cd98f00b204e9800998ecf8427e', 'taglioCapelli6.jpg': '4059905eab817c33ee48f912af80fdb7', 'spartiti_sepu': {'amber.py': 'a6ef147511264ecdc7d6061979892c44', 'bo.txt': 'd7aa6cbc6aa0ace3225ee1738b2d5c6b', 'added_folder': {'preferiti.txt' : 'af45981ef2be534dbb37f96833d3fd03'}}, 'preferiti.txt': 'af45981ef2be534dbb37f9fffffffff'} +tree_a = { + "taglioCapelli4.jpg": "5af62402ec7716e8d729b0683061f0c4", + "taglioCapelli5.jpg": "9c42961af589a279c4c828925291153b", + "pino.txt": "d41d8cd98f00b204e9800998ecf8427e", + "taglioCapelli6.jpg": "4059905eab817c33ee48f912af80fdb7", + "spartiti_sepu": { + "amber.py": "a6ef147511264ecdc7d6061979892c44", + "bo.txt": "d7aa6cbc6aa0ace3225ee1738b2d5c6b", + "ciao": { + "amber.py": "a6ef147511264ecdc7d6061979892c44", + "bo.txt": "d7aa6cbc6aa0ace3225ee1738b2d5c6b" + }, + "added_folder": {} + }, + "preferiti.txt": "af45981ef2be534dbb37f96833d3fd04" +} +tree_b = { + "taglioCapelli4.jpg": "5af62402ec7716e8d729b0683061f0c4", + "taglioCapelli5.jpg": "9c42961af589a279c4c828925291153b", + # "pino.txt": "d41d8cd98f00b204e9800998ecf8427e", + "pino" : { + "a" : { + }, + "c" : {"5af62402ec7716e8d729b068fasdf"}, + "d" : {"1234f02ec7716e8d729b068fasdf"}, + }, + "taglioCapelli6.jpg": "4059905eab817c33ee48f912af80fdb7", + "spartiti_sepu": { + "amber.py": "a6ef147511264ecdc7d6061979892c44", + "bo.txt": "d7aa6cbc6aa0ace3225ee1738b2d5c6b", + "added_folder": { + "preferiti.txt": "af45981ef2be534dbb37f96833d3fd03" + } + }, + "preferiti.txt": "af45981ef2be534dbb37f9fffffffff" +} def test_raw_diff():