From 94e6dccac910d4074a8052434e4fab8a76880118 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Tue, 28 Aug 2018 17:20:29 +0900 Subject: [PATCH 1/4] doc extension visible in pubs list --- pubs/pretty.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pubs/pretty.py b/pubs/pretty.py index 9e8c82c..10de342 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import os import re from . import color @@ -64,8 +65,12 @@ def paper_oneliner(p, citekey_only=False): return p.citekey else: bibdesc = bib_oneliner(p.bibdata) - tags = '' if len(p.tags) == 0 else '| {}'.format( + doc_str = '' + if p.docpath is not None: + doc_str = color.dye_out(' [{}]'.format(os.path.splitext(p.docpath)[1][1:]), + 'tag') + tags = '' if len(p.tags) == 0 else ' | {}'.format( ','.join(color.dye_out(t, 'tag') for t in sorted(p.tags))) - return '[{citekey}] {descr} {tags}'.format( + return '[{citekey}] {descr}{doc}{tags}'.format( citekey=color.dye_out(p.citekey, 'citekey'), - descr=bibdesc, tags=tags) + descr=bibdesc, tags=tags, doc=doc_str) From 49e6c7d9c2100eb824edb44e06f61c1425e9ae31 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Tue, 28 Aug 2018 17:37:35 +0900 Subject: [PATCH 2/4] update tests --- pubs/pretty.py | 4 ++-- tests/test_usecase.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pubs/pretty.py b/pubs/pretty.py index 10de342..226a11e 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -69,8 +69,8 @@ def paper_oneliner(p, citekey_only=False): if p.docpath is not None: doc_str = color.dye_out(' [{}]'.format(os.path.splitext(p.docpath)[1][1:]), 'tag') - tags = '' if len(p.tags) == 0 else ' | {}'.format( + tags = '' if len(p.tags) == 0 else '| {}'.format( ','.join(color.dye_out(t, 'tag') for t in sorted(p.tags))) - return '[{citekey}] {descr}{doc}{tags}'.format( + return '[{citekey}] {descr}{doc} {tags}'.format( citekey=color.dye_out(p.citekey, 'citekey'), descr=bibdesc, tags=tags, doc=doc_str) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 43083cd..3654985 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -669,12 +669,12 @@ class TestUsecase(DataCommandTestCase): correct = ['Initializing pubs in /paper_first\n', 'added to pubs:\n[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' 'data/pagerank.pdf was copied to the pubs repository.\n', - '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n', + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) [pdf] \n', '\n', '', 'network search\n', 'info: Assuming search to be a tag.\n' - '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) | network,search\n', + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) [pdf] | network,search\n', ] cmds = ['pubs init -p /paper_first', From da70d3c3811b30ed292e9a73eae63817002a04f1 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Wed, 26 Sep 2018 22:44:48 -0700 Subject: [PATCH 3/4] Handles listing papers with documents without extension. --- pubs/pretty.py | 7 +++++-- tests/test_usecase.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pubs/pretty.py b/pubs/pretty.py index 226a11e..645ef02 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -67,8 +67,11 @@ def paper_oneliner(p, citekey_only=False): bibdesc = bib_oneliner(p.bibdata) doc_str = '' if p.docpath is not None: - doc_str = color.dye_out(' [{}]'.format(os.path.splitext(p.docpath)[1][1:]), - 'tag') + doc_extension = os.path.splitext(p.docpath)[1] + doc_str = color.dye_out( + ' [{}]'.format(doc_extension[1:] if len(doc_extension) > 1 + else 'NOEXT'), + 'tag') tags = '' if len(p.tags) == 0 else '| {}'.format( ','.join(color.dye_out(t, 'tag') for t in sorted(p.tags))) return '[{citekey}] {descr}{doc} {tags}'.format( diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 3654985..a1ab146 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -1001,6 +1001,24 @@ class TestUsecase(DataCommandTestCase): self.assertEqual(lines[1], 'Total papers: 4, 1 (25%) have a document attached') self.assertEqual(lines[2], 'Total tags: 3, 2 (50%) of papers have at least one tag') + def test_add_no_extension(self): + # This tests checks that a paper which document has no + # extension does not raise issues when listing. This test might + # be removed if decided to prevent such documents. It would then need + # to be replaced by a check that this is prevented. + self.fs.add_real_file(os.path.join(self.rootpath, 'data', 'pagerank.pdf'), + target_path=os.path.join('data', 'no-ext')) + correct = ['Initializing pubs in /pubs\n', + 'added to pubs:\n[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' + 'data/no-ext was copied to the pubs repository.\n', + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) [NOEXT] \n', + ] + cmds = ['pubs init -p /pubs', + 'pubs add -d data/no-ext data/pagerank.bib', + 'pubs list', + ] + self.assertEqual(correct, self.execute_cmds(cmds, capture_output=True)) + @ddt.ddt class TestCache(DataCommandTestCase): From 24ac3bf452b25fb8fef469ab93744e13267ec6d5 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Wed, 26 Sep 2018 23:36:06 -0700 Subject: [PATCH 4/4] Adds changelog for #168. --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 25cc181..f3e3036 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,8 @@ ### Implemented enhancements +- [(#45)](https://github.com/pubs/pubs/issues/45) Doc extension visible in pubs list ([#168](https://github.com/pubs/pubs/pull/168)) + ### Fixed bugs