File: find_unique_file.py

package info (click to toggle)
ghostscript 8.62.dfsg.1-3.2lenny5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 55,332 kB
  • ctags: 73,646
  • sloc: ansic: 505,865; sh: 34,002; python: 4,917; cpp: 3,961; asm: 3,565; ada: 1,681; tcl: 1,469; pascal: 1,089; makefile: 885; cs: 879; lisp: 407; xml: 263; perl: 158; awk: 66; yacc: 15
file content (46 lines) | stat: -rwxr-xr-x 1,362 bytes parent folder | download | duplicates (13)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- Mode: python -*-
import sys, os, re
import anydbm
import gsconf
import myoptparse, optparse

def find_unique(filename):
    file=open(filename)
    lines=file.readlines()
    file.close()

    no_checksum=re.compile(".*no baseline checksum")

    testfiles={}
    comparefiledir=gsconf.comparefiledir
    discard_leader=re.compile(".*"+comparefiledir)
    for line in lines:
        line=line.strip('\n')
        if discard_leader.match(line):
            if no_checksum.match(line):
                testfile = discard_leader.sub("",line)
                value=""
                testfiles[testfile]=value

    testfilelist=testfiles.keys()
    testfilelist.sort()
    for testfile in testfilelist:
        print testfile

if __name__ == "__main__":

    optionsParser=optparse.OptionParser()
    optionsParser.add_option('--file','-f',action='store_true',help="file to be parsed - find unique testfiles")
    (options,arguments)=myoptparse.parseCommandLine(optionsParser,revisionSkip=True,testfileSkip=True,listfileSkip=True,deviceSkip=True)

    args=sys.argv[:]
    options.myself=args.pop(0)
    while len(arguments)> 0:
           filename = arguments.pop(0)
           if os.path.exists(filename):
               find_unique(filename)
           else:
               print options.myself,"cannot open",filename

    sys.exit(0)