changeset 39047:8bd0b74f5c0f

vfs: make patch path a property
author Dmitry Selyutin <ghostmansd@gmail.com>
date Fri, 20 Oct 2017 20:41:21 +0300
parents 27fd4beae98e
children 13693b2945b4
files pygnulib/vfs.py
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pygnulib/vfs.py	Fri Oct 20 20:24:17 2017 +0300
+++ b/pygnulib/vfs.py	Fri Oct 20 20:41:21 2017 +0300
@@ -20,15 +20,13 @@
 
 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 @@
         if not _os_.path.isdir(path):
             raise NotADirectoryError(path)
         super().__init__(name, **table)
+        self.__patch = None
 
 
     def __contains__(self, name):
@@ -82,6 +81,22 @@
         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: