[27556] in Source-Commits

home help back first fref pref prev next nref lref last post

pyhesiodfs commit: Move script name logic to setup.py

daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Tue Dec 31 12:27:31 2013

Date: Tue, 31 Dec 2013 12:27:23 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201312311727.rBVHRNGI027062@drugstore.mit.edu>
To: source-commits@MIT.EDU

https://github.com/mit-athena/pyhesiodfs/commit/4d3308c6c00a66eb3191d210a42dbb83a4e82b0a
commit 4d3308c6c00a66eb3191d210a42dbb83a4e82b0a
Author: Jonathan Reed <jdreed@mit.edu>
Date:   Mon Nov 4 13:38:12 2013 -0500

    Move script name logic to setup.py
    
    Rather than renaming the script in the rules file, move the logic
    to setup.py itself, making use of custom distutils commands to
    do the work for us.

 debian/rules |    6 ------
 setup.py     |   32 ++++++++++++++++++++++++++++----
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/debian/rules b/debian/rules
index 21f08bb..9e8e934 100755
--- a/debian/rules
+++ b/debian/rules
@@ -11,12 +11,6 @@ endif
 
 DEB_UPDATE_RCD_PARAMS_debathena-pyhesiodfs += defaults 15 85
 
-clean::
-	if [ -f pyhesiodfs ]; then mv pyhesiodfs pyHesiodFS.py; fi
-
 include /usr/share/cdbs/1/rules/debhelper.mk
 include /usr/share/cdbs/1/rules/config-package.mk
 include /usr/share/cdbs/1/class/python-distutils.mk
-
-common-configure-indep::
-	if [ -f pyHesiodFS.py ]; then mv pyHesiodFS.py pyhesiodfs; fi
diff --git a/setup.py b/setup.py
index 4885939..4d4f956 100644
--- a/setup.py
+++ b/setup.py
@@ -1,13 +1,33 @@
 from distutils.core import setup
-import sys
+from distutils.command.build_scripts import build_scripts
+from distutils.command.clean import clean
+import sys, os, shutil, filecmp
 
 extra_options = {}
 
-# The script is named this on all platforms except OS X
-script_name='pyhesiodfs'
 if sys.platform == 'darwin':
     extra_options['data_files'] = [('/Library/LaunchDaemons', ('edu.mit.sipb.mit-automounter.plist',))]
-    script_name='pyHesiodFS.py
+    copy_file = None
+    script_name = 'pyHesiodFS.py'
+else:
+    script_name='pyhesiodfs'
+    copy_file = ('pyHesiodFS.py', 'pyhesiodfs')
+
+class BuildScriptsCommand(build_scripts):
+    def finalize_options(self):
+        build_scripts.finalize_options(self)
+        if copy_file is not None:
+            if os.path.isfile(copy_file[1]) and not filecmp.cmp(*copy_file, shallow=False):
+                raise Exception("Will not overwrite existing '%s' with '%s'" % tuple(reversed(copy_file)))
+            shutil.copyfile(*copy_file)
+
+class CleanCommand(clean):
+    def finalize_options(self):
+        clean.finalize_options(self)
+        if copy_file is not None and os.path.isfile(copy_file[1]):
+            if not filecmp.cmp(*copy_file, shallow=False):
+                raise Exception("Will not remove '%s', it's not the same as '%s'" % tuple(reversed(copy_file)))
+            os.unlink(copy_file[1])
 
 setup(name='pyHesiodFS',
       version='1.0.1',
@@ -17,4 +37,8 @@ setup(name='pyHesiodFS',
       maintainer_email='debathena@mit.edu',
       scripts=[script_name],
       requires=['PyHesiod (>=0.2.0)'],
+      cmdclass={
+        'clean': CleanCommand,
+        'build_scripts': BuildScriptsCommand,
+        },
       **extra_options)

home help back first fref pref prev next nref lref last post