diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion index 7edc9df8a758b933967598e0a2e078ad0a2366a4..7368dab32131c376484f6276a7f5e667b618594c 100755 --- a/autotools/build-bash-completion +++ b/autotools/build-bash-completion @@ -28,6 +28,7 @@ from cStringIO import StringIO from ganeti import constants from ganeti import cli from ganeti import utils +from ganeti import build # _autoconf shouldn't be imported from anywhere except constants.py, but we're # making an exception here because this script is only used at build time. @@ -606,10 +607,10 @@ def main(): WriteCompletion(sw, scriptname, GetFunctionName(scriptname), commands=GetCommands(filename, - utils.LoadModule(filename))) + build.LoadModule(filename))) # Burnin script - burnin = utils.LoadModule("tools/burnin") + burnin = build.LoadModule("tools/burnin") WriteCompletion(sw, "%s/burnin" % constants.TOOLSDIR, "_ganeti_burnin", opts=burnin.OPTIONS, args=burnin.ARGUMENTS) diff --git a/lib/build/__init__.py b/lib/build/__init__.py index 007afb2852825e60ec6fa1c584f896db1469a43d..0f58b61f9b213e9757f3956fdb4c2e08b2d9c383 100644 --- a/lib/build/__init__.py +++ b/lib/build/__init__.py @@ -17,3 +17,26 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. + + +import imp +import os + + +def LoadModule(filename): + """Loads an external module by filename. + + Use this function with caution. Python will always write the compiled source + to a file named "${filename}c". + + @type filename: string + @param filename: Path to module + + """ + (name, ext) = os.path.splitext(filename) + + fh = open(filename, "U") + try: + return imp.load_module(name, fh, filename, (ext, "U", imp.PY_SOURCE)) + finally: + fh.close() diff --git a/lib/utils.py b/lib/utils.py index 07be8c04f2412ac60f06dc003c4d3f00cfdd75d8..80e0d9a4dbe3888c17369b0e5a50c76facd6aad9 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -42,7 +42,6 @@ import fcntl import resource import logging import signal -import imp from cStringIO import StringIO @@ -1995,25 +1994,6 @@ def ReadWatcherPauseFile(filename, now=None, remove_after=3600): return value -def LoadModule(filename): - """Loads an external module by filename. - - Use this function with caution. Python will always write the compiled source - to a file named "${filename}c". - - @type filename: string - @param filename: Path to module - - """ - (name, ext) = os.path.splitext(filename) - - fh = open(filename, "U") - try: - return imp.load_module(name, fh, filename, (ext, "U", imp.PY_SOURCE)) - finally: - fh.close() - - class FileLock(object): """Utility class for file locks. diff --git a/test/docs_unittest.py b/test/docs_unittest.py index 447061f1e3c410383dacfa63e6b4f880c54064cc..d69066f4a8fbd13e1be3ce98d711384f17c837b9 100755 --- a/test/docs_unittest.py +++ b/test/docs_unittest.py @@ -27,6 +27,7 @@ import re from ganeti import _autoconf from ganeti import utils from ganeti import cmdlib +from ganeti import build from ganeti.rapi import connector import testutils @@ -126,7 +127,7 @@ class TestManpages(unittest.TestCase): @staticmethod def _LoadScript(name): - return utils.LoadModule("scripts/%s" % name) + return build.LoadModule("scripts/%s" % name) def test(self): for script in _autoconf.GNT_SCRIPTS: