summaryrefslogtreecommitdiffstats
path: root/testout.py
blob: f8032be68affb8fca048293d73db0461d9a2456f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
import sys
import pyrmlint

def fobj2str(fobj):
    return b'//'.join([
        fobj.dupflag.encode('ASCII'),
        fobj.md5sum.encode('ASCII'),
        fobj.path.replace(b"'", b"'\"'\"'"),
        str(fobj.size).encode('ASCII'),
        str(fobj.devid).encode('ASCII'),
        str(fobj.inode).encode('ASCII'),
        b''
    ])

r = pyrmlint.Logreader()
with open(sys.argv[1], 'rb') as f:
    r.parse(f)
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()
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()