def rip (self, location, doc_id):

        note(2, "  converting links in %s...", location)

        linksfile = os.path.join(location, "links", "document.links")
        if os.path.exists(linksfile):
            translation, scaling = thumbnail_translation_and_scaling(location)
            if translation is None or scaling is None:
                note(2, "    couldn't obtain translation or scaling for %s", location)
                return
            
            def scale_rect (left, top, width, height):
                left = trunc((left + translation[0]) * scaling[0] + 0.5)
                top = trunc((top + translation[1]) * scaling[1] + 0.5)
                width = trunc(width * scaling[0] + 0.5)
                height = trunc(height * scaling[1] + 0.5)
                return left, top, width, height

            links = read_links_file(linksfile)
            if not links:
                note(2, "    no links to convert in %s.", location)
                return

            hotspots_file_path = os.path.join(location, "hotspots.txt")
            hotspots_file = open(hotspots_file_path, "wb")

            try:
                for link in links:

                    from_page = link.get("from-page")
                    from_rect = link.get("from-rect")
                    to_uri = link.get("to-uri")
                    to_page = link.get("to-page")
                    if not from_rect or not from_page or (not to_uri and not to_page):
                        # no hotspot to convert
                        continue
                    if not to_uri and to_page:
                        to_uri = '#uplibpage=%d' % (int(to_page) - 1)
                        description = "turn to page %d" % int(to_page)
                    else:
                        description = to_uri
                    from_page = int(from_page) - 1
                    rect = [float(x) for x in from_rect.split(",")]
                    left, top, width, height = scale_rect(*rect)
                    h = Hotspot(doc_id, from_page, left, top, width, height, to_uri, description)
                    h.write(hotspots_file)
                    hotspots_file.flush()
                    
            finally:
                hotspots_file.close()
                

        else:
            note(2, "    no links to convert in %s.", location)
 def links (self):
     if not self.__links:
         links = {}
         linksdir = os.path.join(self.folder(), "links")
         if os.path.isdir(linksdir):
             for name in os.listdir(linksdir):
                 if os.path.splitext(name)[1] == ".links":
                     links.update(read_links_file(os.path.join(linksdir, name), self))
             self.__links = links
         for linkid in self.__removed_links:
             if linkid in self.__links:
                 del self.__links[linkid]
     return self.__links