Adds move option to add and attach commands.
When set removes original document file after copy.
This commit is contained in:
parent
de2a50eeb2
commit
67aac0a2d7
@ -23,6 +23,8 @@ def parser(subparsers):
|
||||
default=None)
|
||||
parser.add_argument('-L', '--link', action='store_false', dest='copy', default=True,
|
||||
help="don't copy document files, just create a link.")
|
||||
parser.add_argument('-M', '--move', action='store_true', dest='move', default=False,
|
||||
help="move document instead of of copying (ignored if --link).")
|
||||
return parser
|
||||
|
||||
|
||||
@ -127,6 +129,8 @@ def command(args):
|
||||
rp.push_paper(p)
|
||||
if docfile is not None:
|
||||
rp.push_doc(p.citekey, docfile, copy=args.copy)
|
||||
if args.copy and args.move:
|
||||
content.remove_file(docfile)
|
||||
ui.print_('{}\nwas added to pubs.'.format(pretty.paper_oneliner(p)))
|
||||
except ValueError as v:
|
||||
ui.error(v.message)
|
||||
|
@ -11,6 +11,8 @@ def parser(subparsers):
|
||||
# help="copy document files into library directory (default)")
|
||||
parser.add_argument('-L', '--link', action='store_false', dest='copy', default=True,
|
||||
help="don't copy document files, just create a link.")
|
||||
parser.add_argument('-M', '--move', action='store_true', dest='move', default=False,
|
||||
help="move document instead of of copying (ignored if --link).")
|
||||
parser.add_argument('citekey',
|
||||
help='citekey of the paper')
|
||||
parser.add_argument('document',
|
||||
@ -32,6 +34,9 @@ def command(args):
|
||||
try:
|
||||
document = args.document
|
||||
rp.push_doc(paper.citekey, document, copy=args.copy)
|
||||
if args.copy and args.move:
|
||||
content.remove_file(document)
|
||||
|
||||
ui.print_('{} attached to {}'.format(color.dye(document, color.bold), color.dye(paper.citekey, color.citekey)))
|
||||
|
||||
except ValueError as v:
|
||||
|
@ -21,7 +21,7 @@ PRINT_OUTPUT=False
|
||||
CAPTURE_OUTPUT=True
|
||||
|
||||
|
||||
# code for fake fs
|
||||
# code for fake fs
|
||||
|
||||
class TestFakeInput(unittest.TestCase):
|
||||
|
||||
@ -174,6 +174,13 @@ class TestAdd(DataCommandTestCase):
|
||||
self.fs['os'].path.join(self.default_pubs_dir, 'doc')),
|
||||
[])
|
||||
|
||||
def test_add_move_removes_doc(self):
|
||||
cmds = ['pubs init',
|
||||
'pubs add /data/pagerank.bib --move -d /data/pagerank.pdf',
|
||||
]
|
||||
self.execute_cmds(cmds)
|
||||
self.assertFalse(self.fs['os'].path.exists('/data/pagerank.pdf'))
|
||||
|
||||
def test_add_twice_fails(self):
|
||||
cmds = ['pubs init',
|
||||
'pubs add /data/pagerank.bib',
|
||||
@ -241,7 +248,6 @@ class TestList(DataCommandTestCase):
|
||||
self.assertEqual(0 + 1, len(outs[-1].split('\n')))
|
||||
|
||||
|
||||
|
||||
class TestUsecase(DataCommandTestCase):
|
||||
|
||||
def test_first(self):
|
||||
@ -291,7 +297,6 @@ class TestUsecase(DataCommandTestCase):
|
||||
docdir = self.fs['os'].path.expanduser('~/.pubs/doc/')
|
||||
self.assertNotIn('turing-mind-1950.pdf', self.fs['os'].listdir(docdir))
|
||||
|
||||
|
||||
def test_tag_list(self):
|
||||
correct = ['Initializing pubs in /paper_first\n',
|
||||
'',
|
||||
@ -412,6 +417,27 @@ class TestUsecase(DataCommandTestCase):
|
||||
outs = self.execute_cmds(cmds)
|
||||
self.assertEqual(1, len(outs[2].splitlines()))
|
||||
|
||||
def test_attach(self):
|
||||
cmds = ['pubs init',
|
||||
'pubs add data/pagerank.bib',
|
||||
'pubs attach Page99 data/pagerank.pdf'
|
||||
]
|
||||
self.execute_cmds(cmds)
|
||||
self.assertTrue(self.fs['os'].path.exists(
|
||||
self.fs['os'].path.join(self.default_pubs_dir,
|
||||
'doc',
|
||||
'Page99.pdf')))
|
||||
# Also test that do not remove original
|
||||
self.assertTrue(self.fs['os'].path.exists('/data/pagerank.pdf'))
|
||||
|
||||
def test_attach_with_move(self):
|
||||
cmds = ['pubs init -p paper_second/',
|
||||
'pubs add data/pagerank.bib',
|
||||
'pubs attach --move Page99 data/pagerank.pdf'
|
||||
]
|
||||
self.execute_cmds(cmds)
|
||||
self.assertFalse(self.fs['os'].path.exists('/data/pagerank.pdf'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user