diff --git a/papers/commands/add_cmd.py b/papers/commands/add_cmd.py index 1b32e5b..64cf355 100644 --- a/papers/commands/add_cmd.py +++ b/papers/commands/add_cmd.py @@ -1,11 +1,12 @@ -from .. import color -from .. import files - +import os try: import ConfigParser as configparser except ImportError: import configparser +from .. import color +from .. import files +from .. import pretty def parser(subparsers, config): @@ -23,7 +24,7 @@ def command(config, pdffile, bibfile): papersdir = files.find_papersdir() fullpdfpath = os.path.abspath(pdffile) - fullbibpath = os.path.abspath(bibtex) + fullbibpath = os.path.abspath(bibfile) files.check_file(fullpdfpath) files.check_file(fullbibpath) @@ -41,12 +42,12 @@ def command(config, pdffile, bibfile): meta.add_section('notes') - if bibtex is not None: + if bibfile is not None: bib_data = files.load_externalbibfile(fullbibpath) print('{}bibliographic data present in {}{}{}'.format( - color.grey, color.cyan, bibtex, color.end)) - print(bib_desc(bib_data)) - files.write_bibfile(bib_data, filename) + color.grey, color.cyan, bibfile, color.end)) + print(pretty.bib_desc(bib_data)) + files.write_bibdata(bib_data, filename) papers = files.read_papers() count = papers.get('header', 'count') diff --git a/papers/commands/init_cmd.py b/papers/commands/init_cmd.py index 22ddf3d..fb9b9d5 100644 --- a/papers/commands/init_cmd.py +++ b/papers/commands/init_cmd.py @@ -1,5 +1,6 @@ # init command +import os try: import ConfigParser as configparser except ImportError: diff --git a/papers/commands/open_cmd.py b/papers/commands/open_cmd.py index 450d2fa..d01f376 100644 --- a/papers/commands/open_cmd.py +++ b/papers/commands/open_cmd.py @@ -1,8 +1,12 @@ +try: + import ConfigParser as configparser +except ImportError: + import configparser +import subprocess + from .. import files from .. import color -import subprocess - def parser(subparsers, config): parser = subparsers.add_parser('open', help="open the paper in a pdf viewer") parser.add_argument("citekey", help="the paper associated citekey") @@ -10,7 +14,12 @@ def parser(subparsers, config): def command(config, citekey): papers = files.read_papers() - filename = papers.get('papers', 'p' + str(citekey)) + try: + filename = papers.get('papers', 'p' + str(citekey)) + except configparser.NoOptionError: + print('{}error{}: paper with citekey {}{}{} not found{}'.format( + color.red, color.grey, color.cyan, citekey, color.grey, color.end)) + exit(-1) meta_data = files.load_meta(filename) filepath = meta_data.get('metadata', 'path') p = subprocess.Popen(['open', filepath]) diff --git a/tests/data/pagerank.bib b/tests/data/pagerank.bib new file mode 100644 index 0000000..f4e7806 --- /dev/null +++ b/tests/data/pagerank.bib @@ -0,0 +1,14 @@ +@techreport{ilprints422, + 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/}, + abstract = {The importance of a Web page is an inherently subjective matter, which depends on the readers interests, knowledge and attitudes. But there is still much that can be said objectively about the relative importance of Web pages. This paper describes PageRank, a mathod for rating Web pages objectively and mechanically, effectively measuring the human interest and attention devoted to them. We compare PageRank to an idealized random Web surfer. We show how to efficiently compute PageRank for large numbers of pages. And, we show how to apply PageRank to search and to user navigation.} +} + diff --git a/tests/data/pagerank.pdf b/tests/data/pagerank.pdf new file mode 100644 index 0000000..0523ae0 Binary files /dev/null and b/tests/data/pagerank.pdf differ diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..86d53cb --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +papers init; +papers list; +papers add data/pagerank.pdf data/pagerank.bib; +papers list; +papers open 0; +rm -Rf .papers; \ No newline at end of file