papers renamed 'pubs'

main
Fabien Benureau 11 years ago
parent b03b899c5a
commit 8d91545472

2
.gitignore vendored

@ -2,5 +2,5 @@ build/
dist/ dist/
*~ *~
*.pyc *.pyc
papers.egg-info *.egg-info
.DS_Store .DS_Store

@ -1,63 +0,0 @@
import sys
from .. import repo
from .. import color
from ..configs import config
from ..uis import get_ui
from ..__init__ import __version__
def parser(subparsers):
parser = subparsers.add_parser('update', help='update the repository to the lastest format')
return parser
def command(args):
ui = get_ui()
code_version = __version__
repo_version = int(config().version)
if repo_version == code_version:
ui.print_('You papers repository is up-to-date.')
sys.exit(0)
elif repo_version > code_version:
ui.print_('Your repository was generated with an newer version of papers.\n'
'You should not use papers until you install the newest version.')
sys.exit(0)
else:
msg = ("You should backup the paper directory {} before continuing."
"Continue ?").format(color.dye(config().papers_dir, color.filepath))
sure = ui.input_yn(question=msg, default='n')
if not sure:
sys.exit(0)
if repo_version == 1:
rp = repo.Repository(config())
for p in rp.all_papers():
tags = set(p.metadata['tags'])
tags = tags.union(p.metadata['labels'])
p.metadata.pop('labels', [])
rp.save_paper(p)
repo_version = 2
if repo_version == 2:
# update config
cfg_update = [('papers-directory', 'papers_dir'),
('open-cmd', 'open_cmd'),
('edit-cmd', 'edit_cmd'),
('import-copy', 'import_copy'),
('import-move', 'import_move'),
]
for old, new in cfg_update:
try:
config()._cfg.set('papers', new, config()._cfg.get('papers', old))
config()._cfg.remove_option('papers', old)
except Exception:
pass
config().save()
repo_version = 3
config().version = repo_version
config().save()

@ -1,5 +0,0 @@
#!/usr/bin/env python2
# -*- coding:utf-8 -*-
from papers import papers_cmd
papers_cmd.execute()

@ -1,7 +1,6 @@
from ..files import editor_input from ..content import editor_input
from .. import repo from .. import repo
from ..paper import get_bibentry_from_string, get_safe_metadata_from_content from ..paper import get_bibentry_from_string, get_safe_metadata_from_content
from .helpers import add_references_argument, parse_reference
from ..configs import config from ..configs import config
from ..uis import get_ui from ..uis import get_ui
@ -11,7 +10,8 @@ def parser(subparsers):
help='open the paper bibliographic file in an editor') help='open the paper bibliographic file in an editor')
parser.add_argument('-m', '--meta', action='store_true', default=False, parser.add_argument('-m', '--meta', action='store_true', default=False,
help='edit metadata') help='edit metadata')
add_references_argument(parser, single=True) parser.add_argument('citekey',
help='citekey of the paper')
return parser return parser
@ -19,12 +19,15 @@ def command(args):
ui = get_ui() ui = get_ui()
meta = args.meta meta = args.meta
reference = args.reference citekey = args.citekey
rp = repo.Repository(config()) rp = repo.Repository(config())
key = parse_reference(rp, reference) coder = endecoder.EnDecoder()
paper = rp.get_paper(key) if meta:
filepath = rp._metafile(key) if meta else rp._bibfile(key) filepath = os.path.join(rp.databroker.databroker.filebroker.metadir(), citekey+'.yaml')
else:
filepath = os.path.join(rp.databroker.databroker.filebroker.bibdir(), citekey+'.bibyaml')
with open(filepath) as f: with open(filepath) as f:
content = f.read() content = f.read()
@ -49,7 +52,7 @@ def command(args):
options = ['overwrite', 'edit again', 'abort'] options = ['overwrite', 'edit again', 'abort']
choice = options[ui.input_choice( choice = options[ui.input_choice(
options, ['o', 'e', 'a'], options, ['o', 'e', 'a'],
question='A paper already exist with this citekey.' question='A paper already exists with this citekey.'
)] )]
if choice == 'abort': if choice == 'abort':

