4 from .resource_list
import get_python_dependency, is_package
6 PKG =
r'([^\.;]+)(\.?[^;]*)?'
7 PYTHON1 =
'^import ' + PKG
8 PYTHON2 =
'from ' + PKG +
' import .*'
9 CPLUS = re.compile(
r'#include\s*[<\\"]([^/]*)/?([^/]*)[>\\"]')
10 CPLUS2 = re.compile(
r'#include\s*[<\\"]([^/]*)/([^/]*)/([^/]*)[>\\"]')
11 ROSCPP = re.compile(
r'#include\s*<ros/ros.h>')
13 EXPRESSIONS = [re.compile(PYTHON1), re.compile(PYTHON2), CPLUS, CPLUS2]
17 return s[0:2] ==
'#!' and 'python' in s
33 parts = os.path.split(rel_fn)
34 if parts
and parts[0] ==
'test':
45 self.
lines = map(unicode.strip, unicode(contents).split(
'\n'))
48 self.
lines = list(map(str.strip, contents.split(
'\n')))
53 for pattern
in patterns:
54 matches += pattern.findall(contents)
59 for line
in self.
lines:
60 for pattern
in patterns:
61 m = pattern.search(line)
63 matches.append(m.groups())
71 Given a map of patterns, replace all instances in the source code.
73 The key in the map (needle) is a regular expression string literal.
74 If there are no groups, then the matching string is replaced with the map value.
75 If there are groups, then the literals of the form $0, $1, etc in the map value are replaced with the groups
79 for needle, replacement
in patterns.items():
80 pattern = re.compile(needle)
83 this_replacement = replacement
84 if len(m.groups()) > 0:
85 for i, chunk
in enumerate(m.groups()):
87 this_replacement = this_replacement.replace(key, chunk)
88 before, middle, after = s.partition(m.group(0))
90 print(
'In %s, replacing %s with %s' % (self.
rel_fn, middle, this_replacement))
91 s = before + this_replacement + after
125 return os.access(self.
file_path, os.X_OK)
128 return self.
rel_fn < other.rel_fn
132 return '%s (%s)' % (self.
rel_fn,
', '.join(attribs))