All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cppUtils.SourceCentral Class Reference

Public Member Functions

def __init__
 
def addIncPath
 
def addIncPathEnv
 
def addIncPaths
 
def addIncPathEnvs
 
def find
 
def findLibrary
 
def findHeader
 
def loadLibrary
 
def loadHeader
 
def loadHeaderFromUPS
 
def load
 
def isLibrary
 
def expandLibraryName
 
def __init__
 
def addIncPath
 
def addIncPathEnv
 
def addIncPaths
 
def addIncPathEnvs
 
def find
 
def findLibrary
 
def findHeader
 
def loadLibrary
 
def loadHeader
 
def loadHeaderFromUPS
 
def load
 
def isLibrary
 
def expandLibraryName
 

Static Public Member Functions

def packageNameFromHeaderPath
 
def packageVarNameFromHeaderPath
 
def LibraryPaths
 
def packageNameFromHeaderPath
 
def packageVarNameFromHeaderPath
 
def LibraryPaths
 

Public Attributes

 headers
 
 libraries
 
 includePaths
 

Static Public Attributes

dictionary AllPlatformInfo
 
list PlatformInfo = AllPlatformInfo[os.uname()[0]]
 

Detailed Description

A class keeping track of the sources and where to look for them.

Definition at line 28 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

Constructor & Destructor Documentation

def cppUtils.SourceCentral.__init__ (   self,
  includePaths 
)
def cppUtils.SourceCentral.__init__ (   self,
  includePaths 
)

Definition at line 45 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

45 
46  def __init__(self, *includePaths):
47  self.headers = {}
48  self.libraries = {}
49  self.includePaths = []
50  self.addIncPaths(*includePaths)
# for

Member Function Documentation

def cppUtils.SourceCentral.addIncPath (   self,
  path,
  force = False 
)

Definition at line 53 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

53 
54  def addIncPath(self, path, force=False):
55  expPath = os.path.expandvars(path)
56  if not os.path.isdir(expPath):
57  print >>sys.stderr, "Warning: include path '%s'" % path,
58  if path != expPath: print >>sys.stderr, " ( => '%s')" % expPath
59  print >>sys.stderr, " does not exist."
60  if force or expPath not in self.includePaths:
self.includePaths.append(expPath)
def cppUtils.SourceCentral.addIncPath (   self,
  path,
  force = False 
)

Definition at line 54 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

54 
55  def addIncPath(self, path, force=False):
56  expPath = os.path.expandvars(path)
57  if not os.path.isdir(expPath):
58  print(
59  "Warning: include path '%s'" % path,
60  (" ( => '%s')" % expPath if path != expPath else ""),
61  " does not exist.",
62  sep='',
63  file=sys.stderr
64  )
65  if force or expPath not in self.includePaths:
self.includePaths.append(expPath)
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def cppUtils.SourceCentral.addIncPathEnv (   self,
  varName,
  force = False 
)

Definition at line 63 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

63 
64  def addIncPathEnv(self, varName, force = False):
65  self.addIncPath(os.environ[varName], force=force)
def cppUtils.SourceCentral.addIncPathEnv (   self,
  varName,
  force = False 
)

Definition at line 68 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

68 
69  def addIncPathEnv(self, varName, force = False):
70  self.addIncPath(os.environ[varName], force=force)
def cppUtils.SourceCentral.addIncPathEnvs (   self,
  varNames 
)

Definition at line 69 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

69 
70  def addIncPathEnvs(self, *varNames):
71  self.addIncPaths(*map((lambda varName: os.environ[varName]), varNames))
def cppUtils.SourceCentral.addIncPathEnvs (   self,
  varNames 
)

Definition at line 74 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

74 
75  def addIncPathEnvs(self, *varNames):
76  self.addIncPaths(*map((lambda varName: os.environ[varName]), varNames))
def cppUtils.SourceCentral.addIncPaths (   self,
  paths 
)

Definition at line 66 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

66 
67  def addIncPaths(self, *paths):
68  for path in paths: self.addIncPath(path)
def cppUtils.SourceCentral.addIncPaths (   self,
  paths 
)

Definition at line 71 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

71 
72  def addIncPaths(self, *paths):
73  for path in paths: self.addIncPath(path)
def cppUtils.SourceCentral.expandLibraryName (   self,
  name 
)

Definition at line 144 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

145  def expandLibraryName(self, name):
146  if not name.startswith('lib'): name = 'lib' + name
147  LibSuffix = self.PlatformInfo['LibSuffix']
148  if not name.endswith(LibSuffix): name += LibSuffix
return name
def cppUtils.SourceCentral.expandLibraryName (   self,
  name 
)

Definition at line 149 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

150  def expandLibraryName(self, name):
151  if not name.startswith('lib'): name = 'lib' + name
152  LibSuffix = self.PlatformInfo['LibSuffix']
153  if not name.endswith(LibSuffix): name += LibSuffix
return name
def cppUtils.SourceCentral.find (   self,
  relPath,
  extraPaths = [] 
)

Definition at line 72 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

72 
73  def find(self, relPath, extraPaths = []):
return self.findLibrary(relPath, extraPaths=extraPaths) if self.isLibrary(relPath) else self.findHeader(relPath, extraPaths=extraPaths)
def cppUtils.SourceCentral.find (   self,
  relPath,
  extraPaths = [] 
)

Definition at line 77 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

77 
78  def find(self, relPath, extraPaths = []):
return self.findLibrary(relPath, extraPaths=extraPaths) if self.isLibrary(relPath) else self.findHeader(relPath, extraPaths=extraPaths)
def cppUtils.SourceCentral.findHeader (   self,
  relPath,
  extraPaths = [] 
)

Definition at line 86 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

86 
87  def findHeader(self, relPath, extraPaths = []):
88  for path in reversed(self.includePaths + list(map(os.path.expandvars, extraPaths))):
89  candidate = os.path.join(path, relPath)
90  if os.path.exists(candidate): return candidate
else: return None
list
Definition: file_to_url.sh:28
def cppUtils.SourceCentral.findHeader (   self,
  relPath,
  extraPaths = [] 
)

Definition at line 91 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

91 
92  def findHeader(self, relPath, extraPaths = []):
93  for path in reversed(self.includePaths + list(map(os.path.expandvars, extraPaths))):
94  candidate = os.path.join(path, relPath)
95  if os.path.exists(candidate): return candidate
else: return None
list
Definition: file_to_url.sh:28
def cppUtils.SourceCentral.findLibrary (   self,
  libName,
  extraPaths = [] 
)

Definition at line 76 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

76 
77  def findLibrary(self, libName, extraPaths = []):
78  expLibName = SourceCentral.expandLibraryName(libName)
79  for path in reversed(
80  SourceCentral.LibraryPaths() + map(os.path.expandvars, extraPaths)
81  ):
82  candidate = os.path.join(path, expLibName)
83  if os.path.exists(candidate): return candidate
else: return None
def cppUtils.SourceCentral.findLibrary (   self,
  libName,
  extraPaths = [] 
)

Definition at line 81 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

81 
82  def findLibrary(self, libName, extraPaths = []):
83  expLibName = SourceCentral.expandLibraryName(libName)
84  for path in reversed(
85  SourceCentral.LibraryPaths() + list(map(os.path.expandvars, extraPaths))
86  ):
87  candidate = os.path.join(path, expLibName)
88  if os.path.exists(candidate): return candidate
else: return None
list
Definition: file_to_url.sh:28
def cppUtils.SourceCentral.isLibrary (   self,
  path 
)

Definition at line 141 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

142  def isLibrary(self, path):
143  return os.path.splitext(path)[-1] in [ self.PlatformInfo['LibSuffix'], '' ]
def cppUtils.SourceCentral.isLibrary (   self,
  path 
)

Definition at line 146 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

147  def isLibrary(self, path):
148  return os.path.splitext(path)[-1] in [ self.PlatformInfo['LibSuffix'], '' ]
def cppUtils.SourceCentral.LibraryPaths ( )
static

Definition at line 160 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

161  def LibraryPaths():
162  return os.getenv(SourceCentral.PlatformInfo['LibEnvPath']) \
.split(SourceCentral.PlatformInfo.get('LibEnvPathSep', ':'))
def cppUtils.SourceCentral.LibraryPaths ( )
static

Definition at line 165 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

166  def LibraryPaths():
167  return os.getenv(SourceCentral.PlatformInfo['LibEnvPath']) \
.split(SourceCentral.PlatformInfo.get('LibEnvPathSep', ':'))
def cppUtils.SourceCentral.load (   self,
  relPath,
  extraPaths = [],
  force = False 
)

