mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 15:39:43 +00:00
flat tree comparison
This commit is contained in:
@@ -10,6 +10,7 @@ import filecmp
|
||||
|
||||
# local imports
|
||||
from dotdrop.logger import Logger
|
||||
from dotdrop.ftree import FTreeDir
|
||||
from dotdrop.utils import must_ignore, uniq_list, diff, \
|
||||
get_file_perm
|
||||
|
||||
@@ -22,12 +23,24 @@ class Comparator:
|
||||
"""constructor
|
||||
@diff_cmd: diff command to use
|
||||
@debug: enable debug
|
||||
@ignore_missing_in_dotdrop: ignore missing files in dotdrop
|
||||
"""
|
||||
self.diff_cmd = diff_cmd
|
||||
self.debug = debug
|
||||
self.log = Logger(debug=self.debug)
|
||||
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):
|
||||
"""
|
||||
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