Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
cmt2cmake Namespace Reference

Classes

class  Package
 
class  Project
 

Functions

def makeParser
 
def open_cache
 
def close_cache
 
def loadConfig
 
def extName
 
def isPackage
 
def isProject
 
def projectCase
 
def callStringWithIndent
 
def writeToFile
 
def main
 

Variables

 cache None
 
dictionary config {}
 
list ignored_packages config['ignored_packages']
 
list data_packages config['data_packages']
 
list needing_python config['needing_python']
 
list no_pedantic config['no_pedantic']
 
list ignore_env config['ignore_env']
 
string toolchain_template
 

Function Documentation

def cmt2cmake.callStringWithIndent (   cmd,
  arglines 
)
Produce a string for a call of a command with indented arguments.

>>> print callStringWithIndent('example_command', ['arg1', 'arg2', 'arg3'])
example_command(arg1
                arg2
                arg3)
>>> print callStringWithIndent('example_command', ['', 'arg2', 'arg3'])
example_command(arg2
                arg3)

Definition at line 153 of file cmt2cmake.py.

154 def callStringWithIndent(cmd, arglines):
155  '''
156  Produce a string for a call of a command with indented arguments.
157 
158  >>> print callStringWithIndent('example_command', ['arg1', 'arg2', 'arg3'])
159  example_command(arg1
160  arg2
161  arg3)
162  >>> print callStringWithIndent('example_command', ['', 'arg2', 'arg3'])
163  example_command(arg2
164  arg3)
165  '''
166  indent = '\n' + ' ' * (len(cmd) + 1)
167  return cmd + '(' + indent.join(filter(None, arglines)) + ')'
def cmt2cmake.close_cache ( )

Definition at line 88 of file cmt2cmake.py.

88 
89 def close_cache():
90  global cache
91  if cache:
92  cache.close()
93  cache = None
def cmt2cmake.extName (   n)
Mapping between the name of the LCG_Interface name and the Find*.cmake name
(if non-trivial).

Definition at line 126 of file cmt2cmake.py.

127 def extName(n):
128  '''
129  Mapping between the name of the LCG_Interface name and the Find*.cmake name
130  (if non-trivial).
131  '''
132  mapping = {'Reflex': 'ROOT',
133  'Python': 'PythonLibs',
134  'neurobayes_expert': 'NeuroBayesExpert',
135  'mysql': 'MySQL',
136  'oracle': 'Oracle',
137  'sqlite': 'SQLite',
138  'lfc': 'LFC',
139  'fftw': 'FFTW',
140  'uuid': 'UUID',
141  }
142  return mapping.get(n, n)
def cmt2cmake.isPackage (   path)

Definition at line 143 of file cmt2cmake.py.

144 def isPackage(path):
145  return os.path.isfile(os.path.join(path, "cmt", "requirements"))
def cmt2cmake.isProject (   path)

Definition at line 146 of file cmt2cmake.py.

147 def isProject(path):
148  return os.path.isfile(os.path.join(path, "cmt", "project.cmt"))
def cmt2cmake.loadConfig (   config_file)
Merge the content of the JSON file with the configuration dictionary.

Definition at line 111 of file cmt2cmake.py.

112 def loadConfig(config_file):
113  '''
114  Merge the content of the JSON file with the configuration dictionary.
115  '''
116  global config
117  if os.path.exists(config_file):
118  data = json.load(open(config_file))
119  for k in data:
120  if k not in config:
121  config[k] = set()
122  config[k].update(map(str, data[k]))
123  # print config
124 
125 loadConfig(os.path.join(os.path.dirname(__file__), 'cmt2cmake.cfg'))
def cmt2cmake.main (   args = None)

Definition at line 912 of file cmt2cmake.py.

