From c4f296346a9a297b581309cdf183bfb59609a139 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Fri, 15 Nov 2013 13:25:54 +0100 Subject: [PATCH] add template text to add editor input --- pubs/commands/add_cmd.py | 22 ++++++++++++++++------ pubs/templates/__init__.py | 1 + pubs/templates/add_bib.txt | 18 ++++++++++++++++++ pubs/templates/str_templates.py | 20 ++++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 pubs/templates/__init__.py create mode 100644 pubs/templates/add_bib.txt create mode 100644 pubs/templates/str_templates.py diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 6b80e83..60afce5 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -4,6 +4,8 @@ from .. import bibstruct from .. import content from .. import repo from .. import paper +from .. import templates + def parser(subparsers): parser = subparsers.add_parser('add', help='add a paper to the repository') @@ -40,13 +42,21 @@ def command(args): if bibfile is None: cont = True bibstr = '' - while cont: try: - bibstr = content.editor_input(config().edit_cmd, bibstr, suffix='.yaml') - bibdata = rp.databroker.verify(bibstr) - bibstruct.verify_bibdata(bibdata) - # REFACTOR Generate citykey - cont = False + bibstr = content.editor_input(config().edit_cmd, + templates.add_bib, + suffix='.bib') + if bibstr == templates.add_bib: + cont = ui.input_yn( + question='Bibfile not edited. Edit again ?', + default='y') + if not cont: + ui.exit(0) + else: + bibdata = rp.databroker.verify(bibstr) + bibstruct.verify_bibdata(bibdata) + # REFACTOR Generate citykey + cont = False except ValueError: cont = ui.input_yn( question='Invalid bibfile. Edit again ?', diff --git a/pubs/templates/__init__.py b/pubs/templates/__init__.py new file mode 100644 index 0000000..8bb9e7b --- /dev/null +++ b/pubs/templates/__init__.py @@ -0,0 +1 @@ +from str_templates import * \ No newline at end of file diff --git a/pubs/templates/add_bib.txt b/pubs/templates/add_bib.txt new file mode 100644 index 0000000..072e065 --- /dev/null +++ b/pubs/templates/add_bib.txt @@ -0,0 +1,18 @@ +# Input the bibliographic data for your article +# Supported formats are bibtex (template below), bibyaml and bibtexml + +@article{ + YourCitekey, + author = "LastName1, FirstName1 and LastName2, FirstName2", + title = "", + journal = "", + number = "7", + pages = "23-31", + volume = "13", + year = "2013", + + doi = "", + issn = "", + keywords = "", + abstract = "" +} \ No newline at end of file diff --git a/pubs/templates/str_templates.py b/pubs/templates/str_templates.py new file mode 100644 index 0000000..624fe5c --- /dev/null +++ b/pubs/templates/str_templates.py @@ -0,0 +1,20 @@ +add_bib = """ +# Input the bibliographic data for your article +# Supported formats are bibtex (template below), bibyaml and bibtexml + +@article{ + YourCitekey, + author = "LastName1, FirstName1 and LastName2, FirstName2", + title = "", + journal = "", + number = "7", + pages = "23-31", + volume = "13", + year = "2013", + + doi = "", + issn = "", + keywords = "", + abstract = "" +} +""" \ No newline at end of file