This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The ability to keep configuration files intact
Type: Stage:
Components: Distutils Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: loewis, sagamore
Priority: normal Keywords: patch

Created on 2006-12-17 20:02 by sagamore, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg51554 - (view) Author: Roman Kurakin (sagamore) Date: 2006-12-17 20:02
While working on one project I've met a problem that I can't to specify to not tuch my configuration files for python package that uses setup.py technique. To solve this problem I've implemented the following solution that works for me. If this idea worths it, I could made a pacth relative needed version of python.

+class smart_install_data(install_data):
+    def run(self):
+        # Use revers order for safe removal
+        for i in range(len(self.data_files)-1, -1, -1):
+            f = self.data_files[i]
+            if type(f) is StringType:
+                continue
+            if len(f) <= 2:
+               continue
+            # Ok, we have additional value, do some magick according it.
+            if f[2] != "preserve":
+                # Nope, we do not know it. Just ignore for now.
+                # Should we scream about it?
+                continue
+            # Check a tuple with path to install to and a list of files
+            dir = convert_path(f[0])
+            if not os.path.isabs(dir):
+                dir = os.path.join(self.install_dir, dir)
+            elif self.root:
+                dir = change_root(self.root, dir)
+
+            if f[1] == []:
+                # If there are no files listed, the user must be
+                # trying to create an empty directory, so just ignore
+                # it.
+                # Should we scream in this case?
+                continue
+
+            # Check files one by one.
+            # Use revers order for safe removal
+            for j in range(len(f[1])-1, -1, -1):
+                data=f[1][j]
+                data = convert_path(data)
+                if not os.path.isfile(data):
+                    # Again skip dirs.
+                    continue
+                dst = os.path.join(dir, os.path.basename(data))
+                if not os.path.exists(dst):
+                    continue
+                del f[1][j]
+            if len(f[1]) == 0:
+                del self.data_files[i]
+
+        return install_data.run(self)

 setup(name = 'usher',
       version = '0.1',
       package_dir = { 'usher':'python' },
       packages = ['usher', 'usher.ushercli', 'usher.usherlnm', 'usher.utils', 'usher.usherctrl'],
+      cmdclass = {'install_data':smart_install_data},
       data_files = [
           ('/etc/init.d', ['initscripts/usherctrl', 'initscripts/usherlnm']),
-          ('/etc/usher', ['configs/usherctrl.config', 'configs/usherlnm.config', 'configs/ushercli.config']),
+          ('/etc/usher', ['configs/usherctrl.config', 'configs/usherlnm.config', 'configs/ushercli.config'], "preserve"),
           ("/usr/lib/python%s/site-packages/usher/usherctrl" % pyver, ['python/usherctrl/app.tac']),
           ("/usr/lib/python%s/site-packages/usher/usherlnm" % pyver, ['python/usherlnm/app.tac'])
       ]
msg51555 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-12-17 20:33
Please suggest this feature to the distutils-sig first (http://www.python.org/community/sigs/current/distutils-sig/)

After collecting feedback, please resubmit it as a new patch, and use a file attachment then, rather than including it in the message itself (it is incomprehensible as it stands). Also please include documentation changes.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44347
2006-12-17 20:02:10sagamorecreate