913 def main(args=None):
914  from optparse import OptionParser
915  parser = OptionParser(usage="%prog [options] [path to project or package]",
916  description="Convert CMT-based projects/packages to CMake (Gaudi project)")
917  parser.add_option("-f", "--force", action="store_const",
918  dest='overwrite', const='force',
919  help="overwrite existing files")
920  parser.add_option('--cache-only', action='store_true',
921  help='just update the cache without creating the CMakeLists.txt files.')
922  parser.add_option('-u' ,'--update', action='store_const',
923  dest='overwrite', const='update',
924  help='modify the CMakeLists.txt files if they are older than '
925  'the corresponding requirements.')
926  #parser.add_option('--cache-file', action='store',
927  # help='file to be used for the cache')
928 
929  opts, args = parser.parse_args(args=args)
930 
931  logging.basicConfig(level=logging.INFO)
932 
933  top_dir = os.getcwd()
934  if args:
935  top_dir = args[0]
936  if not os.path.isdir(top_dir):
937  parser.error("%s is not a directory" % top_dir)
938 
939  loadConfig(os.path.join(top_dir, 'cmt2cmake.cfg'))
940 
941  open_cache()
942  if isProject(top_dir):
943  root = Project(top_dir)
944  elif isPackage(top_dir):
945  root = Package(top_dir)
946  if opts.cache_only:
947  return # the cache is updated instantiating the package
948  else:
949  raise ValueError("%s is neither a project nor a package" % top_dir)
950 
951  if opts.cache_only:
952  root.packages # the cache is updated by instantiating the packages
953  root.heptools() # this triggers the caching of the heptools_version
954  # note that we can get here only if root is a project
955  else:
956  root.process(opts.overwrite)
957  close_cache()
def cmt2cmake.makeParser (   patterns = None)

Definition at line 13 of file cmt2cmake.py.

13 
14 def makeParser(patterns=None):
15  from pyparsing import ( Word, QuotedString, Keyword, Literal, SkipTo, StringEnd,
16  ZeroOrMore, Optional, Combine,
17  alphas, alphanums, printables )
18  dblQuotedString = QuotedString(quoteChar='"', escChar='\\', unquoteResults=False)
19  sglQuotedString = QuotedString(quoteChar="'", escChar='\\', unquoteResults=False)
20  value = dblQuotedString | sglQuotedString | Word(printables)
21 
22  tag_name = Word(alphas + "_", alphanums + "_-")
23  tag_expression = Combine(tag_name + ZeroOrMore('&' + tag_name))
24  values = value + ZeroOrMore(tag_expression + value)
25 
26  identifier = Word(alphas + "_", alphanums + "_")
27  variable = Combine(identifier + '=' + value)
28 
29  constituent_option = (Keyword('-no_share')
30  | Keyword('-no_static')
31  | Keyword('-prototypes')
32  | Keyword('-no_prototypes')
33  | Keyword('-check')
34  | Keyword('-target_tag')
35  | Combine('-group=' + value)
36  | Combine('-suffix=' + value)
37  | Combine('-import=' + value)
38  | variable
39  | Keyword('-OS9')
40  | Keyword('-windows'))
41  source = (Word(alphanums + "_*./$()")
42  | Combine('-s=' + value)
43  | Combine('-k=' + value)
44  | Combine('-x=' + value))
45 
46  # statements
47  comment = (Literal("#") + SkipTo(StringEnd())).suppress()
48 
49  package = Keyword('package') + Word(printables)
50  version = Keyword("version") + Word(printables)
51  use = Keyword("use") + identifier + Word(printables) + Optional(identifier) + Optional(Keyword("-no_auto_imports"))
52 
53  constituent = ((Keyword('library') | Keyword('application') | Keyword('document'))
54  + identifier + ZeroOrMore(constituent_option | source))
55  macro = (Keyword('macro') | Keyword('macro_append')) + identifier + values
56  setenv = (Keyword('set') | Keyword('path_append') | Keyword('path_prepend')) + identifier + values
57 
58  apply_pattern = Keyword("apply_pattern") + identifier + ZeroOrMore(variable)
59  if patterns:
60  direct_patterns = reduce(operator.or_, map(Keyword, set(patterns)))
61  # add the implied 'apply_pattern' to the list of tokens
62  direct_patterns.addParseAction(lambda toks: toks.insert(0, 'apply_pattern'))
63  apply_pattern = apply_pattern | (direct_patterns + ZeroOrMore(variable))
64 
65  statement = (package | version | use | constituent | macro | setenv | apply_pattern)
66 
67  return Optional(statement) + Optional(comment) + StringEnd()
68 
def cmt2cmake.open_cache ( )

