From fd5c19c2405e378116378e3d4f01a56b2fa11c52 Mon Sep 17 00:00:00 2001 From: basebuilder_pel7x64builder0 Date: Wed, 12 Jun 2019 11:54:25 +0200 Subject: [PATCH] python-pycparser add missing source file Signed-off-by: basebuilder_pel7x64builder0 --- ...cparser-0.91.1-remove-relative-sys-path.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 SOURCES/pycparser-0.91.1-remove-relative-sys-path.py diff --git a/SOURCES/pycparser-0.91.1-remove-relative-sys-path.py b/SOURCES/pycparser-0.91.1-remove-relative-sys-path.py new file mode 100644 index 00000000..20fcb06d --- /dev/null +++ b/SOURCES/pycparser-0.91.1-remove-relative-sys-path.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +''' +pycparser examples all contain the following boiler plate code +for running in tree. This script removes them: + +# This is not required if you've installed pycparser into +# your site-packages/ with setup.py +# +sys.path.extend(['.', '..']) +''' + +import sys +import os + +boiler_plate = "sys.path.extend(['.', '..'])\n" +d = sys.argv[1] +for (root, dirs, files) in os.walk(d): + for i in files: + if not i.endswith('.py'): + continue + fname = os.path.join(root, i) + lines = open(fname).readlines() + try: + start = lines.index(boiler_plate) + end = start + except ValueError: + start = None + end = start + if start is not None: + while lines[start-1].startswith('#'): + start -= 1 + + if start is not None and end is not None: + f = open(fname, 'w') + f.writelines(lines[:start]) + f.writelines(lines[end+1:]) + f.close()