Commit e948770c authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Move LoadModule function to ganeti.build



It should only be used at build-time.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent f9897b6d
......@@ -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)
......
......@@ -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()
......@@ -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.
......
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment