Adds config file.

main
Olivier Mangin 12 years ago
parent 5bfe827b7e
commit da7fa55d19

@ -4,18 +4,22 @@ from .. import color
from .. import repo from .. import repo
from ..paper import NoDocumentFile from ..paper import NoDocumentFile
def parser(subparsers, config): def parser(subparsers, config):
parser = subparsers.add_parser('open', help='{}open the paper in a pdf viewer{}'.format(color.normal, color.end)) parser = subparsers.add_parser('open', help='{}open the paper in a pdf viewer{}'.format(color.normal, color.end))
parser.add_argument('citekey', help='{}the paper associated citekey{}'.format(color.normal, color.end)) parser.add_argument('citekey', help='{}the paper associated citekey{}'.format(color.normal, color.end))
return parser return parser
def command(config, citekey): def command(config, citekey):
print config.get('papers', 'open-cmd')
rp = repo.Repository.from_directory() rp = repo.Repository.from_directory()
paper = rp.paper_from_any(citekey, fatal=True) paper = rp.paper_from_any(citekey, fatal=True)
try: try:
if paper.check_file(): if paper.check_file():
filepath = paper.get_file_path() filepath = paper.get_file_path()
subprocess.Popen(['open', filepath]) subprocess.Popen([config.get('papers', 'open-cmd'),
filepath])
print('{}{}{} opened.{}'.format( print('{}{}{} opened.{}'.format(
color.filepath, filepath, color.normal, color.end)) color.filepath, filepath, color.normal, color.end))
else: else:

@ -1,8 +1,12 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import os
import argparse import argparse
import collections import collections
import ConfigParser
from papers import commands from papers import commands
@ -15,7 +19,11 @@ cmds = collections.OrderedDict([
('websearch', commands.websearch_cmd) ('websearch', commands.websearch_cmd)
]) ])
config = None config = ConfigParser.SafeConfigParser()
config.add_section('papers')
config.set('papers', 'open-cmd', 'open')
config.set('papers', 'edit-cmd', 'vim')
config.read(os.path.expanduser('~/.papersrc'))
parser = argparse.ArgumentParser(description="research papers repository") parser = argparse.ArgumentParser(description="research papers repository")
subparsers = parser.add_subparsers(title="valid commands", dest="command") subparsers = parser.add_subparsers(title="valid commands", dest="command")

Loading…
Cancel
Save