Exemplo n.º 1
0
  def create_index(self, idx, song):
    for field in idx:
      if field not in song:
        return

    fname = reduce(
        lambda a, idxv : a+(idxv, song.get(idxv)),
        idx,
        (),
    )

    # write index
    path = fname[:-1]
    name = fname[-1]
    old = db.fget(path) or []
    if name not in old:
      old.append( name  )
      old.sort()
      db.fset(path, old)

    # write song info
    old = db.fget(fname) or []
    old.append(song)
    db.fset(fname, old)

    return fname
Exemplo n.º 2
0
  def invalidate(self, fhash):
    cachename = "%s/media/%s" % (
        spydaap.cache_dir, fhash
    )
    f = db.IndexLinks(fhash).f
    data = load(f)
    f.close()

    for idx in data:
      idx_data = db.fget(idx)

      for el in idx_data:
        if el['fhash'] == fhash:
          idx_data.remove(el)
          db.fset(idx, idx_data)
          break

    try:
      os.unlink(linkfname)
    except OSError:
      pass

    try:
      os.unlink(cachename)
    except OSError:
      pass
Exemplo n.º 3
0
    def do_GET_db_index(self, req):
        areq = tuple(req.split("/"))

        path = ()
        for x in range((len(areq)+1)/2):
          step = areq[x*2]
          path += (step,)

        if path not in md.INDEXES:
          print 'not in index', path
          return # 404

        plen = len(path)
        indexes = filter(
            lambda idx : len(idx) > plen and idx[:plen] == path,
            md.INDEXES
        )

        return ('data', 
            db.fget(areq),
            list(set(map(lambda x :x[plen], indexes))),
            indexes,
        )