Definition at line 137 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

138  def load(self, relPath, extraPaths = [], force = False):
return (self.loadLibrary if self.isLibrary(relPath) else self.loadHeader)(relPath, extraPaths=extraPaths, force=force)
def cppUtils.SourceCentral.load (   self,
  relPath,
  extraPaths = [],
  force = False 
)

Definition at line 142 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

143  def load(self, relPath, extraPaths = [], force = False):
return (self.loadLibrary if self.isLibrary(relPath) else self.loadHeaderFromUPS)(relPath, extraPaths=extraPaths, force=force)
def cppUtils.SourceCentral.loadHeader (   self,
  headerRelPath,
  extraPaths = [],
  force = False 
)

Definition at line 100 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

101  def loadHeader(self, headerRelPath, extraPaths = [], force = False):
102  try: return self.headers[headerRelPath]
103  except KeyError: pass
104  headerPath = self.findHeader(headerRelPath, extraPaths=extraPaths)
105  if not headerPath: raise RuntimeError("Can't locate header file '%s'" % headerRelPath)
106  readHeader(headerPath)
107  self.headers[headerRelPath] = headerPath
return headerPath
def cppUtils.SourceCentral.loadHeader (   self,
  headerRelPath,
  extraPaths = [],
  force = False 
)

Definition at line 105 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

106  def loadHeader(self, headerRelPath, extraPaths = [], force = False):
107  try: return self.headers[headerRelPath]
108  except KeyError: pass
109  headerPath = self.findHeader(headerRelPath, extraPaths=extraPaths)
110  if not headerPath: raise RuntimeError("Can't locate header file '%s'" % headerRelPath)
111  readHeader(headerPath)
112  self.headers[headerRelPath] = headerPath
return headerPath
def cppUtils.SourceCentral.loadHeaderFromUPS (   self,
  headerRelPath,
  extraPaths = [],
  force = False 
)
Loads a C++ header from a UPS product.

Assumptions:
* the specified relative path of the header is under the include directory
  of its UPS product
* the include directory path is set in a environment variable named with
  the standard UPS pattern (`PRODUCTNAME_INC`)
* the header relative path starts with a directory that reflects the name
  of the UPS product, `productname/relative/package/path/header.h`

For example, for a `headerRelPath` of `larcorealg/Geometry/GeometryCore.h`,
the full path must be represented by
`${LARCOREALG_INC}/larcorealg/Geometry/GeometryCore.h`, with the content
of `LARCOREALG_INC` variable being an absolute path.

Definition at line 111 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

112  def loadHeaderFromUPS(self, headerRelPath, extraPaths = [], force = False):
113  """
114  Loads a C++ header from a UPS product.
115 
116  Assumptions:
117  * the specified relative path of the header is under the include directory
118  of its UPS product
119  * the include directory path is set in a environment variable named with
120  the standard UPS pattern (`PRODUCTNAME_INC`)
121  * the header relative path starts with a directory that reflects the name
122  of the UPS product, `productname/relative/package/path/header.h`
123 
124  For example, for a `headerRelPath` of `larcorealg/Geometry/GeometryCore.h`,
125  the full path must be represented by
126  `${LARCOREALG_INC}/larcorealg/Geometry/GeometryCore.h`, with the content
127  of `LARCOREALG_INC` variable being an absolute path.
128  """
129  # make sure that if there is a INC variable for the package, that one is included
130  return self.loadHeader(
131  headerRelPath,
132  extraPaths
133  =([ '$' + self.packageVarNameFromHeaderPath('INC', headerRelPath) ] + extraPaths),
134  force=force
)
def cppUtils.SourceCentral.loadHeaderFromUPS (   self,
  headerRelPath,
  extraPaths = [],
  force = False 
)
Loads a C++ header from a UPS product.

Assumptions:
* the specified relative path of the header is under the include directory
  of its UPS product
* the include directory path is set in a environment variable named with
  the standard UPS pattern (`PRODUCTNAME_INC`)
* the header relative path starts with a directory that reflects the name
  of the UPS product, `productname/relative/package/path/header.h`

