summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2014-01-07 15:03:31 +0100
committerFlorian Bruhin <git@the-compiler.org>2014-01-07 15:03:31 +0100
commit20c117e3dcbf73152727d13dc7da5750db5c91fc (patch)
tree375a9223bc4b4ea42fe5658e5fd9228a1b55bf3d
parent7e04b5e574f85eb006a42b16f0d42e3f3053b08b (diff)
downloadpyrmlint-20c117e3dcbf73152727d13dc7da5750db5c91fc.tar.gz
pyrmlint-20c117e3dcbf73152727d13dc7da5750db5c91fc.zip
Cleanup
-rw-r--r--pyrmlint.py10
-rw-r--r--rmlint2fdupes.py7
-rw-r--r--testout.py17
3 files changed, 19 insertions, 15 deletions
diff --git a/pyrmlint.py b/pyrmlint.py
index 1e9a91e..4cb65a7 100644
--- a/pyrmlint.py
+++ b/pyrmlint.py
@@ -21,6 +21,12 @@ class File:
self.devid = int(elems[4])
self.inode = int(elems[5])
+ def printpath(self):
+ # we want to treat the filename as binary
+ sys.stdout.buffer.write(self.path + b'\n')
+ sys.stdout.flush()
+
+
class Logreader:
data = {}
duplicates = []
@@ -32,6 +38,10 @@ class Logreader:
'NBIN', 'BGID', 'BUID', 'ORIG', 'DUPL']:
self.data[e] = []
+ def parsefile(self, fn):
+ with open(fn, 'rb') as f:
+ self.parse(f)
+
def _parsedupl(self, fobj):
if fobj.dupflag == 'ORIG':
if self._duplist is not None:
diff --git a/rmlint2fdupes.py b/rmlint2fdupes.py
index 03b0425..246f6d9 100644
--- a/rmlint2fdupes.py
+++ b/rmlint2fdupes.py
@@ -2,11 +2,8 @@ import sys
import pyrmlint
r = pyrmlint.Logreader()
-with open(sys.argv[1], 'rb') as f:
- r.parse(f)
+r.parsefile(sys.argv[1])
for pair in r.duplicates:
for fobj in pair:
- # we want to treat the filename as binary
- sys.stdout.buffer.write(fobj.path + b'\n')
- sys.stdout.flush()
+ fobj.printpath()
print()
diff --git a/testout.py b/testout.py
index f8032be..06072ad 100644
--- a/testout.py
+++ b/testout.py
@@ -2,8 +2,8 @@
import sys
import pyrmlint
-def fobj2str(fobj):
- return b'//'.join([
+def printfobj(fobj):
+ out = b'//'.join([
fobj.dupflag.encode('ASCII'),
fobj.md5sum.encode('ASCII'),
fobj.path.replace(b"'", b"'\"'\"'"),
@@ -12,22 +12,19 @@ def fobj2str(fobj):
str(fobj.inode).encode('ASCII'),
b''
])
+ sys.stdout.buffer.write(out + b'\n')
+ sys.stdout.flush()
r = pyrmlint.Logreader()
-with open(sys.argv[1], 'rb') as f:
- r.parse(f)
+r.parsefile(sys.argv[1])
for lst in r.data.values():
for fobj in lst:
if fobj.dupflag not in ['DUPL', 'ORIG']:
- out = fobj2str(fobj)
- sys.stdout.buffer.write(out + b'\n')
- sys.stdout.flush()
+ printfobj(fobj)
for dupl in r.duplicates:
for i, fobj in enumerate(dupl):
if i == 0:
fobj.dupflag = 'ORIG'
else:
fobj.dupflag = 'DUPL'
- out = fobj2str(fobj)
- sys.stdout.buffer.write(out + b'\n')
- sys.stdout.flush()
+ printfobj(fobj)