Esempio n. 1
0
    def delete(self, *args, **kwargs):
        """ Deletes from the file system too.

    If you delete a directory, be careful that you don't use any file object
    that's under that directory. That would cause a lot of errors.
    """
        # This is for moving only. In that we already removed that path.
        db_only = kwargs.pop("db_only", False)
        fspath = self.fspath
        if not db_only and not os.path.exists(fspath):
            try:
                Document.delete(self, *args, **kwargs)
            except:
                pass

            raise NotFoundError("{} not found!".format(fspath))

        if self.is_directory:
            base_dir = os.path.join(File.FILES_FOLDER, self.project.key)
            l = len(base_dir)
            for root, subdirs, filenames in os.walk(fspath, topdown=False):
                for fname in filenames:
                    p = os.path.join(root, fname)
                    p = p[l:]
                    key = File.keygen(self.project, p)
                    File.get(key).delete(db_only=db_only)

                if root != fspath:
                    p = root[
                        l:] + "/"  # os walk does not have the trailing slash
                    key = File.keygen(self.project, p)
                    File.get(key).delete(db_only=db_only)

            if not db_only:
                os.rmdir(fspath)  # suppose to fail if it is not empty.
        else:
            if not db_only:
                os.unlink(fspath)

        return Document.delete(self, *args, **kwargs)
Esempio n. 2
0
  def delete(self, *args, **kwargs):
    """ Deletes from the file system too.

    If you delete a directory, be careful that you don't use any file object
    that's under that directory. That would cause a lot of errors.
    """
    # This is for moving only. In that we already removed that path.
    db_only = kwargs.pop("db_only", False)
    fspath = self.fspath
    if not db_only and not os.path.exists(fspath):
      try:
        Document.delete(self, *args, **kwargs)
      except:
        pass

      raise NotFoundError("{} not found!".format(fspath))

    if self.is_directory:
      base_dir = os.path.join(File.FILES_FOLDER, self.project.key)
      l = len(base_dir)
      for root, subdirs, filenames in os.walk(fspath, topdown=False):
        for fname in filenames:
          p = os.path.join(root, fname)
          p = p[l:]
          key = File.keygen(self.project, p)
          File.get(key).delete(db_only=db_only)

        if root != fspath:
          p = root[l:] + "/" # os walk does not have the trailing slash
          key = File.keygen(self.project, p)
          File.get(key).delete(db_only=db_only)

      if not db_only:
        os.rmdir(fspath) # suppose to fail if it is not empty.
    else:
      if not db_only:
        os.unlink(fspath)

    return Document.delete(self, *args, **kwargs)
Esempio n. 3
0
    def delete(self, *args, **kwargs):
        for comment in Comment.index("parent", self.key):
            comment.delete()

        return Document.delete(self, *args, **kwargs)
Esempio n. 4
0
  def delete(self, *args, **kwargs):
    for comment in Comment.index("parent", self.key):
      comment.delete()

    return Document.delete(self, *args, **kwargs)
Esempio n. 5
0
  def delete(self, *args, **kwargs):
    """Overriden as we need to delete the children"""
    for comment in Comment.index("parent", self.key):
      comment.delete()

    return Document.delete(self, *args, **kwargs)