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))
예제 #3
0
    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:
            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:
            return None

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

        if parser.image is not None:
            svg_file = self.lookup_fzz_file(parser.image, 'svg.schematic')

            if svg_file is None:
                fzp_dir = dirname(fzp_path)
                parts_dir = dirname(fzp_dir)
                svg_path = join(parts_dir, 'svg', basename(fzp_dir),
                                parser.image)

                if exists(svg_path):
                    svg_file = svg_path

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

        self.components[idref] = parser

        return parser