Definition at line 70 of file cmt2cmake.py.

70 
71 def open_cache():
72  global cache
73  # record of known subdirs with their libraries
74  # {'<subdir>': {'libraries': [...]}}
75  # it contains some info about the projects too, under the keys like repr(('<project>', '<version>'))
76  try:
77  # First we try the environment variable CMT2CMAKECACHE and the directory
78  # containing this file...
79  _shelve_file = os.environ.get('CMT2CMAKECACHE',
80  os.path.join(os.path.dirname(__file__),
81  '.cmt2cmake.cache'))
82  cache = shelve.open(_shelve_file)
83  except:
84  # ... otherwise we use the user home directory
85  _shelve_file = os.path.join(os.path.expanduser('~'), '.cmt2cmake.cache')
86  #logging.info("Using cache file %s", _shelve_file)
87  cache = shelve.open(_shelve_file)
def cmt2cmake.projectCase (   name)

Definition at line 149 of file cmt2cmake.py.

150 def projectCase(name):
151  return {'DAVINCI': 'DaVinci',
152  'LHCB': 'LHCb'}.get(name.upper(), name.capitalize())
def cmt2cmake.writeToFile (   filename,
  data,
  log = None 
)
Write the generated CMakeLists.txt.

Definition at line 168 of file cmt2cmake.py.

169 def writeToFile(filename, data, log=None):
170  '''
171  Write the generated CMakeLists.txt.
172  '''
173  if log and os.path.exists(filename):
174  log.info('overwriting %s', filename)
175  f = open(filename, "w")
176  f.write(data)
177  f.close()

Variable Documentation

cmt2cmake.cache None

Definition at line 69 of file cmt2cmake.py.

dictionary cmt2cmake.config {}

Definition at line 94 of file cmt2cmake.py.

list cmt2cmake.data_packages config['data_packages']

Definition at line 101 of file cmt2cmake.py.

list cmt2cmake.ignore_env config['ignore_env']

Definition at line 109 of file cmt2cmake.py.

list cmt2cmake.ignored_packages config['ignored_packages']

Definition at line 100 of file cmt2cmake.py.

list cmt2cmake.needing_python config['needing_python']

Definition at line 104 of file cmt2cmake.py.

list cmt2cmake.no_pedantic config['no_pedantic']

Definition at line 107 of file cmt2cmake.py.

string cmt2cmake.toolchain_template
Initial value:
1 '''# Special wrapper to load the declared version of the heptools toolchain.
2 set(heptools_version {0})
3 
4 # Remove the reference to this file from the cache.
5 unset(CMAKE_TOOLCHAIN_FILE CACHE)
6 
7 # Find the actual toolchain file.
8 find_file(CMAKE_TOOLCHAIN_FILE
9  NAMES heptools-${{heptools_version}}.cmake
10  HINTS ENV CMTPROJECTPATH
11  PATHS ${{CMAKE_CURRENT_LIST_DIR}}/cmake/toolchain
12  PATH_SUFFIXES toolchain)
13 
14 if(NOT CMAKE_TOOLCHAIN_FILE)
15  message(FATAL_ERROR "Cannot find heptools-${{heptools_version}}.cmake.")
16 endif()
17 
18 # Reset the cache variable to have proper documentation.
19 set(CMAKE_TOOLCHAIN_FILE ${{CMAKE_TOOLCHAIN_FILE}}
20  CACHE FILEPATH "The CMake toolchain file" FORCE)
21 
22 include(${{CMAKE_TOOLCHAIN_FILE}})
23 '''

Definition at line 694 of file cmt2cmake.py.


Generated at Wed Nov 28 2012 12:17:35 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004