def ensure_component(self, inst):
        """ If we have not already done so, create the Component the
        given Fritzing instance is an instance of. Return the
        Component, or None if we cannot load it"""

        idref = inst.get('moduleIdRef')

        if idref in self.components:
            return self.components[idref]

        fzp_path = inst.get('path')
        if not fzp_path:
           # print "Path not found", idref
            return None

        if exists(fzp_path):
            fzp_file = fzp_path
        else:
            fzp_file = self.lookup_fzz_file(fzp_path, 'part')

        if not fzp_file:
            fzp_file = lookup_part(fzp_path, self.fritzing_version)
            if fzp_file is not None:
                fzp_path = fzp_file

        if not fzp_file:
          # print "File not found", idref
            return None

        parser = ComponentParser(idref)
        parser.parse_fzp(fzp_file)

        if parser.image is not None:
            #print "Image Path found", idref
            svg_file = self.lookup_fzz_file(parser.image, 'svg.schematic')
			
            if svg_file is None:
               # print "Image not in fzz", idref
                #print fzp_path
                fzp_dir = dirname(fzp_path)
                #print fzp_dir
                pdb_dir = dirname(fzp_dir)
                #print pdb_dir
                fritzingroot_dir = dirname(pdb_dir)
                parts_dir = fritzingroot_dir + '/parts'
                #print parts_dir
                svg_path = join(parts_dir, 'svg', basename(fzp_dir),parser.image)
                #print basename(fzp_dir)			   
                if exists(svg_path):
                    svg_file = svg_path
                    #print svg_file

            if svg_file is not None:
                parser.parse_svg(svg_file)

        self.components[idref] = parser
        return parser
    def test_lookup_missing(self):
        """ Test looking up a part that is missing """

        path = '/some/path/to/fritzing/parts/core/notthere.fzp'
        version = '0.6.4b.12.16.5683'

        found = lookup_part(path, version)

        self.assertEqual(found, None)
Пример #3
0
    def test_lookup_missing(self):
        """ Test looking up a part that is missing """

        path = '/some/path/to/fritzing/parts/core/notthere.fzp'
        version = '0.6.4b.12.16.5683'

        found = lookup_part(path, version)

        self.assertEqual(found, None)
    def test_lookup_present(self):
        """ Test looking up a part that is present """

        path = '/some/path/to/fritzing/parts/core/SMD_Diode_REC_DO.fzp'
        version = '0.6.4b.12.16.5683'

        found = lookup_part(path, version)

        self.assertEqual(basename(found), basename(path))
        self.assertTrue(exists(found))
Пример #5
0
    def test_lookup_present(self):
        """ Test looking up a part that is present """

        path = '/some/path/to/fritzing/parts/core/SMD_Diode_REC_DO.fzp'
        version = '0.6.4b.12.16.5683'

        found = lookup_part(path, version)

        self.assertEqual(basename(found), basename(path))
        self.assertTrue(exists(found))