]> Savannah Git Hosting - gnulib.git/commitdiff
vfs: make patch path a property
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 20 Oct 2017 17:41:21 +0000 (20:41 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 20 Oct 2017 19:46:49 +0000 (22:46 +0300)
pygnulib/vfs.py

index 374389d980b89062e262c034f533a50dd2519daa..b6b659da8389a1f719703033a02c6c8e13509706 100644 (file)
@@ -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: