コード例 #1
0
    def import_document(self, file_path: str) -> bool:
        """Import files from filesystem.
        Creates new document in storage and fill it with file's contents.

        :param sender:
        :param filepath: path to file to import
        """
        if not os.path.exists(file_path):
            return False

        self.header.show_spinner(True)
        try:
            with open(file_path, 'r') as _file:
                lines = _file.readlines()
                filename = os.path.basename(file_path)[:file_path.rfind('.')]

                _doc = Document(title=filename, content='\r\n'.join(lines))
                _doc_id = storage.add(_doc)

                self.document_grid.reload_items()
            return True
        except Exception as e:
            print(e)
            return False
        finally:
            self.header.show_spinner(False)
コード例 #2
0
ファイル: editor_view.py プロジェクト: cckuok/Norka
    def create_document(self, title: str = 'Nameless') -> None:
        """Create new document and put it to storage

        :param title: title of the document. Defaults to 'Nameless'
        :type title: str
        :return: None
        """
        self.document = Document(title=title)
        self.document.document_id = storage.add(self.document)
        self.view.grab_focus()
コード例 #3
0
    def create_document(self, title: str = None, folder_path: str = '/') -> None:
        """Create new document and put it to storage

        :param title: title of the document. Defaults to 'Nameless'
        :param folder_path: path to parent folder to store the document id. Defaults to root.
        """
        if not title:
            title = _('Nameless')
        self.document = Document(title=title, folder=folder_path)
        self.view.grab_focus()
        self.emit('document-load', self.document.document_id)
コード例 #4
0
ファイル: storage.py プロジェクト: Vistaus/Norka
    def find(self, search_text: str) -> list:
        query = f"SELECT * FROM documents WHERE lower(title) LIKE ? ORDER BY archived ASC"

        cursor = self.conn.cursor().execute(query,
                                            (f'%{search_text.lower()}%', ))
        rows = cursor.fetchall()

        docs = []
        for row in rows:
            docs.append(Document.new_with_row(row))

        return docs
コード例 #5
0
ファイル: storage.py プロジェクト: TenderOwl/Norka
    def get(self, doc_id: int) -> Optional[Document]:
        """Returns document with given `doc_id`.

        """
        query = "SELECT * FROM documents WHERE id=?"
        cursor = self.conn.cursor().execute(query, (doc_id, ))
        row = cursor.fetchone()

        if not row:
            return None

        return Document.new_with_row(row)
コード例 #6
0
    def all(self, with_archived: bool = False) -> list:
        query = "SELECT * FROM documents"
        if not with_archived:
            query += " WHERE archived=0"

        cursor = self.conn.cursor().execute(query)
        rows = cursor.fetchall()

        docs = []
        for row in rows:
            docs.append(Document.new_with_row(row))

        return docs
コード例 #7
0
ファイル: storage.py プロジェクト: TenderOwl/Norka
    def all(self,
            path: str = '/',
            with_archived: bool = False,
            desc: bool = False) -> List[Document]:
        """Returns all documents in the given `path`.

        If `with_archived` is True then archived documents will be returned too.
        `desc` indicates whether to return documents in descending order or not.
        """
        query = "SELECT * FROM documents WHERE path LIKE ?"
        if not with_archived:
            query += " AND archived=0"

        query += f" ORDER BY ID {'desc' if desc else 'asc'}"

        cursor = self.conn.cursor().execute(query, (f'{path}', ))
        rows = cursor.fetchall()

        docs = []
        for row in rows:
            docs.append(Document.new_with_row(row))

        return docs
コード例 #8
0
ファイル: storage.py プロジェクト: johnfactotum/Norka
    def get(self, doc_id: int) -> Document:
        query = "SELECT * FROM documents WHERE id=?"
        cursor = self.conn.cursor().execute(query, (doc_id, ))
        row = cursor.fetchone()

        return Document.new_with_row(row)
コード例 #9
0
 def _create_document(self, path: str = "/"):
     document = Document('Test Document', "# Simple test content", path)
     return self.storage.add(document)