@ -10,9 +10,9 @@ from .. import color
def parser(subparsers): def parser(subparsers):
parser = subparsers.add_parser('init', parser = subparsers.add_parser('init',
help="initialize the papers directory") help="initialize the pubs directory")
parser.add_argument('-p', '--pubsdir', default=None, parser.add_argument('-p', '--pubsdir', default=None,
help='path to papers directory (if none, ~/.papers is used)') help='path to pubs directory (if none, ~/.ubs is used)')
parser.add_argument('-d', '--docsdir', default='docsdir://', parser.add_argument('-d', '--docsdir', default='docsdir://',
help=('path to document directory (if not specified, documents will' help=('path to document directory (if not specified, documents will'
'be stored in /path/to/pubsdir/doc/)')) 'be stored in /path/to/pubsdir/doc/)'))
@ -20,14 +20,14 @@ def parser(subparsers):
def command(args): def command(args):
"""Create a .papers directory""" """Create a .pubs directory"""
ui = get_ui() ui = get_ui()
pubsdir = args.pubsdir pubsdir = args.pubsdir
docsdir = args.docsdir docsdir = args.docsdir
if pubsdir is None: if pubsdir is None:
pubsdir = '~/.papers' pubsdir = '~/.pubs'
pubsdir = os.path.normpath(os.path.abspath(os.path.expanduser(pubsdir))) pubsdir = os.path.normpath(os.path.abspath(os.path.expanduser(pubsdir)))
@ -36,7 +36,7 @@ def command(args):
color.dye(pubsdir, color.filepath))) color.dye(pubsdir, color.filepath)))
ui.exit() ui.exit()
ui.print_('Initializing papers in {}.'.format( ui.print_('Initializing pubs in {}.'.format(
color.dye(pubsdir, color.filepath))) color.dye(pubsdir, color.filepath)))
config().pubsdir = pubsdir config().pubsdir = pubsdir

@ -1,19 +1,19 @@
""" """
This command is all about tags. This command is all about tags.
The different use cases are : The different use cases are :
1. > papers tag 1. > pubs tag
Returns the list of all tags Returns the list of all tags
2. > papers tag citekey 2. > pubs tag citekey
Return the list of tags of the given citekey Return the list of tags of the given citekey
3. > papers tag citekey math 3. > pubs tag citekey math
Add 'math' to the list of tags of the given citekey Add 'math' to the list of tags of the given citekey
4. > papers tag citekey :math 4. > pubs tag citekey :math
Remove 'math' for the list of tags of the given citekey Remove 'math' for the list of tags of the given citekey
5. > papers tag citekey math+romance-war 5. > pubs tag citekey math+romance-war
Add 'math' and 'romance' tags to the given citekey, and remove the 'war' tag Add 'math' and 'romance' tags to the given citekey, and remove the 'war' tag
6. > papers tag math 6. > pubs tag math
If 'math' is not a citekey, then display all papers with the tag 'math' If 'math' is not a citekey, then display all papers with the tag 'math'
7. > papers tag -war+math+romance 7. > pubs tag -war+math+romance
display all papers with the tag 'math', 'romance' but not 'war' display all papers with the tag 'math', 'romance' but not 'war'
""" """

@ -0,0 +1,37 @@
import sys
from .. import repo
from .. import color
from ..configs import config
from ..uis import get_ui
from ..__init__ import __version__
def parser(subparsers):
parser = subparsers.add_parser('update', help='update the repository to the lastest format')
return parser
def command(args):
ui = get_ui()
code_version = __version__
repo_version = int(config().version)
if repo_version == code_version:
ui.print_('Your pubs repository is up-to-date.')
sys.exit(0)
elif repo_version > code_version:
ui.print_('Your repository was generated with an newer version of pubs.\n'
'You should not use pubs until you install the newest version.')
sys.exit(0)
else:
msg = ("You should backup the pubs directory {} before continuing."
"Continue ?").format(color.dye(config().papers_dir, color.filepath))
sure = ui.input_yn(question=msg, default='n')
if not sure:
sys.exit(0)
# config().version = repo_version
# config().save()

