コード例 #1
0
ファイル: models.py プロジェクト: tmzhuang/projecto
  def __init__(self, key=None, *args, **kwargs):
    if not key:
      raise KeyError("You need to supply a key to the File model!")

    self._content = None
    self._is_directory = key.endswith("/")
    Document.__init__(self, key=key, *args, **kwargs)
コード例 #2
0
ファイル: models.py プロジェクト: jbalthis/projecto
    def __init__(self, key=None, *args, **kwargs):
        if not key:
            raise KeyError("You need to supply a key to the File model!")

        self._content = None
        self._is_directory = key.endswith("/")
        Document.__init__(self, key=key, *args, **kwargs)
コード例 #3
0
ファイル: models.py プロジェクト: jbalthis/projecto
    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)
コード例 #4
0
ファイル: models.py プロジェクト: tmzhuang/projecto
  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)
コード例 #5
0
ファイル: models.py プロジェクト: Siecje/projecto
  def save(self, *args, **kwargs):
    self.date = datetime.now()
    fspath = self.fspath

    if not self._ensure_base_dir_exists(fspath):
      raise NotFoundError("Base dir is not found for {}".format(fspath))

    if not os.path.exists(fspath):
      # We have to do this.. Should PROBABLY move this to new_project
      # TODO: move this to new project
      safe_mkdirs(self.base_dir)

      if self.is_directory:
        safe_mkdirs(fspath)
      else:
        # TODO: we need to worry about race conditions here as well.
        if self._content:
          self._content.save(fspath)

    return Document.save(self, *args, **kwargs)
コード例 #6
0
ファイル: models.py プロジェクト: jbalthis/projecto
    def save(self, *args, **kwargs):
        self.date = datetime.now()
        fspath = self.fspath

        if not self._ensure_base_dir_exists(fspath):
            raise NotFoundError("Base dir is not found for {}".format(fspath))

        if not os.path.exists(fspath):
            # We have to do this.. Should PROBABLY move this to new_project
            # TODO: move this to new project
            safe_mkdirs(self.base_dir)

            if self.is_directory:
                safe_mkdirs(fspath)
            else:
                # TODO: we need to worry about race conditions here as well.
                if self._content:
                    self._content.save(fspath)

        return Document.save(self, *args, **kwargs)
コード例 #7
0
ファイル: models.py プロジェクト: jbalthis/projecto
    def delete(self, *args, **kwargs):
        for comment in Comment.index("parent", self.key):
            comment.delete()

        return Document.delete(self, *args, **kwargs)
コード例 #8
0
ファイル: models.py プロジェクト: Siecje/projecto
  def delete(self, *args, **kwargs):
    for comment in Comment.index("parent", self.key):
      comment.delete()

    return Document.delete(self, *args, **kwargs)
コード例 #9
0
ファイル: models.py プロジェクト: tmzhuang/projecto
  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)