This file is indexed.

/usr/share/fritzing/parts/scripts/schem2csv.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
110
111
112
113
114
115
116
117
118
# usage:
#    schem2csv.py -d <directory> 
#    
#    <directory> is a folder containing schematic .svg files.  
#    save a csv file to <csv file path> 

import getopt, sys, os, re, csv, xml.dom.minidom, xml.dom
    
def usage():
    print """
usage:
    schem2csv.py -d <directory> -c <csv file path>
    
    <directory> is a folder containing .svg files.  
    save a csv file to <csv file path> 
    """
        
       
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hd:c:", ["help", "directory", "csv"])
    except getopt.GetoptError, err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    outputDir = None
    csvPath = None
    
    for o, a in opts:
        #print o
        #print a
        if o in ("-d", "--directory"):
            outputDir = a
        elif o in ("-c", "--csv"):
            csvPath = a
        elif o in ("-h", "--help"):
            usage()
            sys.exit(2)
        else:
            assert False, "unhandled option"
    
    if not outputDir:
        usage()
        sys.exit(2)
        
    if not csvPath:
        usage()
        sys.exit(2)
        
    writer = None
    file = None
    try:
        file = open(csvPath, 'wb')
        writer = csv.writer(file, delimiter=',')
        writer.writerow(["current svg","location","disp","use svg"] )
        writer.writerow(["","","rectangular\nillustrated\nsparkfun","path of sparkfun svg to use"] )
        writer.writerow(["","","",""] )
    except:
        print "unable to save to", csvPath
        sys.exit(2)
            
    names = []
    for filename in os.listdir(outputDir): 
        if (filename.endswith(".svg")):  
            svgFilename = os.path.join(outputDir, filename)
            try:
                dom = xml.dom.minidom.parse(svgFilename)
            except xml.parsers.expat.ExpatError, err:
                print str(err), svgFilename
                continue
            
            svg = dom.documentElement
            viewBox = svg.getAttribute("viewBox").split(" ")
            area = sys.float_info.max
            if len(viewBox) != 4:
                print "no viewBox in", svgFilename
            else:   
                try:
                    viewBoxWidth = float(viewBox[2]) - float(viewBox[0])
                    viewBoxHeight = float(viewBox[3]) - float(viewBox[1])
                    area = viewBoxWidth * viewBoxHeight * 0.75
                    if (area <= 0):
                        print "bad viewBox (1) in", svgFilename
                except:
                    print "bad viewBox (2) in", svgFilename
               
            disp = "illustrated"
            rects = svg.getElementsByTagName("rect")
            for rect in rects:
                try:
                    width = float(rect.getAttribute("width"))
                    height = float(rect.getAttribute("height"))
                    if width * height > area:
                        disp = "rectangular"
                        break
                except:
                    print "bad rect in", svgFilename
                
            location = "core"
            if "contrib" in svgFilename:
                location = "contrib"
            
            writer.writerow([filename, location, disp, ""])
    
    if file:
        file.close()
        
            
def getText(nodelist):
    rc = []
    for node in nodelist:
        if node.nodeType == node.TEXT_NODE:
            rc.append(node.data)
    return ''.join(rc) 
    
if __name__ == "__main__":
    main()