From: <pj...@us...> - 2009-03-29 20:07:48
|
Revision: 6114 http://jython.svn.sourceforge.net/jython/?rev=6114&view=rev Author: pjenvey Date: 2009-03-29 20:07:31 +0000 (Sun, 29 Mar 2009) Log Message: ----------- o workaround our shebang line issues (#1112) by using /usr/bin/env when we can o make installed scripts executable Modified Paths: -------------- trunk/jython/Lib/distutils/command/build_scripts.py trunk/jython/Lib/distutils/command/install_scripts.py Modified: trunk/jython/Lib/distutils/command/build_scripts.py =================================================================== --- trunk/jython/Lib/distutils/command/build_scripts.py 2009-03-29 20:00:29 UTC (rev 6113) +++ trunk/jython/Lib/distutils/command/build_scripts.py 2009-03-29 20:07:31 UTC (rev 6114) @@ -94,18 +94,18 @@ if adjust: log.info("copying and adjusting %s -> %s", script, self.build_dir) + if not sysconfig.python_build: + executable = self.executable + else: + executable = os.path.join( + sysconfig.get_config_var("BINDIR"), + "python" + sysconfig.get_config_var("EXE")) + executable = fix_jython_executable(executable, post_interp) if not self.dry_run: outf = open(outfile, "w") - if not sysconfig.python_build: - outf.write("#!%s%s\n" % - (self.executable, - post_interp)) - else: - outf.write("#!%s%s\n" % - (os.path.join( - sysconfig.get_config_var("BINDIR"), - "python" + sysconfig.get_config_var("EXE")), - post_interp)) + outf.write("#!%s%s\n" % + (executable, + post_interp)) outf.writelines(f.readlines()) outf.close() if f: @@ -115,7 +115,7 @@ f.close() self.copy_file(script, outfile) - if os.name == 'posix': + if hasattr(os, 'chmod'): for file in outfiles: if self.dry_run: log.info("changing mode of %s", file) @@ -130,3 +130,29 @@ # copy_scripts () # class build_scripts + + +def is_sh(executable): + """Determine if the specified executable is a .sh (contains a #! line)""" + try: + fp = open(executable) + magic = fp.read(2) + fp.close() + except IOError, OSError: + return executable + return magic == '#!' + + +def fix_jython_executable(executable, options): + if sys.platform.startswith('java') and is_sh(executable): + # Workaround Jython's sys.executable being a .sh (an invalid + # shebang line interpreter) + if options: + # Can't apply the workaround, leave it broken + log.warn("WARNING: Unable to adapt shebang line for Jython," + " the following script is NOT executable\n" + " see http://bugs.jython.org/issue1112 for" + " more information.") + else: + return '/usr/bin/env %s' % executable + return executable Modified: trunk/jython/Lib/distutils/command/install_scripts.py =================================================================== --- trunk/jython/Lib/distutils/command/install_scripts.py 2009-03-29 20:00:29 UTC (rev 6113) +++ trunk/jython/Lib/distutils/command/install_scripts.py 2009-03-29 20:07:31 UTC (rev 6114) @@ -46,7 +46,7 @@ if not self.skip_build: self.run_command('build_scripts') self.outfiles = self.copy_tree(self.build_dir, self.install_dir) - if os.name == 'posix': + if hasattr(os, 'chmod'): # Set the executable bits (owner, group, and world) on # all the scripts we just installed. for file in self.get_outputs(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |