diff options
author | Swapnil Negi <swapnil.negi09@gmail.com> | 2018-04-10 19:58:09 +0530 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-04-28 17:08:33 +0200 |
commit | 82d0a6bc2d326dfe002cecd2e6c7341cb4a1d021 (patch) | |
tree | 0e6881276fac6453c37aa2f148d3809974b025f5 | |
parent | 9b3e719af6de6d695b3acddc38590f7daee7a2eb (diff) |
gr-newmod: Pylint fixes in python scripts
-rw-r--r-- | gr-utils/python/modtool/gr-newmod/python/build_utils.py | 153 | ||||
-rw-r--r-- | gr-utils/python/modtool/gr-newmod/python/build_utils_codes.py | 28 |
2 files changed, 90 insertions, 91 deletions
diff --git a/gr-utils/python/modtool/gr-newmod/python/build_utils.py b/gr-utils/python/modtool/gr-newmod/python/build_utils.py index a907101a75..01fcf3bc88 100644 --- a/gr-utils/python/modtool/gr-newmod/python/build_utils.py +++ b/gr-utils/python/modtool/gr-newmod/python/build_utils.py @@ -23,7 +23,9 @@ """Misc utilities used at build time """ -import re, os, os.path +import re +import os +import os.path from build_utils_codes import * @@ -54,96 +56,96 @@ except KeyError, e: name_dict = {} -def log_output_name (name): - (base, ext) = os.path.splitext (name) +def log_output_name(name): + (base, ext) = os.path.splitext(name) ext = ext[1:] # drop the leading '.' - entry = name_dict.setdefault (ext, []) - entry.append (name) + entry = name_dict.setdefault(ext, []) + entry.append(name) -def open_and_log_name (name, dir): +def open_and_log_name(name, dir): global do_sources if do_sources: - f = open (name, dir) + f = open(name, dir) else: f = None - log_output_name (name) + log_output_name(name) return f -def expand_template (d, template_filename, extra = ""): +def expand_template(d, template_filename, extra=""): '''Given a dictionary D and a TEMPLATE_FILENAME, expand template into output file ''' global do_sources - output_extension = extract_extension (template_filename) - template = open_src (template_filename, 'r') + output_extension = extract_extension(template_filename) + template = open_src(template_filename, 'r') output_name = d['NAME'] + extra + '.' + output_extension - log_output_name (output_name) + log_output_name(output_name) if do_sources: - output = open (output_name, 'w') - do_substitution (d, template, output) - output.close () - template.close () + output = open(output_name, 'w') + do_substitution(d, template, output) + output.close() + template.close() -def output_glue (dirname): - output_makefile_fragment () - output_ifile_include (dirname) +def output_glue(dirname): + output_makefile_fragment() + output_ifile_include(dirname) -def output_makefile_fragment (): +def output_makefile_fragment(): global do_makefile if not do_makefile: return # overwrite the source, which must be writable; this should have been # checked for beforehand in the top-level Makefile.gen.gen . - f = open (os.path.join (os.environ.get('gendir', os.environ.get('srcdir', '.')), 'Makefile.gen'), 'w') - f.write ('#\n# This file is machine generated. All edits will be overwritten\n#\n') - output_subfrag (f, 'h') - output_subfrag (f, 'i') - output_subfrag (f, 'cc') - f.close () - -def output_ifile_include (dirname): + f = open(os.path.join(os.environ.get('gendir', os.environ.get('srcdir', '.')), 'Makefile.gen'), 'w') + f.write('#\n# This file is machine generated. All edits will be overwritten\n#\n') + output_subfrag(f, 'h') + output_subfrag(f, 'i') + output_subfrag(f, 'cc') + f.close() + +def output_ifile_include(dirname): global do_sources if do_sources: - f = open ('%s_generated.i' % (dirname,), 'w') - f.write ('//\n// This file is machine generated. All edits will be overwritten\n//\n') - files = name_dict.setdefault ('i', []) - files.sort () - f.write ('%{\n') + f = open('%s_generated.i' % (dirname,), 'w') + f.write('//\n// This file is machine generated. All edits will be overwritten\n//\n') + files = name_dict.setdefault('i', []) + files.sort() + f.write('%{\n') for file in files: - f.write ('#include <%s>\n' % (file[0:-1] + 'h',)) - f.write ('%}\n\n') + f.write('#include <%s>\n' % (file[0:-1] + 'h',)) + f.write('%}\n\n') for file in files: - f.write ('%%include <%s>\n' % (file,)) + f.write('%%include <%s>\n' % (file,)) -def output_subfrag (f, ext): - files = name_dict.setdefault (ext, []) - files.sort () - f.write ("GENERATED_%s =" % (ext.upper ())) +def output_subfrag(f, ext): + files = name_dict.setdefault(ext, []) + files.sort() + f.write("GENERATED_%s =" % (ext.upper())) for file in files: - f.write (" \\\n\t%s" % (file,)) - f.write ("\n\n") + f.write(" \\\n\t%s" % (file,)) + f.write("\n\n") -def extract_extension (template_name): +def extract_extension(template_name): # template name is something like: GrFIRfilterXXX.h.t # we return everything between the penultimate . and .t - mo = re.search (r'\.([a-z]+)\.t$', template_name) + mo = re.search(r'\.([a-z]+)\.t$', template_name) if not mo: raise ValueError, "Incorrectly formed template_name '%s'" % (template_name,) - return mo.group (1) + return mo.group(1) -def open_src (name, mode): +def open_src(name, mode): global srcdir - return open (os.path.join (srcdir, name), mode) + return open(os.path.join(srcdir, name), mode) -def do_substitution (d, in_file, out_file): - def repl (match_obj): - key = match_obj.group (1) +def do_substitution(d, in_file, out_file): + def repl(match_obj): + key = match_obj.group(1) # print key return d[key] - inp = in_file.read () - out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, inp) - out_file.write (out) + inp = in_file.read() + out = re.sub(r"@([a-zA-Z0-9_]+)@", repl, inp) + out_file.write(out) @@ -170,46 +172,45 @@ copyright = '''/* -*- c++ -*- */ */ ''' -def is_complex (code3): - if i_code (code3) == 'c' or o_code (code3) == 'c': +def is_complex(code3): + if i_code(code3) == 'c' or o_code(code3) == 'c': return '1' - else: - return '0' + return '0' -def standard_dict (name, code3, package='gr'): +def standard_dict(name, code3, package='gr'): d = {} d['NAME'] = name d['NAME_IMPL'] = name+'_impl' d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) d['GUARD_NAME_IMPL'] = 'INCLUDED_%s_%s_IMPL_H' % (package.upper(), name.upper()) - d['BASE_NAME'] = re.sub ('^' + package + '_', '', name) + d['BASE_NAME'] = re.sub('^' + package + '_', '', name) d['SPTR_NAME'] = '%s_sptr' % name d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' d['COPYRIGHT'] = copyright - d['TYPE'] = i_type (code3) - d['I_TYPE'] = i_type (code3) - d['O_TYPE'] = o_type (code3) - d['TAP_TYPE'] = tap_type (code3) - d['IS_COMPLEX'] = is_complex (code3) + d['TYPE'] = i_type(code3) + d['I_TYPE'] = i_type(code3) + d['O_TYPE'] = o_type(code3) + d['TAP_TYPE'] = tap_type(code3) + d['IS_COMPLEX'] = is_complex(code3) return d -def standard_dict2 (name, code3, package): +def standard_dict2(name, code3, package): d = {} d['NAME'] = name d['BASE_NAME'] = name d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' d['COPYRIGHT'] = copyright - d['TYPE'] = i_type (code3) - d['I_TYPE'] = i_type (code3) - d['O_TYPE'] = o_type (code3) - d['TAP_TYPE'] = tap_type (code3) - d['IS_COMPLEX'] = is_complex (code3) + d['TYPE'] = i_type(code3) + d['I_TYPE'] = i_type(code3) + d['O_TYPE'] = o_type(code3) + d['TAP_TYPE'] = tap_type(code3) + d['IS_COMPLEX'] = is_complex(code3) return d -def standard_impl_dict2 (name, code3, package): +def standard_impl_dict2(name, code3, package): d = {} d['NAME'] = name d['IMPL_NAME'] = name @@ -219,9 +220,9 @@ def standard_impl_dict2 (name, code3, package): d['COPYRIGHT'] = copyright d['FIR_TYPE'] = "fir_filter_" + code3 d['CFIR_TYPE'] = "fir_filter_" + code3[0:2] + 'c' - d['TYPE'] = i_type (code3) - d['I_TYPE'] = i_type (code3) - d['O_TYPE'] = o_type (code3) - d['TAP_TYPE'] = tap_type (code3) - d['IS_COMPLEX'] = is_complex (code3) + d['TYPE'] = i_type(code3) + d['I_TYPE'] = i_type(code3) + d['O_TYPE'] = o_type(code3) + d['TAP_TYPE'] = tap_type(code3) + d['IS_COMPLEX'] = is_complex(code3) return d diff --git a/gr-utils/python/modtool/gr-newmod/python/build_utils_codes.py b/gr-utils/python/modtool/gr-newmod/python/build_utils_codes.py index 88bff95685..2e4f2aa653 100644 --- a/gr-utils/python/modtool/gr-newmod/python/build_utils_codes.py +++ b/gr-utils/python/modtool/gr-newmod/python/build_utils_codes.py @@ -20,29 +20,27 @@ # Boston, MA 02110-1301, USA. # -def i_code (code3): +def i_code(code3): return code3[0] -def o_code (code3): - if len (code3) >= 2: +def o_code(code3): + if len(code3) >= 2: return code3[1] - else: - return code3[0] + return code3[0] -def tap_code (code3): - if len (code3) >= 3: +def tap_code(code3): + if len(code3) >= 3: return code3[2] - else: - return code3[0] + return code3[0] -def i_type (code3): - return char_to_type[i_code (code3)] +def i_type(code3): + return char_to_type[i_code(code3)] -def o_type (code3): - return char_to_type[o_code (code3)] +def o_type(code3): + return char_to_type[o_code(code3)] -def tap_type (code3): - return char_to_type[tap_code (code3)] +def tap_type(code3): + return char_to_type[tap_code(code3)] char_to_type = {} |