For example, for a `headerRelPath` of `larcorealg/Geometry/GeometryCore.h`,
the full path must be represented by
`${LARCOREALG_INC}/larcorealg/Geometry/GeometryCore.h`, with the content
of `LARCOREALG_INC` variable being an absolute path.

Definition at line 116 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

117  def loadHeaderFromUPS(self, headerRelPath, extraPaths = [], force = False):
118  """
119  Loads a C++ header from a UPS product.
120 
121  Assumptions:
122  * the specified relative path of the header is under the include directory
123  of its UPS product
124  * the include directory path is set in a environment variable named with
125  the standard UPS pattern (`PRODUCTNAME_INC`)
126  * the header relative path starts with a directory that reflects the name
127  of the UPS product, `productname/relative/package/path/header.h`
128 
129  For example, for a `headerRelPath` of `larcorealg/Geometry/GeometryCore.h`,
130  the full path must be represented by
131  `${LARCOREALG_INC}/larcorealg/Geometry/GeometryCore.h`, with the content
132  of `LARCOREALG_INC` variable being an absolute path.
133  """
134  # make sure that if there is a INC variable for the package, that one is included
135  return self.loadHeader(
136  headerRelPath,
137  extraPaths
138  =([ '$' + self.packageVarNameFromHeaderPath('INC', headerRelPath) ] + extraPaths),
139  force=force
)
def cppUtils.SourceCentral.loadLibrary (   self,
  relPath,
  extraPaths = [],
  force = False 
)

Definition at line 93 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

93 
94  def loadLibrary(self, relPath, extraPaths = [], force = False):
95  expandedName = self.expandLibraryName(relPath)
96  res = ROOT.gSystem.Load(expandedName)
97  if res == 0: self.libraries[relPath] = expandedName
return res
def cppUtils.SourceCentral.loadLibrary (   self,
  relPath,
  extraPaths = [],
  force = False 
)

Definition at line 98 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

98 
99  def loadLibrary(self, relPath, extraPaths = [], force = False):
100  expandedName = self.expandLibraryName(relPath)
101  res = ROOT.gSystem.Load(expandedName)
102  if res == 0: self.libraries[relPath] = expandedName
return res
def cppUtils.SourceCentral.packageNameFromHeaderPath (   headerPath)
static

Definition at line 152 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

153  def packageNameFromHeaderPath(headerPath):
154  return os.path.split(os.path.dirname(headerPath))[0]
def cppUtils.SourceCentral.packageNameFromHeaderPath (   headerPath)
static

Definition at line 157 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

158  def packageNameFromHeaderPath(headerPath):
159  return os.path.split(os.path.dirname(headerPath))[0]
def cppUtils.SourceCentral.packageVarNameFromHeaderPath (   varSuffix,
  headerPath 
)
static

Definition at line 156 of file sbndcode/sbndcode/gallery/python/cppUtils.py.

157  def packageVarNameFromHeaderPath(varSuffix, headerPath):
158  return SourceCentral.packageNameFromHeaderPath(headerPath).upper() + '_' + varSuffix
def cppUtils.SourceCentral.packageVarNameFromHeaderPath (   varSuffix,
  headerPath 
)
static

Definition at line 161 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

162  def packageVarNameFromHeaderPath(varSuffix, headerPath):
163  return SourceCentral.packageNameFromHeaderPath(headerPath).upper() + '_' + varSuffix

Member Data Documentation

dictionary cppUtils.SourceCentral.AllPlatformInfo
static
Initial value:
1 = {
2  'Linux': {
3  'Name': 'Linux',
4  'LibSuffix': '.so',
5  'LibEnvPath': 'LD_LIBRARY_PATH',
6  },
7  'Darwin': {
8  'Name': 'Darwin',
9  'LibSuffix': '.dylib',
10  'LibEnvPath': 'DYLD_LIBRARY_PATH', # might be not honoured
11  },
12  }

Definition at line 32 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

cppUtils.SourceCentral.headers

Definition at line 47 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

cppUtils.SourceCentral.includePaths

Definition at line 49 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

cppUtils.SourceCentral.libraries

Definition at line 48 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.

list cppUtils.SourceCentral.PlatformInfo = AllPlatformInfo[os.uname()[0]]
static

Definition at line 44 of file icarusalg/icarusalg/gallery/helpers/python/cppUtils.py.


The documentation for this class was generated from the following files: