# HG changeset patch # User drewp@bigasterisk.com # Date 1649220792 25200 # Node ID 9251cd695508efea5640508c9a9cec1a0800abbb # Parent 7ddcd92b2191c19530f6a034b0e3bcf00a671fe6 v2.0 support for py3 diff -r 7ddcd92b2191 -r 9251cd695508 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Apr 05 21:53:12 2022 -0700 @@ -0,0 +1,3 @@ +build +dist + diff -r 7ddcd92b2191 -r 9251cd695508 grepedit --- a/grepedit Tue Apr 05 21:47:56 2022 -0700 +++ b/grepedit Tue Apr 05 21:53:12 2022 -0700 @@ -1,4 +1,4 @@ -#!/usr/local/bin/python +#!/usr/bin/python3 ## Copyright 2005 Drew Perttula @@ -50,7 +50,6 @@ """ import tempfile, sys, os, re -from sets import Set def grep_parse(filename): """parse grep output lines in given file into a dict of @@ -61,7 +60,7 @@ continue m = re.match(r"(?P.*?)(?P[-:])(?P\d+)(?P=sep)(?P.*\n)$", line) if m is None: - print "couldn't parse grep result line %r" % line + print("couldn't parse grep result line %r" % line) continue filename, lineno, text = (m.group('filename'), int(m.group('lineno')), m.group('line')) @@ -90,7 +89,7 @@ originals = grep_parse(tf.name) if options.get('sort-text', False): - orig = [(v,k) for k,v in originals.items()] + orig = [(v,k) for k,v in list(originals.items())] orig.sort() f = open(tf.name, "w") for text, (filename,lineno) in orig: @@ -101,7 +100,7 @@ corrections = grep_parse(tf.name) -files = Set([filename for filename,lineno in corrections.keys()]) +files = set([filename for filename,lineno in list(corrections.keys())]) for orig_filename in files: (copy_fd, copy_filename) = tempfile.mkstemp( dir=os.path.dirname(orig_filename), @@ -113,22 +112,22 @@ key = orig_filename,lineno if key in corrections: if line != originals[key]: - print "%s:%s has changed since the grep command ran- not modifying this line" % key - print repr(line) - print repr(originals[key]) + print("%s:%s has changed since the grep command ran- not modifying this line" % key) + print(repr(line)) + print(repr(originals[key])) elif corrections[key] == line: pass else: - print "%s:%s substituting new line" % key + print("%s:%s substituting new line" % key) line = corrections[key] any_changes = True - os.write(copy_fd, line) + os.write(copy_fd, line.encode()) os.close(copy_fd) if any_changes: os.rename(copy_filename, orig_filename) else: - print "no changes made in file %s" % orig_filename + print("no changes made in file %s" % orig_filename) os.unlink(copy_filename) diff -r 7ddcd92b2191 -r 9251cd695508 setup.py --- a/setup.py Tue Apr 05 21:47:56 2022 -0700 +++ b/setup.py Tue Apr 05 21:53:12 2022 -0700 @@ -2,12 +2,12 @@ setup(name="grepedit", - version="1.0", + version="2.0", description="edit the result of a grep and modify the original files", author="Drew Perttula", author_email="drewp@bigasterisk.com", url="http://bigasterisk.com/grepedit", - download_url="http://projects.bigasterisk.com/grepedit-1.0.tar.gz", + download_url="http://projects.bigasterisk.com/grepedit-2.0.tar.gz", scripts=["grepedit"],