Exemple #1
0
 def get(self, instance, mode, day):
   expires = ((time.time() - day >= 36*3600 and 30*86400) or 900)
   day = mode + time.strftime("%Y%m%d", time.gmtime(day))
   urls = { "data": makeurl("%s/%s/%s/%s" % (self._svc, instance, self._item, day)) }
   data = self._retrieve((instance, self._item, day), urls, expires=expires)
   cherrypy.request.rest_generate_preamble = data["desc"]
   return data["result"]
Exemple #2
0
  def get(self, tile):
    # The cache file. Avoid putting too many files per directory.
    cache = "%s/Z%s/R%s/C%s.jpg" % ((self._cachedir,) + tile)

    # The cache directory for this tile. Create it if needed.
    # Multiple threads may attempt to create it concurrently,
    # so make sure we don't fail if one succeeds over another.
    dirname = cache.rsplit("/", 1)[0]
    if not os.path.isdir(dirname):
      try: os.makedirs(dirname, 0755)
      except:
        if not os.path.isdir(dirname):
          raise

    # If we've already cached the image tile, return it. The
    # data is forever cacheable on disk.
    if os.path.isfile(cache):
      return open(cache).read()

    # Tile not present, fetch and save in cache, then return it.
    # The cache file update has to happen atomically as several
    # threads might attempt it concurrently.
    im = self.api.proxy.fetch(("worldmap", "-".join(tile)), 30,
                              { "data": makeurl("%s/%s-r%s-c%s.jpg" %
                                                ((self._datasvc,) + tile)) },
                              content_type="image/*")
    if im:
      (fd, tmp) = mkstemp(dir=dirname)
      os.write(fd, im)
      os.close(fd)
      os.chmod(tmp, 0666 & ~self._umask)
      os.rename(tmp, cache)

    return im
Exemple #3
0
    def get(self, tile):
        # The cache file. Avoid putting too many files per directory.
        cache = "%s/Z%s/R%s/C%s.jpg" % ((self._cachedir, ) + tile)

        # The cache directory for this tile. Create it if needed.
        # Multiple threads may attempt to create it concurrently,
        # so make sure we don't fail if one succeeds over another.
        dirname = cache.rsplit("/", 1)[0]
        if not os.path.isdir(dirname):
            try:
                os.makedirs(dirname, 0755)
            except:
                if not os.path.isdir(dirname):
                    raise

        # If we've already cached the image tile, return it. The
        # data is forever cacheable on disk.
        if os.path.isfile(cache):
            return open(cache).read()

        # Tile not present, fetch and save in cache, then return it.
        # The cache file update has to happen atomically as several
        # threads might attempt it concurrently.
        im = self.api.proxy.fetch(
            ("worldmap", "-".join(tile)),
            30, {
                "data": makeurl("%s/%s-r%s-c%s.jpg" %
                                ((self._datasvc, ) + tile))
            },
            content_type="image/*")
        if im:
            (fd, tmp) = mkstemp(dir=dirname)
            os.write(fd, im)
            os.close(fd)
            os.chmod(tmp, 0666 & ~self._umask)
            os.rename(tmp, cache)

        return im
Exemple #4
0
 def get(self, instance):
   urls = { "data": makeurl("%s/%s/%s" % (self._datasvc, instance, self._entity)) }
   data = self._retrieve((instance, self._entity), urls)
   cherrypy.request.rest_generate_preamble = { "columns": self._columns }
   return data
Exemple #5
0
 def _graph(self, section, base, **kwargs):
   base = self.app.appconfig.phedex + ("/graphs/%s?" % base)
   return { "url": makeurl(base, conn="Prod/WebSite", **kwargs),
            "urledit": self._urledit, "match": None, "images": None,
            "section": self._prefix + section }