Exemplo n.º 1
0
Arquivo: insert.py Projeto: bfeng/dfs
    def post(self):
        key = self.request.get("key")
        value = self.request.get("value")

        filename = urllib.unquote(key)

        # Clean up current file
        query = DataFile.all().filter("f_key", filename)

        for data_file in query:
            data_file.delete()

        # Create a file
        writable_file_name = files.blobstore.create(mime_type="application/octect-stream")

        with files.open(writable_file_name, "a") as f:
            f.write(value)
        files.finalize(writable_file_name)

        blob_key = files.blobstore.get_blob_key(writable_file_name)

        data_file = DataFile(f_key=filename, f_value=blob_key)
        data_file.put()

        if memcache.get(key="turn") == "on":
            if BlobInfo.get(blob_key).size <= 100000:
                memcache.set(key=filename, value=value, time=3600)

        write_boolean(self, True)
Exemplo n.º 2
0
Arquivo: listing.py Projeto: bfeng/dfs
  def post(self):
    data_files = DataFile.all()

    result = {"type":"array", "value":[]}
    for data_file in data_files:
      result["value"].append(data_file.f_key)

    write_json(self, result)
Exemplo n.º 3
0
Arquivo: remove.py Projeto: bfeng/dfs
  def post(self):
    key = urllib.unquote(self.request.get('key'))

    query = DataFile.all().filter('f_key =', key)
    data_file = query.get()
    if data_file is None:
      write_boolean(self, False)
    else:
      if data_file.f_value:
          data_file.f_value.delete()
      data_file.delete()
      write_boolean(self, True)
Exemplo n.º 4
0
Arquivo: find.py Projeto: bfeng/dfs
  def post(self):
    key = urllib.unquote(self.request.get('key'))

    if memcache.get(key="turn") == 'on':
      data = memcache.get(key)
      if data is not None:
        write_string(self, data)
        return

    query = DataFile.all().filter('f_key =', key)

    data_file = query.get()

    if data_file:
      blob_reader = blobstore.BlobReader(data_file.f_value, buffer_size=1048576)
      for line in blob_reader:
        write_string(self, line)
    else:
      write_boolean(self, False)