# 02110-1301, USA.
-import imp
import optparse
import os
import sys
return "_" + re.sub(r"[^a-z0-9]+", "_", name.lower())
-def LoadModule(filename):
- """Loads an external module by filename.
-
- """
- (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()
-
-
def GetCommands(filename, module):
"""Returns the commands defined in a module.
WriteCompletion(sw, scriptname,
GetFunctionName(scriptname),
- commands=GetCommands(filename, LoadModule(filename)))
+ commands=GetCommands(filename,
+ utils.LoadModule(filename)))
# Burnin script
- burnin = LoadModule("tools/burnin")
+ burnin = utils.LoadModule("tools/burnin")
WriteCompletion(sw, "%s/burnin" % constants.TOOLSDIR, "_ganeti_burnin",
opts=burnin.OPTIONS, args=burnin.ARGUMENTS)
import resource
import logging
import signal
+import imp
from cStringIO import StringIO
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.