Lucas: This one likely conflicts slightly with your recent setuptools version change patch. On recent RPM based distros I suspect they have a similar python-setuptools package available of sufficiently recent version that the change below could be extended to support installing the OS package on those as well.
Install setuptools via apt-get on debian/ubuntu systems when a system package of sufficient version exists instead of building and installing our own on the system Python. This is mostly to avoid gLucid users polluting their system Python. Signed-off-by: Gregory Smith <[email protected]> --- autotest/utils/external_packages.py 2010-04-28 16:36:06.000000000 -0700 +++ autotest/utils/external_packages.py 2010-09-14 10:58:13.000000000 -0700 @@ -478,7 +478,7 @@ # For all known setuptools releases a string compare works for the # version string. Hopefully they never release a 0.10. (Their own # version comparison code would break if they did.) - version = '0.6c9' + version = '0.6' urls = ('http://pypi.python.org/packages/source/s/setuptools/' 'setuptools-%s.tar.gz' % (version,),) local_filename = 'setuptools-%s.tar.gz' % version @@ -487,6 +487,57 @@ SUDO_SLEEP_DELAY = 15 + def is_needed(self, *args, **kwargs): + """ + If the package is needed, this first checks if there is a suitable + Ubuntu package and installs that. If that works, great. Otherwise + we report it as needed and continue to install our own build. + + Ubuntu Lucid comes with a more than sufficiently recent version. + """ + super_needed = ExternalPackage.is_needed(self, *args, **kwargs) + if super_needed and os.path.exists('/etc/debian_version'): + debian_pkg_name = 'python-setuptools' + pkg_version = self._get_deb_package_version(debian_pkg_name) + if pkg_version >= self.version: + logging.info('found acceptable Debian/Ubuntu %s %s', + debian_pkg_name, pkg_version) + self._display_sudo_warning(pkg_version) + rc = os.system('sudo apt-get install ' + debian_pkg_name) + if rc == 0: + # un-import the previous version, if any to re-test it. + if self.module_name in sys.modules: + del sys.modules[self.module_name] + # re-test that the import works. + return ExternalPackage.is_needed(self, *args, **kwargs) + return super_needed + + + def _get_deb_package_version(self, pkg_name): + """Returns the version from a given package in apt. '' means unknown.""" + p = subprocess.Popen(['apt-cache', 'show', pkg_name], + stdout=subprocess.PIPE) + pkg_info = p.communicate()[0] + rc = p.wait() + if rc != 0: + return '' + for line in pkg_info.splitlines(): + if line.startswith('Version:'): + pkg_version = line.split(':', 2)[1] + pkg_version = pkg_version.strip() + return pkg_version + return '' + + + def _display_sudo_warning(self, version): + print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' + print 'About to run sudo to install setuptools', version + print 'on your system for use by', sys.executable, '\n' + print '!! ^C within', self.SUDO_SLEEP_DELAY, 'seconds to abort.\n' + time.sleep(self.SUDO_SLEEP_DELAY) + + + def _build_and_install(self, install_dir): """Install setuptools on the system.""" logging.info('NOTE: setuptools install does not use install_dir.') @@ -497,13 +548,7 @@ egg_path = self._build_egg_using_setup_py() if not egg_path: return False - - print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' - print 'About to run sudo to install setuptools', self.version - print 'on your system for use by', sys.executable, '\n' - print '!! ^C within', self.SUDO_SLEEP_DELAY, 'seconds to abort.\n' - time.sleep(self.SUDO_SLEEP_DELAY) - + self._display_sudo_warning(self.version) # Copy the egg to the local filesystem /var/tmp so that root can # access it properly (avoid NFS squashroot issues). temp_dir = self._get_temp_dir() _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
