This file is indexed.

/usr/share/fritzing/parts/scripts/props2csv.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
119
120
121
122
123
124
125
126
127
128
# usage:
#    props2csv.py -d <directory> 
#    
#    <directory> is a folder containing .fzp files.  
#    save a csv file of props, tags, etc. to <csv file path> 

import getopt, sys, os, re, csv, xml.dom.minidom, xml.dom
    
def usage():
    print """
usage:
    props2csv.py -d <directory> -c <csv file path>
    
    <directory> is a folder containing .fzp files.  
    save a csv file of props, tags, etc. 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(["fzp","location","title","description","family","props","tags","taxonomy"] )
    except:
        print "unable to save to", csvPath
        sys.exit(2)
            
    names = []
    for filename in os.listdir(outputDir): 
        if (filename.endswith(".fzp")):  
            fzpFilename = os.path.join(outputDir, filename)
            try:
                dom = xml.dom.minidom.parse(fzpFilename)
            except xml.parsers.expat.ExpatError, err:
                print str(err), fzpFilename
                continue
             
            theLine = filename + ","
            
            fzp = dom.documentElement
            
            titleText = ""
            titles = fzp.getElementsByTagName("title")
            for title in titles:
                titleText = getText(title.childNodes)
                break       # assume only one title
                
            taxonomyText = ""
            taxonomies = fzp.getElementsByTagName("taxonomy")
            for taxonomy in taxonomies:
                taxonomyText = getText(taxonomy.childNodes)
                break       # assume only one title
                
            location = "core"
            if "contrib" in fzpFilename:
                location = "contrib"
            elif "resource" in fzpFilename:
                location = "resources"
            
            descriptionText = ""
            descriptions = fzp.getElementsByTagName("description")
            for description in descriptions:
                descriptionText = getText(description.childNodes)
                break       # assume only one description
            
            tagsText = ""
            tags = fzp.getElementsByTagName("tag")
            for tag in tags:
                tagsText += getText(tag.childNodes) + "\n"

            familyText = ""
            propertiesText = ""
            properties = fzp.getElementsByTagName("property")
            for property in properties:
                name = property.getAttribute('name')
                value = getText(property.childNodes)
                propertiesText += name + ":" + value + "\n"
                if name == "family":
                    familyText = value
            
            writer.writerow([filename, location, titleText.encode("utf-8"), descriptionText.encode("utf-8"), familyText.encode("utf-8"), propertiesText.encode("utf-8"), tagsText.encode("utf-8"), taxonomyText.encode("utf-8")])
    
    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()