From 7bfcae70a2c96edd893c58760b2c0619e6c9d92e Mon Sep 17 00:00:00 2001 From: Scott Tsai Date: Tue, 16 Oct 2012 08:40:03 +0800 Subject: initial import --- python-pycparser.spec | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ remove-relative-sys-path | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 python-pycparser.spec create mode 100755 remove-relative-sys-path diff --git a/python-pycparser.spec b/python-pycparser.spec new file mode 100644 index 0000000..cb29a93 --- /dev/null +++ b/python-pycparser.spec @@ -0,0 +1,50 @@ +Name: python-pycparser +Version: 2.07 +Release: 1%{?dist} +Summary: C parser and AST generator written in Python + +License: BSD +URL: http://code.google.com/p/pycparser/ +Source0: http://pycparser.googlecode.com/files/pycparser-2.07.tar.gz +Source1: remove-relative-sys-path + +BuildArch: noarch + +# for unit tests +BuildRequires: python-ply +BuildRequires: dos2unix + +Requires: python-ply + +%description +pycparser is a complete parser for the C language, written in pure Python. +It is a module designed to be easily integrated into applications that +need to parse C source code. + + +%prep +%setup -q -n pycparser-%{version} + +# examples +find examples -type f -exec dos2unix '{}' ';' +cp %SOURCE1 . +./remove-relative-sys-path examples + +%build +%{__python} setup.py build + +%install +%{__python} setup.py install --skip-build --root $RPM_BUILD_ROOT + +%check +%{__python} tests/all_tests.py + +%files +%doc examples +# For noarch packages: sitelib +%{python_sitelib}/* + + +%changelog +* Tue Jun 18 2012 Scott Tsai 2.07-1 +- upstream 2.07 diff --git a/remove-relative-sys-path b/remove-relative-sys-path new file mode 100755 index 0000000..20fcb06 --- /dev/null +++ b/remove-relative-sys-path @@ -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() -- cgit