diff --git a/pubs/commands/list_cmd.py b/pubs/commands/list_cmd.py index e38c4f7..b615e54 100644 --- a/pubs/commands/list_cmd.py +++ b/pubs/commands/list_cmd.py @@ -22,6 +22,9 @@ def parser(subparsers, conf): parser.add_argument('-a', '--alphabetical', action='store_true', dest='alphabetical', default=False, help='lexicographic order on the citekeys.') + parser.add_argument('-C', '--chronological', action='store_true', + dest='chronological', default=False, + help='chronological order on the year field.') parser.add_argument('--no-docs', action='store_true', dest='nodocs', default=False, help='list only pubs without attached documents.') @@ -45,6 +48,8 @@ def command(conf, args): papers = [p for p in papers if p.docpath is None] if args.alphabetical: papers = sorted(papers, key=lambda p: p.citekey) + elif args.chronological: + papers = sorted(papers, key=lambda p: ('year' not in p.bibdata, p.bibdata.get('year'), date_added)) else: papers = sorted(papers, key=date_added) if len(papers) > 0: diff --git a/tests/bibexamples/noyear.bib b/tests/bibexamples/noyear.bib new file mode 100644 index 0000000..3ec056b --- /dev/null +++ b/tests/bibexamples/noyear.bib @@ -0,0 +1,5 @@ +@article{Doe_noyear, + title={About Assigning Timestamps to Research Articles}, + author={Doe, John}, + journal={Journal Example}, +} diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 66d9260..33301a4 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -516,6 +516,27 @@ class TestList(DataCommandTestCase): self.assertEqual(0, len(outs[3].splitlines())) self.assertEqual(1, len(outs[4].splitlines())) + def test_list_chronological_order(self): + cmds = ['pubs init', + 'pubs import data/', + 'pubs remove -f Einstein_1935', + 'pubs remove -f Cesar2013', + 'pubs list --chronological', + 'pubs import bibexamples/noyear.bib', + 'pubs list -C', + ] + data_chrono_correct = '[Schrodinger_1935] Schrödinger, E. and Born, M. "Discussion of Probability Relations between Separated Systems" Mathematical Proceedings of the Cambridge Philosophical Society (1935) \n' \ + '[turing1950computing] Turing, Alan M "Computing machinery and intelligence" Mind (1950) \n' \ + '[Bell_1964] Bell, J. S. "On the Einstein Podolsky Rosen paradox" Physics Physique физика (1964) \n' \ + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' \ + '[10.1371_journal.pone.0038236] Saunders, Caroline Lyon AND Chrystopher L. Nehaniv AND Joe "Interactive Language Learning by Robots: The Transition from Babbling to Word Forms" PLoS ONE (2012) \n' \ + '[10.1371_journal.pone.0063400] Ay, Georg Martius AND Ralf Der AND Nihat "Information Driven Self-Organization of Complex Robotic Behaviors" PLoS ONE (2013) \n' + correct = [ data_chrono_correct, + data_chrono_correct + '[Doe_noyear] Doe, John "About Assigning Timestamps to Research Articles" Journal Example \n' + ] + outs = self.execute_cmds(cmds) + self.assertEqual(outs[4], correct[0]) + self.assertEqual(outs[6], correct[1]) class TestTag(DataCommandTestCase):