codekingpro/portable-devtools
115k
1from distutils import log2import distutils.command.install_scripts as orig3import os4import sys5 6from .._path import ensure_directory7 8 9class install_scripts(orig.install_scripts):10 """Do normal script install, plus any egg_info wrapper scripts"""11 12 def initialize_options(self):13 orig.install_scripts.initialize_options(self)14 self.no_ep = False15 16 def run(self):17 self.run_command("egg_info")18 if self.distribution.scripts:19 orig.install_scripts.run(self) # run first to set up self.outfiles20 else:21 self.outfiles = []22 if self.no_ep:23 # don't install entry point scripts into .egg file!24 return25 self._install_ep_scripts()26 27 def _install_ep_scripts(self):28 # Delay import side-effects29 from pkg_resources import Distribution, PathMetadata30 from . import easy_install as ei31 32 ei_cmd = self.get_finalized_command("egg_info")33 dist = Distribution(34 ei_cmd.egg_base,35 PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),36 ei_cmd.egg_name,37 ei_cmd.egg_version,38 )39 bs_cmd = self.get_finalized_command('build_scripts')40 exec_param = getattr(bs_cmd, 'executable', None)41 writer = ei.ScriptWriter42 if exec_param == sys.executable:43 # In case the path to the Python executable contains a space, wrap44 # it so it's not split up.45 exec_param = [exec_param]46 # resolve the writer to the environment47 writer = writer.best()48 cmd = writer.command_spec_class.best().from_param(exec_param)49 for args in writer.get_args(dist, cmd.as_header()):50 self.write_script(*args)51 52 def write_script(self, script_name, contents, mode="t", *ignored):53 """Write an executable file to the scripts directory"""54 from setuptools.command.easy_install import chmod, current_umask55 56 log.info("Installing %s script to %s", script_name, self.install_dir)57 target = os.path.join(self.install_dir, script_name)58 self.outfiles.append(target)59 60 mask = current_umask()61 if not self.dry_run:62 ensure_directory(target)63 f = open(target, "w" + mode)64 f.write(contents)65 f.close()66 chmod(target, 0o777 - mask)67 