1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-26 06:53:14 +00:00

Make sure that regexp are raw strings

This commit is contained in:
Carles Fernandez 2019-01-29 14:52:01 +01:00
parent 2cf690d88e
commit 3d2f10dae7
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
3 changed files with 17 additions and 18 deletions

View File

@ -53,7 +53,7 @@ def split_into_nested_ifdef_sections(code):
header = 'text'
in_section_depth = 0
for i, line in enumerate(code.splitlines()):
m = re.match('^(\s*)#(\s*)(\w+)(.*)$', line)
m = re.match(r'^(\s*)#(\s*)(\w+)(.*)$', line)
line_is = 'normal'
if m:
p0, p1, fcn, stuff = m.groups()
@ -121,11 +121,11 @@ def flatten_section_text(sections):
class impl_class(object):
def __init__(self, kern_name, header, body):
#extract LV_HAVE_*
self.deps = set(res.lower() for res in re.findall('LV_HAVE_(\w+)', header))
self.deps = set(res.lower() for res in re.findall(r'LV_HAVE_(\w+)', header))
#extract function suffix and args
body = flatten_section_text(body)
try:
fcn_matcher = re.compile('^.*(%s\\w*)\\s*\\((.*)$'%kern_name, re.DOTALL | re.MULTILINE)
fcn_matcher = re.compile(r'^.*(%s\w*)\s*\((.*)$'%kern_name, re.DOTALL | re.MULTILINE)
body = body.split('{')[0].rsplit(')', 1)[0] #get the part before the open ){ bracket
m = fcn_matcher.match(body)
impl_name, the_rest = m.groups()
@ -133,7 +133,7 @@ class impl_class(object):
self.args = list()
fcn_args = the_rest.split(',')
for fcn_arg in fcn_args:
arg_matcher = re.compile('^\s*(.*\\W)\s*(\w+)\s*$', re.DOTALL | re.MULTILINE)
arg_matcher = re.compile(r'^\s*(.*\W)\s*(\w+)\s*$', re.DOTALL | re.MULTILINE)
m = arg_matcher.match(fcn_arg)
arg_type, arg_name = m.groups()
self.args.append((arg_type, arg_name))
@ -153,7 +153,7 @@ def extract_lv_haves(code):
haves = list()
for line in code.splitlines():
if not line.strip().startswith('#'): continue
have_set = set(res.lower() for res in re.findall('LV_HAVE_(\w+)', line))
have_set = set(res.lower() for res in re.findall(r'LV_HAVE_(\w+)', line))
if have_set: haves.append(have_set)
return haves

View File

@ -29,7 +29,7 @@ from six.moves import configparser, input
class volk_gnsssdr_modtool_config(object):
def key_val_sub(self, num, stuff, section):
return re.sub('\$' + 'k' + str(num), stuff[num][0], (re.sub('\$' + str(num), stuff[num][1], section[1][num])));
return re.sub(r'\$' + 'k' + str(num), stuff[num][0], (re.sub(r'\$' + str(num), stuff[num][1], section[1][num])));
def verify(self):
for i in self.verification:
@ -95,4 +95,3 @@ class volk_gnsssdr_modtool_config(object):
for i in stuff:
retval[i[0]] = i[1]
return retval

View File

@ -28,13 +28,13 @@ class volk_gnsssdr_modtool(object):
def __init__(self, cfg):
self.volk_gnsssdr = re.compile('volk_gnsssdr');
self.remove_after_underscore = re.compile("_.*");
self.volk_gnsssdr_run_tests = re.compile('^\s*VOLK_RUN_TESTS.*\n', re.MULTILINE);
self.volk_gnsssdr_profile = re.compile('^\s*(VOLK_PROFILE|VOLK_PUPPET_PROFILE).*\n', re.MULTILINE);
self.volk_gnsssdr_run_tests = re.compile(r'^\s*VOLK_RUN_TESTS.*\n', re.MULTILINE);
self.volk_gnsssdr_profile = re.compile(r'^\s*(VOLK_PROFILE|VOLK_PUPPET_PROFILE).*\n', re.MULTILINE);
self.my_dict = cfg;
self.lastline = re.compile('\s*char path\[1024\];.*');
self.badassert = re.compile('^\s*assert\(toked\[0\] == "volk_gnsssdr_.*\n', re.MULTILINE);
self.lastline = re.compile(r'\s*char path\[1024\];.*');
self.badassert = re.compile(r'^\s*assert\(toked\[0\] == "volk_gnsssdr_.*\n', re.MULTILINE);
self.goodassert = ' assert(toked[0] == "volk_gnsssdr");\n'
self.baderase = re.compile('^\s*toked.erase\(toked.begin\(\)\);.*\n', re.MULTILINE);
self.baderase = re.compile(r'^\s*toked.erase\(toked.begin\(\)\);.*\n', re.MULTILINE);
self.gooderase = ' toked.erase(toked.begin());\n toked.erase(toked.begin());\n';
def get_basename(self, base=None):
@ -65,7 +65,7 @@ class volk_gnsssdr_modtool(object):
for line in hdr_files:
subline = re.search(".*\.h.*", os.path.basename(line))
subline = re.search(r".*\.h.*", os.path.basename(line))
if subline:
subsubline = begins.search(subline.group(0));
if subsubline:
@ -81,7 +81,7 @@ class volk_gnsssdr_modtool(object):
for dt in datatypes:
if dt in line:
#subline = re.search("(?<=volk_gnsssdr_)" + dt + ".*(?=\.h)", line);
subline = re.search(begins.pattern[:-2] + dt + ".*(?=\.h)", line);
subline = re.search(begins.pattern[:-2] + dt + r".*(?=\.h)", line);
if subline:
functions.append(subline.group(0));
@ -188,8 +188,8 @@ class volk_gnsssdr_modtool(object):
inpath = os.path.abspath(base);
kernel = re.compile(name)
search_kernels = set([kernel])
profile = re.compile('^\s*VOLK_PROFILE')
puppet = re.compile('^\s*VOLK_PUPPET')
profile = re.compile(r'^\s*VOLK_PROFILE')
puppet = re.compile(r'^\s*VOLK_PUPPET')
src_dest = os.path.join(inpath, 'apps/', top[:-1] + '_profile.cc');
infile = open(src_dest);
otherlines = infile.readlines();
@ -257,8 +257,8 @@ class volk_gnsssdr_modtool(object):
kernel = re.compile(name)
search_kernels = set([kernel])
profile = re.compile('^\s*VOLK_PROFILE')
puppet = re.compile('^\s*VOLK_PUPPET')
profile = re.compile(r'^\s*VOLK_PROFILE')
puppet = re.compile(r'^\s*VOLK_PUPPET')
infile = open(os.path.join(inpath, 'apps/', oldvolk_gnsssdr.pattern + '_profile.cc'));
otherinfile = open(os.path.join(self.my_dict['destination'], 'volk_gnsssdr_' + self.my_dict['name'], 'apps/volk_gnsssdr_' + self.my_dict['name'] + '_profile.cc'));
dest = os.path.join(self.my_dict['destination'], 'volk_gnsssdr_' + self.my_dict['name'], 'apps/volk_gnsssdr_' + self.my_dict['name'] + '_profile.cc');