Several bug fixes.
- edit command fails correctly on unknown citekey, - init command and filebroker use content module to check paths, - fix wrong docfile in testrepo, - list command does not fail on None added date (unknown add dates are older than everything else). Also adds relevant test.
This commit is contained in:
parent
ac1562f4ea
commit
91b3fc75bb
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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 = {
|
||||
|
@ -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
|
||||
|
4
setup.py
4
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
|
||||
|
@ -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):
|
||||
|
@ -1,3 +1,3 @@
|
||||
docfile: docsdir://doc/Page99.pdf
|
||||
docfile: docsdir://Page99.pdf
|
||||
notes: []
|
||||
tags: [search, network]
|
||||
|
Loading…
x
Reference in New Issue
Block a user