4 VAR_PATTERN = re.compile(
'\*\*([\w_]+)\)')
5 EQ_PATTERN = re.compile(
'([\w_]+)\s*=([^,]+)')
10 TEMPLATE =
"""#!/usr/bin/env python 12 from distutils.core import setup 13 from catkin_pkg.python_setup import generate_distutils_setup 15 %(var)s = generate_distutils_setup( 16 packages=['%(name)s'],%(exec)s 17 package_dir={'': 'src'} 28 self.
var =
'package_info' 33 original = open(self.
file_path,
'r').read() 36 m = VAR_PATTERN.search(original)
41 key_s =
'generate_distutils_setup' 42 if key_s
not in original:
44 i = original.index(key_s) + len(key_s)
45 p_i = original.index(
'(', i)
46 ep_i = original.index(
')', p_i)
47 body = original[p_i + 1:ep_i]
48 for var_name, value
in EQ_PATTERN.findall(body):
49 if var_name ==
'scripts':
50 self.
execs = eval(value)
61 if len(self.
execs) > 0:
62 execs = EXEC_TEMPLATE % repr(self.
execs)
65 return TEMPLATE % {
'name': self.
pkg_name,
'var': self.
var,
'exec': execs}
def __init__(self, pkg_name, file_path)