Revision e948770c

b/autotools/build-bash-completion
28 28
from ganeti import constants
29 29
from ganeti import cli
30 30
from ganeti import utils
31
from ganeti import build
31 32

  
32 33
# _autoconf shouldn't be imported from anywhere except constants.py, but we're
33 34
# making an exception here because this script is only used at build time.
......
606 607
    WriteCompletion(sw, scriptname,
607 608
                    GetFunctionName(scriptname),
608 609
                    commands=GetCommands(filename,
609
                                         utils.LoadModule(filename)))
610
                                         build.LoadModule(filename)))
610 611

  
611 612
  # Burnin script
612
  burnin = utils.LoadModule("tools/burnin")
613
  burnin = build.LoadModule("tools/burnin")
613 614
  WriteCompletion(sw, "%s/burnin" % constants.TOOLSDIR, "_ganeti_burnin",
614 615
                  opts=burnin.OPTIONS, args=burnin.ARGUMENTS)
615 616

  
b/lib/build/__init__.py
17 17
# along with this program; if not, write to the Free Software
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 19
# 02110-1301, USA.
20

  
21

  
22
import imp
23
import os
24

  
25

  
26
def LoadModule(filename):
27
  """Loads an external module by filename.
28

  
29
  Use this function with caution. Python will always write the compiled source
30
  to a file named "${filename}c".
31

  
32
  @type filename: string
33
  @param filename: Path to module
34

  
35
  """
36
  (name, ext) = os.path.splitext(filename)
37

  
38
  fh = open(filename, "U")
39
  try:
40
    return imp.load_module(name, fh, filename, (ext, "U", imp.PY_SOURCE))
41
  finally:
42
    fh.close()
b/lib/utils.py
42 42
import resource
43 43
import logging
44 44
import signal
45
import imp
46 45

  
47 46
from cStringIO import StringIO
48 47

  
......
1995 1994
  return value
1996 1995

  
1997 1996

  
1998
def LoadModule(filename):
1999
  """Loads an external module by filename.
2000

  
2001
  Use this function with caution. Python will always write the compiled source
2002
  to a file named "${filename}c".
2003

  
2004
  @type filename: string
2005
  @param filename: Path to module
2006

  
2007
  """
2008
  (name, ext) = os.path.splitext(filename)
2009

  
2010
  fh = open(filename, "U")
2011
  try:
2012
    return imp.load_module(name, fh, filename, (ext, "U", imp.PY_SOURCE))
2013
  finally:
2014
    fh.close()
2015

  
2016

  
2017 1997
class FileLock(object):
2018 1998
  """Utility class for file locks.
2019 1999

  
b/test/docs_unittest.py
27 27
from ganeti import _autoconf
28 28
from ganeti import utils
29 29
from ganeti import cmdlib
30
from ganeti import build
30 31
from ganeti.rapi import connector
31 32

  
32 33
import testutils
......
126 127

  
127 128
  @staticmethod
128 129
  def _LoadScript(name):
129
    return utils.LoadModule("scripts/%s" % name)
130
    return build.LoadModule("scripts/%s" % name)
130 131

  
131 132
  def test(self):
132 133
    for script in _autoconf.GNT_SCRIPTS:

Also available in: Unified diff