| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

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 157 of file cmt2cmake.py.

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

def cmt2cmake.close_cache | ( |  | ) |

Definition at line 89 of file cmt2cmake.py.

89
90 def close_cache():
91 global cache
92 if cache:
93 cache.close()
94 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 127 of file cmt2cmake.py.

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

def cmt2cmake.isPackage | ( |  | path | ) |

Definition at line 147 of file cmt2cmake.py.

147
148 def isPackage(path):
149 return os.path.isfile(os.path.join(path, "cmt", "requirements"))

def cmt2cmake.isProject | ( |  | path | ) |

Definition at line 150 of file cmt2cmake.py.

150
151 def isProject(path):
152 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 112 of file cmt2cmake.py.

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

def cmt2cmake.main | ( |  | args = `None` | ) |

Definition at line 928 of file cmt2cmake.py.

928
929 def main(args=None):
930 from optparse import OptionParser
931 parser = OptionParser(usage="%prog [options] [path to project or package]",
932 description="Convert CMT-based projects/packages to CMake (Gaudi project)")
933 parser.add_option("-f", "--force", action="store_const",
934 dest='overwrite', const='force',
935 help="overwrite existing files")
936 parser.add_option('--cache-only', action='store_true',
937 help='just update the cache without creating the CMakeLists.txt files.')
938 parser.add_option('-u' ,'--update', action='store_const',
939 dest='overwrite', const='update',
940 help='modify the CMakeLists.txt files if they are older than '
941 'the corresponding requirements.')
942 #parser.add_option('--cache-file', action='store',
943 # help='file to be used for the cache')
944
945 opts, args = parser.parse_args(args=args)
946
947 logging.basicConfig(level=logging.INFO)
948
949 top_dir = os.getcwd()
950 if args:
951 top_dir = args[0]
952 if not os.path.isdir(top_dir):
953 parser.error("%s is not a directory" % top_dir)
954
955 loadConfig(os.path.join(top_dir, 'cmt2cmake.cfg'))
956
957 open_cache()
958 if isProject(top_dir):
959 root = Project(top_dir)
960 elif isPackage(top_dir):
961 root = Package(top_dir)
962 if opts.cache_only:
963 return # the cache is updated instantiating the package
964 else:
965 raise ValueError("%s is neither a project nor a package" % top_dir)
966
967 if opts.cache_only:
968 root.packages # the cache is updated by instantiating the packages
969 root.heptools() # this triggers the caching of the heptools_version
970 # note that we can get here only if root is a project
971 else:
972 root.process(opts.overwrite)
973 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 alias = Keyword('alias') + identifier + values
58
59 apply_pattern = Keyword("apply_pattern") + identifier + ZeroOrMore(variable)
60 if patterns:
61 direct_patterns = reduce(operator.or_, map(Keyword, set(patterns)))
62 # add the implied 'apply_pattern' to the list of tokens
63 direct_patterns.addParseAction(lambda toks: toks.insert(0, 'apply_pattern'))
64 apply_pattern = apply_pattern | (direct_patterns + ZeroOrMore(variable))
65
66 statement = (package | version | use | constituent | macro | setenv | alias | apply_pattern)
67
68 return Optional(statement) + Optional(comment) + StringEnd()
69

def cmt2cmake.open_cache | ( |  | ) |

Definition at line 71 of file cmt2cmake.py.

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

def cmt2cmake.projectCase | ( |  | name | ) |

Definition at line 153 of file cmt2cmake.py.

153
154 def projectCase(name):
155 return {'DAVINCI': 'DaVinci',
156 'LHCB': 'LHCb'}.get(name.upper(), name.capitalize())

def cmt2cmake.writeToFile | ( |  | filename,
|  |  | data,
|  |  | log = `None`
| ) |  |

    Write the generated CMakeLists.txt.

Definition at line 172 of file cmt2cmake.py.

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

## Variable Documentation

cmt2cmake.cache None

Definition at line 70 of file cmt2cmake.py.

dictionary cmt2cmake.config {}

Definition at line 95 of file cmt2cmake.py.

list cmt2cmake.data_packages config['data_packages']

Definition at line 102 of file cmt2cmake.py.

list cmt2cmake.ignore_env config['ignore_env']

Definition at line 110 of file cmt2cmake.py.

list cmt2cmake.ignored_packages config['ignored_packages']

Definition at line 101 of file cmt2cmake.py.

list cmt2cmake.needing_python config['needing_python']

Definition at line 105 of file cmt2cmake.py.

list cmt2cmake.no_pedantic config['no_pedantic']

Definition at line 108 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 710 of file cmt2cmake.py.