From 1969829ed70af2dd7ca90c49d97e1279c26581c2 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 20 Oct 2017 20:41:21 +0300 Subject: [PATCH] vfs: make patch path a property --- pygnulib/vfs.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pygnulib/vfs.py b/pygnulib/vfs.py index 374389d980..b6b659da83 100644 --- a/pygnulib/vfs.py +++ b/pygnulib/vfs.py @@ -20,15 +20,13 @@ from .module import File as _FileModule_ class Base: """gnulib generic virtual file system""" - def __init__(self, root, patch="patch", **table): + def __init__(self, root, **table): _type_assert_("root", root, str) - _type_assert_("patch", patch, str) self.__table = {} for (key, value) in table.items(): _type_assert_(key, value, str) self.__table[key] = _os_.path.normpath(value) self.__root = root - self.__patch = patch def __repr__(self): @@ -72,6 +70,7 @@ class Project(Base): if not _os_.path.isdir(path): raise NotADirectoryError(path) super().__init__(name, **table) + self.__patch = None def __contains__(self, name): @@ -82,6 +81,22 @@ class Project(Base): return _os_.path.exists(path) + @property + def patch(self): + """path to patch binary""" + if self.__patch is None: + raise AttributeError("patch") + return self.__patch + + @patch.setter + def patch(self, path): + _type_assert_("path", path, str) + if not _os_.path.isabs(path): + if _shutil_.which(path) is None: + raise FileNotFoundError("patch") + self.__patch = path + + def __backup(self, name): backup = "{}~".format(name) try: -- 2.39.5