From 0283d4179801f30d08c41fb124c8497aab51ac54 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 18 May 2012 16:34:40 +0000 Subject: [PATCH] Replace INSTALL_LIB on installation. This restores code removed in r28342, which rewrites sys.path to include the directory in which the Zenmap modules are installed. This is needed to run the program without changes to PYTHONPATH when the installation directory is not among the Python interpreter's default search paths. (/usr/local/lib/python2.7/site-packages/ or a user's home directory are common cases.) A difference is that now we make sure that the directory we are adding is not writable by any other users, to avoid installation mistakes like Debian bug #663217. --- zenmap/setup.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/zenmap/setup.py b/zenmap/setup.py index 942d7d643..36e87808f 100755 --- a/zenmap/setup.py +++ b/zenmap/setup.py @@ -205,6 +205,7 @@ class my_install(install): install.run(self) self.set_perms() + self.set_modules_path() self.fix_paths() self.create_uninstaller() self.write_installed_files() @@ -306,6 +307,30 @@ for dir in dirs: mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 os.chmod(uninstaller_filename, mode) + def set_modules_path(self): + app_file_name = os.path.join(self.install_scripts, APP_NAME) + # Find where the modules are installed. distutils will put them in + # self.install_lib, but that path can contain the root (DESTDIR), so we + # must strip it off if necessary. + modules_dir = self.install_lib + if self.root is not None: + modules_dir = path_strip_prefix(modules, self.root) + + app_file = open(app_file_name, "r") + lines = app_file.readlines() + app_file.close() + + for i in range(len(lines)): + if re.match(r'^INSTALL_LIB =', lines[i]): + lines[i] = "INSTALL_LIB = %s\n" % repr(modules_dir) + break + else: + raise ValueError("INSTALL_LIB replacement not found in %s" % app_file_name) + + app_file = open(app_file_name, "w") + app_file.writelines(lines) + app_file.close() + def set_perms(self): re_bin = re.compile("(bin|\.sh)") for output in self.get_installed_files():