mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-15 17:20:05 +00:00
flat tree comparison
This commit is contained in:
@@ -10,6 +10,7 @@ import filecmp
|
|||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from dotdrop.logger import Logger
|
from dotdrop.logger import Logger
|
||||||
|
from dotdrop.ftree import FTreeDir
|
||||||
from dotdrop.utils import must_ignore, uniq_list, diff, \
|
from dotdrop.utils import must_ignore, uniq_list, diff, \
|
||||||
get_file_perm
|
get_file_perm
|
||||||
|
|
||||||
@@ -22,12 +23,24 @@ class Comparator:
|
|||||||
"""constructor
|
"""constructor
|
||||||
@diff_cmd: diff command to use
|
@diff_cmd: diff command to use
|
||||||
@debug: enable debug
|
@debug: enable debug
|
||||||
|
@ignore_missing_in_dotdrop: ignore missing files in dotdrop
|
||||||
"""
|
"""
|
||||||
self.diff_cmd = diff_cmd
|
self.diff_cmd = diff_cmd
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.log = Logger(debug=self.debug)
|
self.log = Logger(debug=self.debug)
|
||||||
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
||||||
|
|
||||||
|
def compare2(self, local_path, deployed_path, ignore=None, mode=None):
|
||||||
|
"""
|
||||||
|
diff local_path (dotdrop dotfile) and
|
||||||
|
deployed_path (destination file)
|
||||||
|
If mode is None, rights will be read from local_path
|
||||||
|
"""
|
||||||
|
local_tree = FTreeDir(local_path, ignores=ignore, debug=self.debug)
|
||||||
|
deploy_tree = FTreeDir(deployed_path, ignores=ignore, debug=self.debug)
|
||||||
|
lonly, ronly, common = local_tree.compare(deploy_tree)
|
||||||
|
# TODO
|
||||||
|
|
||||||
def compare(self, local_path, deployed_path, ignore=None, mode=None):
|
def compare(self, local_path, deployed_path, ignore=None, mode=None):
|
||||||
"""
|
"""
|
||||||
diff local_path (dotdrop dotfile) and
|
diff local_path (dotdrop dotfile) and
|
||||||
|
|||||||
45
dotdrop/ftree.py
Normal file
45
dotdrop/ftree.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
"""
|
||||||
|
author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
|
Copyright (c) 2024, deadc0de6
|
||||||
|
|
||||||
|
filesystem tree for directories
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from dotdrop.utils import must_ignore
|
||||||
|
|
||||||
|
|
||||||
|
class FTreeDir:
|
||||||
|
|
||||||
|
def __init__(self, path, ignores=None, debug=False):
|
||||||
|
self.path = path
|
||||||
|
self.ignores
|
||||||
|
self.debug = debug
|
||||||
|
self.entries = []
|
||||||
|
if os.path.exists(path) and os.path.isdir(path):
|
||||||
|
self._walk()
|
||||||
|
|
||||||
|
def _walk(self):
|
||||||
|
for root, _, files in os.walk(self.path):
|
||||||
|
for f in files:
|
||||||
|
fpath = os.path.join(root, f)
|
||||||
|
if must_ignore([fpath], ignores=self.ignores,
|
||||||
|
debug=self.debug):
|
||||||
|
continue
|
||||||
|
self.entries.append(fpath)
|
||||||
|
self.entries.sort()
|
||||||
|
|
||||||
|
def compare(self, other):
|
||||||
|
"""
|
||||||
|
compare two trees and returns
|
||||||
|
- left_only (only in self)
|
||||||
|
- right_only (only in other)
|
||||||
|
- in_both (in both)
|
||||||
|
"""
|
||||||
|
left_only = set(self.entries) - set(other.entries)
|
||||||
|
right_only = set(other.entries) - set(self.entries)
|
||||||
|
in_both = set(self.entries) & set(other.entries)
|
||||||
|
return left_only, right_only, in_both
|
||||||
Reference in New Issue
Block a user