Revision d6f5892b lib/utils.py

b/lib/utils.py
42 42
import resource
43 43
import logging
44 44
import signal
45
import imp
45 46

  
46 47
from cStringIO import StringIO
47 48

  
......
1992 1993
  return value
1993 1994

  
1994 1995

  
1996
def LoadModule(filename):
1997
  """Loads an external module by filename.
1998

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

  
2002
  @type filename: string
2003
  @param filename: Path to module
2004

  
2005
  """
2006
  (name, ext) = os.path.splitext(filename)
2007

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

  
2014

  
1995 2015
class FileLock(object):
1996 2016
  """Utility class for file locks.
1997 2017

  

Also available in: Unified diff