@ -5,8 +5,8 @@ from .p3 import configparser
# constant stuff (DFT = DEFAULT) # constant stuff (DFT = DEFAULT)
MAIN_SECTION = 'papers' MAIN_SECTION = 'pubs'
DFT_CONFIG_PATH = os.path.expanduser('~/.papersrc') DFT_CONFIG_PATH = os.path.expanduser('~/.pubsrc')
try: try:
DFT_EDIT_CMD = os.environ['EDITOR'] DFT_EDIT_CMD = os.environ['EDITOR']
except KeyError: except KeyError:
@ -15,7 +15,7 @@ except KeyError:
DFT_PLUGINS = '' DFT_PLUGINS = ''
DFT_CONFIG = collections.OrderedDict([ DFT_CONFIG = collections.OrderedDict([
('pubsdir', os.path.expanduser('~/.papers')), ('pubsdir', os.path.expanduser('~/.pubs')),
('docsdir', ''), ('docsdir', ''),
('import_copy', True), ('import_copy', True),
('import_move', False), ('import_move', False),

@ -35,7 +35,7 @@ def load_plugins(ui, names):
PapersPlugin subclasses desired. PapersPlugin subclasses desired.
""" """
for name in names: for name in names:
modname = '%s.%s.%s.%s' % ('papers', PLUGIN_NAMESPACE, name, name) modname = '%s.%s.%s.%s' % ('pubs', PLUGIN_NAMESPACE, name, name)
try: try:
namespace = importlib.import_module(modname) namespace = importlib.import_module(modname)
except ImportError as exc: except ImportError as exc:

@ -3,7 +3,7 @@ import shlex
from ...plugins import PapersPlugin from ...plugins import PapersPlugin
from ...configs import config from ...configs import config
from ...papers_cmd import execute from ...pubs_cmd import execute
class Alias(object): class Alias(object):

@ -0,0 +1,5 @@
#!/usr/bin/env python2
# -*- coding:utf-8 -*-
from pubs import pubs_cmd
pubs_cmd.execute()

@ -41,17 +41,17 @@ def _update_check(config, ui):
if repo_version > code_version: if repo_version > code_version:
ui.warning( ui.warning(
'your repository was generated with an newer version' 'your repository was generated with an newer version'
' of papers (v{}) than the one you are using (v{}).' ' of pubs (v{}) than the one you are using (v{}).'
'\n'.format(repo_version, code_version) + '\n'.format(repo_version, code_version) +
'You should not use papers until you install the ' 'You should not use pubs until you install the '
'newest version. (use version_warning in you papersrc ' 'newest version. (use version_warning in you pubsrc '
'to bypass this error)') 'to bypass this error)')
sys.exit() sys.exit()
elif repo_version < code_version: elif repo_version < code_version:
ui.print_( ui.print_(
'warning: your repository version (v{})'.format(repo_version) 'warning: your repository version (v{})'.format(repo_version)
+ 'must be updated to version {}.\n'.format(code_version) + 'must be updated to version {}.\n'.format(code_version)
+ "run 'papers update'.") + "run 'pubs update'.")
sys.exit() sys.exit()

@ -2,7 +2,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup(name='papers', setup(name='pubs',
version='4', version='4',
author='Fabien Benureau, Olivier Mangin, Jonathan Grizou', author='Fabien Benureau, Olivier Mangin, Jonathan Grizou',
author_email='fabien.benureau+inria@gmail.com', author_email='fabien.benureau+inria@gmail.com',
@ -11,7 +11,7 @@ setup(name='papers',
requires=['pybtex'], requires=['pybtex'],
packages=find_packages(), packages=find_packages(),
package_data={'': ['*.tex', '*.sty']}, package_data={'': ['*.tex', '*.sty']},
scripts=['papers/papers'] scripts=['pubs/pubs']
) )
# TODO include proper package data from plugins (08/06/2013) # TODO include proper package data from plugins (08/06/2013)

@ -11,8 +11,8 @@ import fake_filesystem
import fake_filesystem_shutil import fake_filesystem_shutil
import fake_filesystem_glob import fake_filesystem_glob
from papers import color from pubs import color
from papers.p3 import io, input from pubs.p3 import io, input
# code for fake fs # code for fake fs
@ -26,13 +26,13 @@ real_glob = glob
# def _mod_list(): # def _mod_list():
# ml = [] # ml = []
# import papers # import pubs
# for importer, modname, ispkg in pkgutil.walk_packages( # for importer, modname, ispkg in pkgutil.walk_packages(
# path=papers.__path__, # path=pubs.__path__,
# prefix=papers.__name__ + '.', # prefix=pubs.__name__ + '.',
# onerror=lambda x: None): # onerror=lambda x: None):
# # HACK to not load textnote # # HACK to not load textnote
# if not modname.startswith('papers.plugs.texnote'): # if not modname.startswith('pubs.plugs.texnote'):
# ml.append((modname, __import__(modname, fromlist='dummy'))) # ml.append((modname, __import__(modname, fromlist='dummy')))
# return ml # return ml

@ -1,6 +1,8 @@
from pybtex.database import Person from pybtex.database import Person
from papers.paper import Paper, get_bibentry_from_string import testenv
from pubs import endecoder
import str_fixtures
turing1950 = Paper() turing1950 = Paper()
turing1950.bibentry.fields['title'] = u'Computing machinery and intelligence.' turing1950.bibentry.fields['title'] = u'Computing machinery and intelligence.'
@ -16,35 +18,7 @@ doe2013.bibentry.fields['year'] = u'2013'
doe2013.bibentry.persons['author'] = [Person(u'John Doe')] doe2013.bibentry.persons['author'] = [Person(u'John Doe')]
doe2013.citekey = doe2013.generate_citekey() doe2013.citekey = doe2013.generate_citekey()
coder = endecoder.EnDecoder()
bibdata = coder.decode_bibdata(str_fixtures.bibtex_external0, fmt='bibtex')
page99 = Paper(bibdata)
pagerankbib = """
@techreport{Page99,
number = {1999-66},
month = {November},
author = {Lawrence Page and Sergey Brin and Rajeev Motwani and Terry Winograd},
note = {Previous number = SIDL-WP-1999-0120},
title = {The PageRank Citation Ranking: Bringing Order to the Web.},
type = {Technical Report},
publisher = {Stanford InfoLab},
year = {1999},
institution = {Stanford InfoLab},
url = {http://ilpubs.stanford.edu:8090/422/},
}
"""
page99 = Paper(bibentry=get_bibentry_from_string(pagerankbib)[1])
pagerankbib_generated = """@techreport{
Page99,
author = "Page, Lawrence and Brin, Sergey and Motwani, Rajeev and Winograd, Terry",
publisher = "Stanford InfoLab",
title = "The PageRank Citation Ranking: Bringing Order to the Web.",
url = "http://ilpubs.stanford.edu:8090/422/",
number = "1999-66",
month = "November",
note = "Previous number = SIDL-WP-1999-0120",
year = "1999",
institution = "Stanford InfoLab"
}
"""

@ -1,11 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
rm -Rf tmpdir/*; rm -Rf tmpdir/*;
papers init -p tmpdir/; pubs init -p tmpdir/;
papers add -d data/pagerank.pdf -b data/pagerank.bib; pubs add -d data/pagerank.pdf -b data/pagerank.bib;
papers list; pubs list;
papers tag; pubs tag;
papers tag Page99 network+search; pubs tag Page99 network+search;
papers tag Page99; pubs tag Page99;
papers tag search; pubs tag search;
papers tag 0; pubs tag 0;
#rm -Rf tmpdir/*; #rm -Rf tmpdir/*;

@ -1,5 +1,5 @@
import testenv import testenv
from papers import color from pubs import color
def perf_color(): def perf_color():
s = str(range(1000)) s = str(range(1000))

@ -2,9 +2,9 @@
import unittest import unittest
import testenv import testenv
from papers import configs from pubs import configs
from papers.configs import config from pubs.configs import config
from papers.p3 import configparser from pubs.p3 import configparser
class TestConfig(unittest.TestCase): class TestConfig(unittest.TestCase):
@ -17,7 +17,7 @@ class TestConfig(unittest.TestCase):
a = configs.Config() a = configs.Config()
a.as_global() a.as_global()
self.assertEqual(config().papers_dir, configs.DFT_CONFIG['papers_dir']) self.assertEqual(config().pubs_dir, configs.DFT_CONFIG['pubs_dir'])
self.assertEqual(config().color, configs.str2bool(configs.DFT_CONFIG['color'])) self.assertEqual(config().color, configs.str2bool(configs.DFT_CONFIG['color']))
def test_set(self): def test_set(self):
@ -25,11 +25,11 @@ class TestConfig(unittest.TestCase):
a.as_global() a.as_global()
config().color = 'no' config().color = 'no'
self.assertEqual(config().color, False) self.assertEqual(config().color, False)
self.assertEqual(config('papers').color, False) self.assertEqual(config('pubs').color, False)
# booleans type for new variables are memorized, but not saved. # booleans type for new variables are memorized, but not saved.
config().bla = True config().bla = True
self.assertEqual(config().bla, True) self.assertEqual(config().bla, True)
self.assertEqual(config('papers').bla, True) self.assertEqual(config('pubs').bla, True)
with self.assertRaises(configparser.NoOptionError): with self.assertRaises(configparser.NoOptionError):
config()._cfg.get(configs.MAIN_SECTION, '_section') config()._cfg.get(configs.MAIN_SECTION, '_section')
@ -65,5 +65,5 @@ class TestConfig(unittest.TestCase):
self.assertEqual(config(section = 'bla3').get('color', default = config().color), True) self.assertEqual(config(section = 'bla3').get('color', default = config().color), True)
def test_keywords(self): def test_keywords(self):
a = configs.Config(papers_dir = '/blabla') a = configs.Config(pubs_dir = '/blabla')
self.assertEqual(a.papers_dir, '/blabla') self.assertEqual(a.pubs_dir, '/blabla')

@ -5,10 +5,10 @@ import os
import testenv import testenv
import fake_env import fake_env
from papers import content, filebroker, databroker, datacache from pubs import content, filebroker, databroker, datacache
import str_fixtures import str_fixtures
from papers import endecoder from pubs import endecoder
class TestFakeFs(unittest.TestCase): class TestFakeFs(unittest.TestCase):
"""Abstract TestCase intializing the fake filesystem.""" """Abstract TestCase intializing the fake filesystem."""

@ -4,7 +4,7 @@ import unittest
import yaml import yaml
import testenv import testenv
from papers import endecoder from pubs import endecoder
from str_fixtures import bibyaml_raw0, bibtexml_raw0, bibtex_raw0, metadata_raw0 from str_fixtures import bibyaml_raw0, bibtexml_raw0, bibtex_raw0, metadata_raw0

@ -1,7 +1,7 @@
from unittest import TestCase from unittest import TestCase
import testenv import testenv
from papers.events import Event from pubs.events import Event
_output = None _output = None

@ -5,7 +5,7 @@ import os
import testenv import testenv
import fake_env import fake_env
from papers import content, filebroker from pubs import content, filebroker
class TestFakeFs(unittest.TestCase): class TestFakeFs(unittest.TestCase):
"""Abstract TestCase intializing the fake filesystem.""" """Abstract TestCase intializing the fake filesystem."""

@ -4,10 +4,10 @@ import shutil
import os import os
import fixtures import fixtures
from papers.repo import (Repository, _base27, BIB_DIR, META_DIR, from pubs.repo import (Repository, _base27, BIB_DIR, META_DIR,
CiteKeyCollision) CiteKeyCollision)
from papers.paper import PaperInRepo from pubs.paper import PaperInRepo
from papers import configs, files from pubs import configs, files
class TestCitekeyGeneration(unittest.TestCase): class TestCitekeyGeneration(unittest.TestCase):
@ -30,7 +30,7 @@ class TestRepo(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmpdir = tempfile.mkdtemp() self.tmpdir = tempfile.mkdtemp()
self.repo = Repository(configs.Config(papers_dir=self.tmpdir), load=False) self.repo = Repository(configs.Config(pubs_dir=self.tmpdir), load=False)
self.repo.save() self.repo.save()
self.repo.add_paper(fixtures.turing1950) self.repo.add_paper(fixtures.turing1950)

@ -2,7 +2,7 @@
import unittest import unittest
import testenv import testenv
from papers.commands.tag_cmd import _parse_tags, _tag_groups from pubs.commands.tag_cmd import _parse_tags, _tag_groups
class TestTag(unittest.TestCase): class TestTag(unittest.TestCase):

@ -5,12 +5,12 @@ import os
import testenv import testenv
import fake_env import fake_env
from papers import papers_cmd from pubs import pubs_cmd
from papers import color, content, filebroker, uis, beets_ui, p3 from pubs import color, content, filebroker, uis, beets_ui, p3
import str_fixtures import str_fixtures
from papers.commands import init_cmd, import_cmd from pubs.commands import init_cmd, import_cmd
# code for fake fs # code for fake fs
@ -65,7 +65,7 @@ class CommandTestCase(unittest.TestCase):
input = fake_env.FakeInput(cmd[1], [content, uis, beets_ui, p3]) input = fake_env.FakeInput(cmd[1], [content, uis, beets_ui, p3])
input.as_global() input.as_global()
_, stdout, stderr = fake_env.redirect(papers_cmd.execute)(cmd[0].split()) _, stdout, stderr = fake_env.redirect(pubs_cmd.execute)(cmd[0].split())
if len(cmd) == 3: if len(cmd) == 3:
actual_out = color.undye(stdout.getvalue()) actual_out = color.undye(stdout.getvalue())
correct_out = color.undye(cmd[2]) correct_out = color.undye(cmd[2])
@ -73,7 +73,7 @@ class CommandTestCase(unittest.TestCase):
else: else:
assert type(cmd) == str assert type(cmd) == str
_, stdout, stderr = fake_env.redirect(papers_cmd.execute)(cmd.split()) _, stdout, stderr = fake_env.redirect(pubs_cmd.execute)(cmd.split())
assert(stderr.getvalue() == '') assert(stderr.getvalue() == '')
outs.append(color.undye(stdout.getvalue())) outs.append(color.undye(stdout.getvalue()))
@ -97,28 +97,28 @@ class DataCommandTestCase(CommandTestCase):
class TestInit(CommandTestCase): class TestInit(CommandTestCase):
def test_init(self): def test_init(self):
pubsdir = os.path.expanduser('~/papers_test2') pubsdir = os.path.expanduser('~/pubs_test2')
papers_cmd.execute('papers init -p {}'.format(pubsdir).split()) pubs_cmd.execute('pubs init -p {}'.format(pubsdir).split())
self.assertEqual(set(self.fs['os'].listdir(pubsdir)), self.assertEqual(set(self.fs['os'].listdir(pubsdir)),
{'bib', 'doc', 'meta', 'notes'}) {'bib', 'doc', 'meta', 'notes'})
def test_init2(self): def test_init2(self):
pubsdir = os.path.expanduser('~/.papers') pubsdir = os.path.expanduser('~/.pubs')
papers_cmd.execute('papers init'.split()) pubs_cmd.execute('pubs init'.split())
self.assertEqual(set(self.fs['os'].listdir(pubsdir)), self.assertEqual(set(self.fs['os'].listdir(pubsdir)),
{'bib', 'doc', 'meta', 'notes'}) {'bib', 'doc', 'meta', 'notes'})
class TestAdd(DataCommandTestCase): class TestAdd(DataCommandTestCase):
def test_add(self): def test_add(self):
cmds = ['papers init', cmds = ['pubs init',
'papers add -b /data/pagerank.bib -d /data/pagerank.pdf', 'pubs add -b /data/pagerank.bib -d /data/pagerank.pdf',
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_add2(self): def test_add2(self):
cmds = ['papers init -p /not_default', cmds = ['pubs init -p /not_default',
'papers add -b /data/pagerank.bib -d /data/pagerank.pdf', 'pubs add -b /data/pagerank.bib -d /data/pagerank.pdf',
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
self.assertEqual(set(self.fs['os'].listdir('/not_default/doc')), {'Page99.pdf'}) self.assertEqual(set(self.fs['os'].listdir('/not_default/doc')), {'Page99.pdf'})
@ -127,37 +127,37 @@ class TestAdd(DataCommandTestCase):
class TestList(DataCommandTestCase): class TestList(DataCommandTestCase):
def test_list(self): def test_list(self):
cmds = ['papers init -p /not_default2', cmds = ['pubs init -p /not_default2',
'papers list', 'pubs list',
'papers add -b /data/pagerank.bib -d /data/pagerank.pdf', 'pubs add -b /data/pagerank.bib -d /data/pagerank.pdf',
'papers list', 'pubs list',
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_list_smart_case(self): def test_list_smart_case(self):
cmds = ['papers init', cmds = ['pubs init',
'papers list', 'pubs list',
'papers import data/', 'pubs import data/',
'papers list title:language author:Saunders', 'pubs list title:language author:Saunders',
] ]
outs = self.execute_cmds(cmds) outs = self.execute_cmds(cmds)
print outs[-1] print outs[-1]
self.assertEquals(1, len(outs[-1].split('/n'))) self.assertEquals(1, len(outs[-1].split('/n')))
def test_list_ignore_case(self): def test_list_ignore_case(self):
cmds = ['papers init', cmds = ['pubs init',
'papers list', 'pubs list',
'papers import data/', 'pubs import data/',
'papers list --ignore-case title:lAnguAge author:saunders', 'pubs list --ignore-case title:lAnguAge author:saunders',
] ]
outs = self.execute_cmds(cmds) outs = self.execute_cmds(cmds)
self.assertEquals(1, len(outs[-1].split('/n'))) self.assertEquals(1, len(outs[-1].split('/n')))
def test_list_force_case(self): def test_list_force_case(self):
cmds = ['papers init', cmds = ['pubs init',
'papers list', 'pubs list',
'papers import data/', 'pubs import data/',
'papers list --force-case title:Language author:saunders', 'pubs list --force-case title:Language author:saunders',
] ]
outs = self.execute_cmds(cmds) outs = self.execute_cmds(cmds)
self.assertEquals(0 + 1, len(outs[-1].split('/n'))) self.assertEquals(0 + 1, len(outs[-1].split('/n')))
@ -167,7 +167,7 @@ class TestList(DataCommandTestCase):
class TestUsecase(DataCommandTestCase): class TestUsecase(DataCommandTestCase):
def test_first(self): def test_first(self):
correct = ['Initializing papers in /paper_first.\n', correct = ['Initializing pubs in /paper_first.\n',
'', '',
'[Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) \n', '[Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) \n',
'', '',
@ -176,55 +176,55 @@ class TestUsecase(DataCommandTestCase):
'[Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) search network\n' '[Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) search network\n'
] ]
cmds = ['papers init -p paper_first/', cmds = ['pubs init -p paper_first/',
'papers add -d data/pagerank.pdf -b data/pagerank.bib', 'pubs add -d data/pagerank.pdf -b data/pagerank.bib',
'papers list', 'pubs list',
'papers tag', 'pubs tag',
'papers tag Page99 network+search', 'pubs tag Page99 network+search',
'papers tag Page99', 'pubs tag Page99',
'papers tag search', 'pubs tag search',
] ]
self.assertEqual(correct, self.execute_cmds(cmds)) self.assertEqual(correct, self.execute_cmds(cmds))
def test_second(self): def test_second(self):
cmds = ['papers init -p paper_second/', cmds = ['pubs init -p paper_second/',
'papers add -b data/pagerank.bib', 'pubs add -b data/pagerank.bib',
'papers add -d data/turing-mind-1950.pdf -b data/turing1950.bib', 'pubs add -d data/turing-mind-1950.pdf -b data/turing1950.bib',
'papers add -b data/martius.bib', 'pubs add -b data/martius.bib',
'papers add -b data/10.1371%2Fjournal.pone.0038236.bib', 'pubs add -b data/10.1371%2Fjournal.pone.0038236.bib',
'papers list', 'pubs list',
'papers attach Page99 data/pagerank.pdf' 'pubs attach Page99 data/pagerank.pdf'
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_third(self): def test_third(self):
cmds = ['papers init', cmds = ['pubs init',
'papers add -b data/pagerank.bib', 'pubs add -b data/pagerank.bib',
'papers add -d data/turing-mind-1950.pdf -b data/turing1950.bib', 'pubs add -d data/turing-mind-1950.pdf -b data/turing1950.bib',
'papers add -b data/martius.bib', 'pubs add -b data/martius.bib',
'papers add -b data/10.1371%2Fjournal.pone.0038236.bib', 'pubs add -b data/10.1371%2Fjournal.pone.0038236.bib',
'papers list', 'pubs list',
'papers attach Page99 data/pagerank.pdf', 'pubs attach Page99 data/pagerank.pdf',
('papers remove Page99', ['y']), ('pubs remove Page99', ['y']),
'papers remove -f turing1950computing', 'pubs remove -f turing1950computing',
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_editor_abort(self): def test_editor_abort(self):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
cmds = ['papers init', cmds = ['pubs init',
('papers add', ['abc', 'n']), ('pubs add', ['abc', 'n']),
('papers add', ['abc', 'y', 'abc', 'n']), ('pubs add', ['abc', 'y', 'abc', 'n']),
'papers add -b data/pagerank.bib', 'pubs add -b data/pagerank.bib',
('papers edit Page99', ['', 'a']), ('pubs edit Page99', ['', 'a']),
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_editor_success(self): def test_editor_success(self):
cmds = ['papers init', cmds = ['pubs init',
('papers add', [str_fixtures.bibtex_external0]), ('pubs add', [str_fixtures.bibtex_external0]),
('papers remove Page99', ['y']), ('pubs remove Page99', ['y']),
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
@ -239,64 +239,64 @@ class TestUsecase(DataCommandTestCase):
line2 = re.sub('L. Page', 'L. Ridge', line1) line2 = re.sub('L. Page', 'L. Ridge', line1)
line3 = re.sub('Page99', 'Ridge07', line2) line3 = re.sub('Page99', 'Ridge07', line2)
cmds = ['papers init', cmds = ['pubs init',
'papers add -b data/pagerank.bib', 'pubs add -b data/pagerank.bib',
('papers list', [], line), ('pubs list', [], line),
('papers edit Page99', [bib1]), ('pubs edit Page99', [bib1]),
('papers list', [], line1), ('pubs list', [], line1),
('papers edit Page99', [bib2]), ('pubs edit Page99', [bib2]),
('papers list', [], line2), ('pubs list', [], line2),
('papers edit Page99', [bib3]), ('pubs edit Page99', [bib3]),
('papers list', [], line3), ('pubs list', [], line3),
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_export(self): def test_export(self):
cmds = ['papers init', cmds = ['pubs init',
('papers add', [str_fixtures.bibtex_external0]), ('pubs add', [str_fixtures.bibtex_external0]),
'papers export Page99', 'pubs export Page99',
('papers export Page99 -f bibtex', [], str_fixtures.bibtex_raw0), ('pubs export Page99 -f bibtex', [], str_fixtures.bibtex_raw0),
'papers export Page99 -f bibyaml', 'pubs export Page99 -f bibyaml',
] ]
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_import(self): def test_import(self):
cmds = ['papers init', cmds = ['pubs init',
'papers import data/', 'pubs import data/',
'papers list' 'pubs list'
] ]
outs = self.execute_cmds(cmds) outs = self.execute_cmds(cmds)
self.assertEqual(4 + 1, len(outs[-1].split('\n'))) self.assertEqual(4 + 1, len(outs[-1].split('\n')))
def test_import_one(self): def test_import_one(self):
cmds = ['papers init', cmds = ['pubs init',
'papers import data/ Page99', 'pubs import data/ Page99',
'papers list' 'pubs list'
] ]
outs = self.execute_cmds(cmds) outs = self.execute_cmds(cmds)
self.assertEqual(1 + 1, len(outs[-1].split('\n'))) self.assertEqual(1 + 1, len(outs[-1].split('\n')))
def test_open(self): def test_open(self):
cmds = ['papers init', cmds = ['pubs init',
'papers add -b data/pagerank.bib', 'pubs add -b data/pagerank.bib',
'papers open Page99' 'pubs open Page99'
] ]
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
self.execute_cmds(cmds) self.execute_cmds(cmds)
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
cmds[-1] == 'papers open Page8' cmds[-1] == 'pubs open Page8'
self.execute_cmds(cmds) self.execute_cmds(cmds)
def test_update(self): def test_update(self):
cmds = ['papers init', cmds = ['pubs init',
'papers add -b data/pagerank.bib', 'pubs add -b data/pagerank.bib',
'papers update' 'pubs update'
] ]
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):

Loading…
Cancel
Save