From 1cd95bdeeccb3160fefc7fcbca42d57e803c1720 Mon Sep 17 00:00:00 2001 From: Dennis Wilson Date: Mon, 29 May 2017 11:43:30 +0200 Subject: [PATCH 1/2] overwrite argument on import --- pubs/commands/import_cmd.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index 03935b4..b83249a 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -20,6 +20,8 @@ def parser(subparsers, conf): help="don't copy document files, just create a link.") parser.add_argument('keys', nargs='*', help="one or several keys to import from the file") + parser.add_argument('-O', '--overwrite', default=False, + help="Overwrite keys already in the database") return parser @@ -78,7 +80,7 @@ def command(conf, args): if isinstance(p, Exception): ui.error(u'Could not load entry for citekey {}.'.format(k)) else: - rp.push_paper(p) + rp.push_paper(p, overwrite=args.overwrite) ui.info(u'{} imported.'.format(color.dye_out(p.citekey, 'citekey'))) docfile = bibstruct.extract_docfile(p.bibdata) if docfile is None: From 3e31c4455e0bdffdbab0f8284894cff290fa5e9c Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 11 Dec 2017 15:49:06 -0500 Subject: [PATCH 2/2] Fixes argument and adds tests for overwrite on import. --- pubs/commands/import_cmd.py | 2 +- tests/test_usecase.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index b83249a..09b721f 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -20,7 +20,7 @@ def parser(subparsers, conf): help="don't copy document files, just create a link.") parser.add_argument('keys', nargs='*', help="one or several keys to import from the file") - parser.add_argument('-O', '--overwrite', default=False, + parser.add_argument('-O', '--overwrite', action='store_true', default=False, help="Overwrite keys already in the database") return parser diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 41b652a..78c3579 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -687,6 +687,26 @@ class TestUsecase(DataCommandTestCase): outs = self.execute_cmds(cmds) self.assertEqual(1 + 1, len(outs[-1].split('\n'))) + def test_import_does_not_overwrite(self): + cmds = ['pubs init', + 'pubs import data/ Page99', + 'pubs import data/', + 'pubs list' + ] + + with self.assertRaises(FakeSystemExit): + self.execute_cmds(cmds) + + def test_import_overwrites(self): + cmds = ['pubs init', + 'pubs import data/ Page99', + 'pubs import --overwrite data/ Page99', + 'pubs list' + ] + + outs = self.execute_cmds(cmds) + self.assertEqual(1 + 1, len(outs[-1].split('\n'))) + def test_update(self): cmds = ['pubs init', 'pubs add data/pagerank.bib',