From e948770cd1cae68cdf44d5e62b5ea6c99cd876c8 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 10 Sep 2009 17:42:27 +0200 Subject: [PATCH] Move LoadModule function to ganeti.build It should only be used at build-time. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- autotools/build-bash-completion | 5 +++-- lib/build/__init__.py | 23 +++++++++++++++++++++++ lib/utils.py | 20 -------------------- test/docs_unittest.py | 3 ++- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion index 7edc9df8a..7368dab32 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 007afb285..0f58b61f9 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 07be8c04f..80e0d9a4d 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 447061f1e..d69066f4a 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: -- GitLab