/usr/share/fritzing/parts/scripts/checkcopies.py is in fritzing-parts 0.9.3b-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | import getopt, sys, os, re, time
def usage():
print """
usage:
checkcopies.py -d <directory>
<directory> is a folder containing svg files.
looks for files that have the same content but different names
"""
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hd:", ["help", "directory"])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
return
outputDir = None
gotnot = 0
for o, a in opts:
#print o
#print a
if o in ("-d", "--directory"):
outputDir = a
elif o in ("-h", "--help"):
usage()
return
else:
assert False, "unhandled option"
if(not(outputDir)):
print "missing -d {directory} parameter"
usage()
return
fs = []
for f in os.listdir(outputDir):
if f.endswith(".svg"):
fs.append(os.path.splitext(f)[0])
#print "appending", f, os.path.splitext(f)[0]
fs.sort(key=str.lower) # remove the .svg so the sort works better
dirs = []
for f in fs:
dirs.append(f + ".svg")
dirlen = len(dirs)
matches = []
for i in range(dirlen):
if i in matches:
continue
f1 = dirs[i]
path = os.path.join(outputDir, f1)
if not os.path.isfile(path):
continue
if not f1.endswith(".svg"):
continue
# print "testing", f1
txt1 = None
try:
infile = open(path, "r")
txt1 = infile.read()
infile.close()
except:
print "failure", f1
if txt1 == None:
continue
for j in range(i + 1, dirlen):
f2 = dirs[j]
path = os.path.join(outputDir,f2)
if not os.path.isfile(path):
continue
if not f2.endswith(".svg"):
continue
if f1 == f2:
continue
txt2 = None
try:
infile = open(path, "r")
txt2 = infile.read()
infile.close()
except:
print "failure", f2
continue
if txt2 == None:
continue
if txt1 == txt2:
matches.append(j)
print "<map package='{0}' to='{1}' />".format(f1, f2)
if __name__ == "__main__":
main()
|