LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Classes | Functions
lsst.sconsUtils.utils Namespace Reference

Classes

class  Log
 A dead-simple logger for all messages. More...
 

Functions

def runExternal
 Safe wrapper for running external programs, reading stdout, and sanitizing error messages. More...
 
def memberOf
 A Python decorator that injects functions into a class. More...
 

Function Documentation

def lsst.sconsUtils.utils.memberOf (   cls,
  name = None 
)

A Python decorator that injects functions into a class.

For example:

1 class test_class(object):
2  pass
3 
4 @memberOf(test_class):
5 def test_method(self):
6  print "test_method!"

...will cause test_method to appear as as if it were defined within test_class.

The function or method will still be added to the module scope as well, replacing any existing module-scope function with that name; this appears to be unavoidable.

Definition at line 85 of file utils.py.

85 
86 def memberOf(cls, name=None):
87  if isinstance(cls, type):
88  classes = (cls,)
89  else:
90  classes = tuple(cls)
91  kw = {"name": name}
92  def nested(member):
93  if kw["name"] is None: kw["name"] = member.__name__
94  for scope in classes:
95  setattr(scope, kw["name"], member)
96  return member
97  return nested
98 
def memberOf
A Python decorator that injects functions into a class.
Definition: utils.py:85
def lsst.sconsUtils.utils.runExternal (   cmd,
  fatal = False,
  msg = None 
)

Safe wrapper for running external programs, reading stdout, and sanitizing error messages.

Note that the entire program output is returned, not just a single line.

Definition at line 52 of file utils.py.

52 
53 def runExternal(cmd, fatal=False, msg=None):
54  if msg is None:
55  try:
56  msg = "Error running %s" % cmd.split()[0]
57  except:
58  msg = "Error running external command"
59  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60  stdout, stderr = process.communicate()
61  if process.returncode != 0:
62  if fatal:
63  raise RuntimeError("%s: %s" % (msg, stderr))
64  else:
65  from . import state # can't import at module scope due to circular dependency
66  state.log.warn("%s: %s" % (msg, stderr))
67  return stdout
def runExternal
Safe wrapper for running external programs, reading stdout, and sanitizing error messages.
Definition: utils.py:52