From 212ccc7f476fb17278491b26ae388ed9cc13a7ea Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 17 Jun 2013 22:43:36 +0200 Subject: [PATCH] Added klammerkomma.py --- klammerkomma.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 klammerkomma.py diff --git a/klammerkomma.py b/klammerkomma.py new file mode 100755 index 0000000..ec735ad --- /dev/null +++ b/klammerkomma.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import os +import sys +import tempfile +import re +import shutil + +re_komma = re.compile(r',(\s*[\)\]\}])') + +i = 0 +for fname in sys.argv: + if i == 0: + i = 1 + continue + if not os.path.exists(fname): + sys.stderr.write("Datei %r existiert nicht.\n" % (fname)) + continue + (ofd, ofname) = tempfile.mkstemp() + print "Mangling %r -> %r" % (fname, ofname) + try: + try: + ifile = open(fname) + lines = ifile.read() + nlines = re_komma.sub(r'\1', lines) + os.write(ofd, nlines) + finally: + os.close(ofd) + ifile.close() + print "Moving %r -> %r" % (ofname, fname) + shutil.move(ofname, fname) + finally: + if os.path.exists(ofname): + print "Removing %r ..." % (ofname) + os.remove(ofname) + +# vim: ts=4 et -- 2.39.5