[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Adjust shebang line of installed nyx script
commit 8e050ea63ac3e7a69422352c78568d64d55cc517
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Jun 9 09:35:08 2015 -0700
Adjust shebang line of installed nyx script
Very good point from Yawning that we should adjust our shebang line to match
the interpreter that's installing us...
https://trac.torproject.org/projects/tor/ticket/16317
This is based on the copy_scripts() method of...
distutils/command/build_scripts.py
---
setup.py | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/setup.py b/setup.py
index b07995f..d780228 100644
--- a/setup.py
+++ b/setup.py
@@ -6,6 +6,7 @@ import gzip
import os
import shutil
import stat
+import sysconfig
import nyx
@@ -57,9 +58,22 @@ class NyxInstaller(install):
# Install our bin script. We do this ourselves rather than with the setup()
# method's scripts argument because we want to call the script 'nyx' rather
# than 'run_nyx'.
+ #
+ # If using setuptools this would be better replaced with its entry_points.
self.mkpath(os.path.dirname(dest))
- shutil.copyfile(source, dest)
+
+ with open(source, 'rb') as source_file:
+ with open(dest, 'wb') as dest_file:
+ orig_shebang = source_file.readline()
+
+ python_cmd = 'python%s%s' % (sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('EXE'))
+ new_shebang = '#!%s\n' % os.path.join(sysconfig.get_config_var('BINDIR'), python_cmd)
+
+ log.info("adjusting bin script's shebang line '%s' -> '%s'" % (orig_shebang.strip(), new_shebang.strip()))
+ dest_file.write(new_shebang)
+ dest_file.write(source_file.read())
+
mode = ((os.stat(dest)[stat.ST_MODE]) | 0o555) & 0o7777
os.chmod(dest, mode)
log.info("installed bin script to '%s'" % dest)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits