Exemplo n.º 1
0
    def _add_tag(self, repo, citekey):
        """Add tag to reference.

        Parameters
        ----------
        repo : TODO
        citekey : TODO

        Returns
        -------
        TODO

        """
        # Get all tags
        tags = repo.get_tags()
        # Present in wofi
        wofi = self._wofi_misc
        wofi.lines = min([len(tags), 15])

        new_tag = wofi.select_or_new("New tag...", tags)

        paper = repo.pull_paper(citekey)
        paper.add_tag(new_tag)
        repo.push_paper(paper, overwrite=True, event=False)
        events.PostCommandEvent().send()
        self.menu_reference(repo, citekey, None)
Exemplo n.º 2
0
    def _add_bibfile_manual(self, repo):
        """Add publication to library by manual entry of bibfile.

        Parameters
        ----------
        repo : `obj`:Repository


        """
        tmp_bib_file = os.path.expandvars("${HOME}/.local/tmp/test.bib")
        uis._ui.edit_file(tmp_bib_file, False)

        doc = choose_file("PDF:", "Choose a PDF file", filter="pdf")

        args = PubsArgs()
        args.bibfile = tmp_bib_file
        args.docfile = doc
        # Read bibfile
        if doc is not None:
            with open(tmp_bib_file) as bibtex_file:
                bibtex_str = bibtex_file.read()
                bib_database = bibtexparser.loads(bibtex_str)
                base_key = bib_database.entries[0]["ID"]
                citekey = repo.unique_citekey(base_key, uis._ui)
                args.citekey = citekey

        conf = repo.conf
        add_cmd(conf, args)

        if doc is not None:
            doc = update_pdf_metadata(repo, args.citekey)

        events.PostCommandEvent().send()
Exemplo n.º 3
0
    def _add_bibfile(self, repo):
        """Add publication to library from bibfile.

        Parameters
        ----------
        repo : `obj`:Repository


        """
        bibfile, doc = choose_two_files(
            text="Bibfile:",
            description="Import reference from Bibfile",
        )

        args = PubsArgs()
        args.bibfile = bibfile
        args.docfile = doc
        # Read bibfile
        if doc is not None:
            with open(bibfile) as bibtex_file:
                bibtex_str = bibtex_file.read()
                bib_database = bibtexparser.loads(bibtex_str)
                base_key = bib_database.entries[0]["ID"]
                citekey = repo.unique_citekey(base_key, uis._ui)
                args.citekey = citekey

        conf = repo.conf
        add_cmd(conf, args)

        if doc is not None:
            doc = update_pdf_metadata(repo, args.citekey)

        events.PostCommandEvent().send()
Exemplo n.º 4
0
    def _update_pdf_metadata(self, repo, citekey):
        """Update the PDF's metadata

        Parameters
        ----------
        repo : TODO
        citekey : TODO

        Returns
        -------
        TODO

        """
        paper = repo.pull_paper(citekey)

        docpath = content.system_path(
            repo.databroker.real_docpath(paper.docpath))
        doc = update_pdf_metadata(repo, citekey)
        events.PostCommandEvent().send()
Exemplo n.º 5
0
    def _edit_bib(self, repo, citekey):
        """Edit bibfile corresponding to the citekey.

        Parameters
        ----------
        repo : TODO
        citekey : TODO

        Returns
        -------
        TODO

        """
        conf = repo.conf
        args = PubsArgs()
        args.citekey = citekey
        edit_cmd(conf, args)
        events.PostCommandEvent().send()

        return 1
Exemplo n.º 6
0
    def _add_isbn(self, repo):
        """Add publication to library from ISBN.

        Parameters
        ----------
        repo : `obj`:Repository


        """
        isbn, doc = get_user_input("ISBN:",
                                   description="Import reference by ISBN")

        args = PubsArgs()
        args.isbn = isbn
        args.docfile = doc
        args.citekey = gen_citekey(repo, args)

        conf = repo.conf
        add_cmd(conf, args)

        if doc is not None:
            doc = update_pdf_metadata(repo, args.citekey)

        events.PostCommandEvent().send()
Exemplo n.º 7
0
    def _add_arxiv(self, repo):
        """Add publication to library from ArXiv.

        Parameters
        ----------
        repo : `obj`:Repository


        """
        arxiv, doc = get_user_input("ArXiv:",
                                    description="Import reference by Arxiv")

        args = PubsArgs()
        args.arxiv = arxiv
        args.docfile = doc
        args.citekey = gen_citekey(repo, args)

        conf = repo.conf
        add_cmd(conf, args)

        if doc is not None:
            doc = update_pdf_metadata(repo, args.citekey)

        events.PostCommandEvent().send()