[Patches] [ python-Patches-1617496 ] The ability to keep configuration files intact

SourceForge.net noreply at sourceforge.net
Sun Dec 17 21:02:10 CET 2006


Patches item #1617496, was opened at 2006-12-17 23:02
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1617496&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Distutils and setup.py
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Roman Kurakin (sagamore)
Assigned to: Nobody/Anonymous (nobody)
Summary: The ability to keep configuration files intact

Initial Comment:
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'])
       ]


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1617496&group_id=5470


More information about the Patches mailing list