From ec71059a2727cd7b8038a34059762913695b3b89 Mon Sep 17 00:00:00 2001 From: Rui Pinheiro Date: Sat, 23 Mar 2024 18:09:10 +0000 Subject: [PATCH 1/2] Do not snapshot child filesystem if it has a more specific config --- pyznap/take.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pyznap/take.py b/pyznap/take.py index 4ac1a5f..4014eb6 100644 --- a/pyznap/take.py +++ b/pyznap/take.py @@ -127,11 +127,14 @@ def take_config(config): logger = logging.getLogger(__name__) logger.info('Taking snapshots...') + config_d = {} for conf in config: + config_d[conf['name']] = conf + + for name,conf in config_d.items(): if not conf.get('snap', None): continue - name = conf['name'] try: _type, fsname, user, host, port = parse_name(name) except ValueError as err: @@ -164,9 +167,20 @@ def take_config(config): else: # Take recursive snapshot of parent filesystem take_filesystem(children[0], conf) - # Take snapshot of all children that don't have all snapshots yet + + # Take snapshot of all children that do not have a more specific config for child in children[1:]: - take_filesystem(child, conf) + skip = False + if child.name in config_d: + skip = True + else: + for other_name in config_d.keys(): + if other_name.startswith(name + '/') and child.name.startswith(other_name + '/'): + skip = True + break + + if not skip: + take_filesystem(child, conf) finally: if ssh: ssh.close() From 312089c5539414791e4d393f6dc1e17eb9493921 Mon Sep 17 00:00:00 2001 From: Rui Pinheiro Date: Thu, 7 Aug 2025 10:18:58 +0100 Subject: [PATCH 2/2] Remove dependency on pkg_resources which is deprecated in python 3.10 --- pyznap/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyznap/utils.py b/pyznap/utils.py index 1182419..edb4b48 100644 --- a/pyznap/utils.py +++ b/pyznap/utils.py @@ -11,6 +11,7 @@ import os import re import logging +import pathlib from subprocess import Popen, PIPE, TimeoutExpired, CalledProcessError from .process import run from .ssh import SSHException @@ -18,7 +19,6 @@ from datetime import datetime from configparser import (ConfigParser, NoOptionError, MissingSectionHeaderError, DuplicateSectionError, DuplicateOptionError) -from pkg_resources import resource_string def exists(executable='', ssh=None): @@ -171,7 +171,10 @@ def create_config(path): logger = logging.getLogger(__name__) CONFIG_FILE = os.path.join(path, 'pyznap.conf') - config = resource_string(__name__, 'config/pyznap.conf').decode("utf-8") + + config_path = (pathlib.Path(__file__).parent.resolve() / 'config' / 'pyznap.conf').absolute() + with open(config_path, 'r') as file: + config = file.read() logger.info('Initial setup...')