diff --git a/pubs/commands/edit_cmd.py b/pubs/commands/edit_cmd.py index cd78dd7..30ab5e8 100644 --- a/pubs/commands/edit_cmd.py +++ b/pubs/commands/edit_cmd.py @@ -22,7 +22,11 @@ def command(args): citekey = args.citekey rp = repo.Repository(config()) - paper = rp.pull_paper(citekey) + try: + paper = rp.pull_paper(citekey) + except repo.InvalidReference as v: + ui.error(v) + ui.exit(1) coder = EnDecoder() if meta: diff --git a/pubs/commands/init_cmd.py b/pubs/commands/init_cmd.py index cfafb43..b6aa0ee 100644 --- a/pubs/commands/init_cmd.py +++ b/pubs/commands/init_cmd.py @@ -2,11 +2,11 @@ import os -from .. import databroker from ..configs import config from ..uis import get_ui from .. import color from ..repo import Repository +from ..content import system_path, check_directory def parser(subparsers): @@ -30,9 +30,9 @@ def command(args): if pubsdir is None: pubsdir = '~/.pubs' - pubsdir = os.path.normpath(os.path.abspath(os.path.expanduser(pubsdir))) + pubsdir = system_path(pubsdir) - if os.path.exists(pubsdir) and len(os.listdir(pubsdir)) > 0: + if check_directory(pubsdir, fail=False) and len(os.listdir(pubsdir)) > 0: ui.error('directory {} is not empty.'.format( color.dye(pubsdir, color.filepath))) ui.exit() diff --git a/pubs/commands/list_cmd.py b/pubs/commands/list_cmd.py index ae1421f..39d6219 100644 --- a/pubs/commands/list_cmd.py +++ b/pubs/commands/list_cmd.py @@ -1,3 +1,5 @@ +from datetime import datetime + from .. import repo from .. import pretty from .. import bibstruct @@ -25,7 +27,7 @@ def parser(subparsers): def date_added(np): n, p = np - return p.added + return p.added or datetime(1, 1, 1) def command(args): @@ -34,9 +36,10 @@ def command(args): papers = filter(lambda (n, p): filter_paper(p, args.query, case_sensitive=args.case_sensitive), enumerate(rp.all_papers())) - ui.print_('\n'.join( - pretty.paper_oneliner(p, n=n, citekey_only=args.citekeys) - for n, p in sorted(papers, key=date_added))) + if len(papers) > 0: + ui.print_('\n'.join( + pretty.paper_oneliner(p, n=n, citekey_only=args.citekeys) + for n, p in sorted(papers, key=date_added))) FIELD_ALIASES = { diff --git a/pubs/filebroker.py b/pubs/filebroker.py index d5ef507..fe1218c 100644 --- a/pubs/filebroker.py +++ b/pubs/filebroker.py @@ -66,10 +66,10 @@ class FileBroker(object): def remove(self, citekey): metafilepath = os.path.join(self.metadir, citekey + '.yaml') if check_file(metafilepath): - os.remove(metafilepath) + os.remove(system_path(metafilepath)) bibfilepath = os.path.join(self.bibdir, citekey + '.bib') if check_file(bibfilepath): - os.remove(bibfilepath) + os.remove(system_path(bibfilepath)) def exists(self, citekey, both=True): meta_exists = check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) @@ -178,7 +178,7 @@ class DocBroker(object): return filepath = self.real_docpath(docpath) if check_file(filepath): - os.remove(filepath) + os.remove(system_path(filepath)) def rename_doc(self, docpath, new_citekey): """ Move a document inside the docsdir diff --git a/setup.py b/setup.py index 0fe96ef..eeb3edd 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,5 @@ setup(name='pubs', description='research papers manager', requires=['bibtexparser'], packages=find_packages(), - package_data={'': ['*.tex', '*.sty']}, scripts=['pubs/pubs'] ) - -# TODO include proper package data from plugins (08/06/2013) -# should we use MANIFEST.in or package_data = ..., or both diff --git a/tests/test_usecase.py b/tests/test_usecase.py index b84d117..32fdac3 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -144,7 +144,32 @@ class TestList(DataCommandTestCase): 'pubs add /data/pagerank.bib -d /data/pagerank.pdf', 'pubs list', ] - self.execute_cmds(cmds) + outs = self.execute_cmds(cmds) + print outs[1].splitlines() + self.assertEquals(0, len(outs[1].splitlines())) + print outs[3].splitlines() + self.assertEquals(1, len(outs[3].splitlines())) + + def test_list_several_no_date(self): + self.execute_cmds(['pubs init -p /testrepo']) + self.fs['shutil'].rmtree('testrepo') + testrepo = os.path.join(os.path.dirname(__file__), 'testrepo') + fake_env.copy_dir(self.fs, testrepo, 'testrepo') + cmds = ['pubs list', + 'pubs remove -f Page99', + 'pubs list', + 'pubs add /data/pagerank.bib -d /data/pagerank.pdf', + 'pubs list', + ] + outs = self.execute_cmds(cmds) + print outs[0].splitlines() + self.assertEquals(4, len(outs[0].splitlines())) + print outs[2].splitlines() + self.assertEquals(3, len(outs[2].splitlines())) + print outs[4].splitlines() + self.assertEquals(4, len(outs[4].splitlines())) + # Last added should be last + self.assertEquals('[Page99]', outs[4].splitlines()[-1][:8]) def test_list_smart_case(self): cmds = ['pubs init', @@ -154,7 +179,7 @@ class TestList(DataCommandTestCase): ] outs = self.execute_cmds(cmds) print outs[-1] - self.assertEquals(1, len(outs[-1].split('/n'))) + self.assertEquals(1, len(outs[-1].splitlines())) def test_list_ignore_case(self): cmds = ['pubs init', @@ -163,7 +188,8 @@ class TestList(DataCommandTestCase): 'pubs list --ignore-case title:lAnguAge author:saunders', ] outs = self.execute_cmds(cmds) - self.assertEquals(1, len(outs[-1].split('/n'))) + print outs[-1] + self.assertEquals(1, len(outs[-1].splitlines())) def test_list_force_case(self): cmds = ['pubs init', @@ -172,7 +198,7 @@ class TestList(DataCommandTestCase): 'pubs list --force-case title:Language author:saunders', ] outs = self.execute_cmds(cmds) - self.assertEquals(0 + 1, len(outs[-1].split('/n'))) + self.assertEquals(0 + 1, len(outs[-1].split('\n'))) @@ -222,6 +248,9 @@ class TestUsecase(DataCommandTestCase): 'pubs remove -f turing1950computing', ] self.execute_cmds(cmds) + docdir = self.fs['os'].path.expanduser('~/.pubs/doc/') + print self.fs['os'].listdir(docdir) + self.assertNotIn('turing-mind-1950.pdf', self.fs['os'].listdir(docdir)) def test_editor_abort(self): with self.assertRaises(SystemExit): diff --git a/tests/testrepo/meta/Page99.yaml b/tests/testrepo/meta/Page99.yaml index 2c24eca..9d3dad2 100644 --- a/tests/testrepo/meta/Page99.yaml +++ b/tests/testrepo/meta/Page99.yaml @@ -1,3 +1,3 @@ -docfile: docsdir://doc/Page99.pdf +docfile: docsdir://Page99.pdf notes: [] tags: [search, network]