Fixes #144: behavior of add_copy mode during add.
- correctly handles add_copy mode and configuration, - add option top force 'copy' mode (since the default had been changed in between from 'copy' to 'move' this is now needed), - fixes assumption in one test that the default is 'copy' (in other words the test was broken and ensuring that the functionality was broken too.), - do not try to delete the source when it is an URL.
This commit is contained in:
parent
c6edacf3ec
commit
a8de97c327
@ -34,10 +34,19 @@ def parser(subparsers, conf):
|
|||||||
).completer = CommaSeparatedTagsCompletion(conf)
|
).completer = CommaSeparatedTagsCompletion(conf)
|
||||||
parser.add_argument('-k', '--citekey', help='citekey associated with the paper;\nif not provided, one will be generated automatically.',
|
parser.add_argument('-k', '--citekey', help='citekey associated with the paper;\nif not provided, one will be generated automatically.',
|
||||||
default=None, type=p3.u_maybe)
|
default=None, type=p3.u_maybe)
|
||||||
parser.add_argument('-L', '--link', action='store_false', dest='copy', default=True,
|
doc_add_group = parser.add_mutually_exclusive_group()
|
||||||
help="don't copy document files, just create a link.")
|
doc_add_group.add_argument(
|
||||||
parser.add_argument('-M', '--move', action='store_true', dest='move', default=False,
|
'-L', '--link', action='store_const', dest='doc_add', const='link',
|
||||||
help="move document instead of of copying (ignored if --link).")
|
default=None,
|
||||||
|
help="don't copy document files, just create a link.")
|
||||||
|
doc_add_group.add_argument(
|
||||||
|
'-M', '--move', action='store_const', dest='doc_add', const='move',
|
||||||
|
default=None,
|
||||||
|
help="move document instead of of copying.")
|
||||||
|
doc_add_group.add_argument(
|
||||||
|
'-C', '--copy', action='store_const', dest='doc_add', const='copy',
|
||||||
|
default=None,
|
||||||
|
help="copy document instead of of move.")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
@ -136,25 +145,20 @@ def command(conf, args):
|
|||||||
'{}, using {} instead.').format(bib_docfile, docfile))
|
'{}, using {} instead.').format(bib_docfile, docfile))
|
||||||
|
|
||||||
# create the paper
|
# create the paper
|
||||||
copy = args.copy
|
doc_add = args.doc_add
|
||||||
if copy is None:
|
if doc_add is None:
|
||||||
copy = conf['main']['doc_add'] in ('copy', 'move')
|
doc_add = conf['main']['doc_add']
|
||||||
move = args.move
|
|
||||||
if move is None:
|
|
||||||
move = conf['main']['doc_add'] == 'move'
|
|
||||||
|
|
||||||
rp.push_paper(p)
|
rp.push_paper(p)
|
||||||
ui.message('added to pubs:\n{}'.format(pretty.paper_oneliner(p)))
|
ui.message('added to pubs:\n{}'.format(pretty.paper_oneliner(p)))
|
||||||
if docfile is not None:
|
if docfile is not None:
|
||||||
rp.push_doc(p.citekey, docfile, copy=copy or args.move)
|
rp.push_doc(p.citekey, docfile, copy=(doc_add in ('copy', 'move')))
|
||||||
if copy:
|
if doc_add == 'move' and content.content_type(docfile) != 'url':
|
||||||
if move:
|
content.remove_file(docfile)
|
||||||
content.remove_file(docfile)
|
|
||||||
|
|
||||||
if copy:
|
if doc_add == 'move':
|
||||||
if move:
|
ui.message('{} was moved to the pubs repository.'.format(docfile))
|
||||||
ui.message('{} was moved to the pubs repository.'.format(docfile))
|
elif doc_add == 'copy':
|
||||||
else:
|
|
||||||
ui.message('{} was copied to the pubs repository.'.format(docfile))
|
ui.message('{} was copied to the pubs repository.'.format(docfile))
|
||||||
|
|
||||||
rp.close()
|
rp.close()
|
||||||
|
@ -292,9 +292,66 @@ class TestAdd(URLContentTestCase):
|
|||||||
'pubs add data/pagerank.bib --link -d data/pagerank.pdf',
|
'pubs add data/pagerank.bib --link -d data/pagerank.pdf',
|
||||||
]
|
]
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
self.assertEqual(os.listdir(
|
self.assertEqual(
|
||||||
os.path.join(self.default_pubs_dir, 'doc')),
|
os.listdir(os.path.join(self.default_pubs_dir, 'doc')),
|
||||||
[])
|
[])
|
||||||
|
self.assertTrue(os.path.exists('data/pagerank.pdf'))
|
||||||
|
|
||||||
|
def test_add_doc_nocopy_from_config_does_not_copy(self):
|
||||||
|
self.execute_cmds(['pubs init'])
|
||||||
|
config = conf.load_conf()
|
||||||
|
config['main']['doc_add'] = 'link'
|
||||||
|
conf.save_conf(config)
|
||||||
|
cmds = ['pubs add data/pagerank.bib -d data/pagerank.pdf']
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
self.assertEqual(
|
||||||
|
os.listdir(os.path.join(self.default_pubs_dir, 'doc')),
|
||||||
|
[])
|
||||||
|
self.assertTrue(os.path.exists('data/pagerank.pdf'))
|
||||||
|
|
||||||
|
def test_add_doc_copy(self):
|
||||||
|
cmds = ['pubs init',
|
||||||
|
'pubs add data/pagerank.bib --copy -d data/pagerank.pdf',
|
||||||
|
]
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
self.assertEqual(
|
||||||
|
os.listdir(os.path.join(self.default_pubs_dir, 'doc')),
|
||||||
|
['Page99.pdf'])
|
||||||
|
self.assertTrue(os.path.exists('data/pagerank.pdf'))
|
||||||
|
|
||||||
|
def test_add_doc_copy_from_config(self):
|
||||||
|
self.execute_cmds(['pubs init'])
|
||||||
|
config = conf.load_conf()
|
||||||
|
config['main']['doc_add'] = 'copy'
|
||||||
|
conf.save_conf(config)
|
||||||
|
cmds = ['pubs add data/pagerank.bib -d data/pagerank.pdf']
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
self.assertEqual(
|
||||||
|
os.listdir(os.path.join(self.default_pubs_dir, 'doc')),
|
||||||
|
['Page99.pdf'])
|
||||||
|
self.assertTrue(os.path.exists('data/pagerank.pdf'))
|
||||||
|
|
||||||
|
def test_add_doc_move(self):
|
||||||
|
cmds = ['pubs init',
|
||||||
|
'pubs add data/pagerank.bib --move -d data/pagerank.pdf',
|
||||||
|
]
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
self.assertEqual(
|
||||||
|
os.listdir(os.path.join(self.default_pubs_dir, 'doc')),
|
||||||
|
['Page99.pdf'])
|
||||||
|
self.assertFalse(os.path.exists('data/pagerank.pdf'))
|
||||||
|
|
||||||
|
def test_add_doc_move_from_config(self):
|
||||||
|
self.execute_cmds(['pubs init'])
|
||||||
|
config = conf.load_conf()
|
||||||
|
config['main']['doc_add'] = 'move'
|
||||||
|
conf.save_conf(config)
|
||||||
|
cmds = ['pubs add data/pagerank.bib -d data/pagerank.pdf']
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
self.assertEqual(
|
||||||
|
os.listdir(os.path.join(self.default_pubs_dir, 'doc')),
|
||||||
|
['Page99.pdf'])
|
||||||
|
self.assertFalse(os.path.exists('data/pagerank.pdf'))
|
||||||
|
|
||||||
def test_add_move_removes_doc(self):
|
def test_add_move_removes_doc(self):
|
||||||
cmds = ['pubs init',
|
cmds = ['pubs init',
|
||||||
@ -611,7 +668,7 @@ class TestUsecase(DataCommandTestCase):
|
|||||||
def test_first(self):
|
def test_first(self):
|
||||||
correct = ['Initializing pubs in /paper_first\n',
|
correct = ['Initializing pubs in /paper_first\n',
|
||||||
'added to pubs:\n[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n'
|
'added to pubs:\n[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n'
|
||||||
'data/pagerank.pdf was copied to the pubs repository.\n',
|
'data/pagerank.pdf was moved to the pubs repository.\n',
|
||||||
'[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n',
|
'[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n',
|
||||||
'\n',
|
'\n',
|
||||||
'',
|
'',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user