-
Notifications
You must be signed in to change notification settings - Fork 0
/
libris
executable file
·51 lines (38 loc) · 1.41 KB
/
libris
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- mode: python -*-
import os, sys, argparse, configparser
import add, bibtex, serve, edit_metadata, open_paper, edit_notes, rename, remove
import list_papers
def main():
rcfile = os.path.expanduser("~/.librisrc")
if not os.path.exists(rcfile):
sys.exit("Can't find config file ~/.librisrc")
config = configparser.ConfigParser()
parsed_files = config.read([rcfile])
if len(parsed_files) != 1:
sys.exit("Error parsing config file ~/.librisrc")
parser = argparse.ArgumentParser(description="dead simple research paper organization")
subparsers = parser.add_subparsers(title="valid commands", dest="command")
commands = {
"add" : add,
"bibtex" : bibtex,
"serve" : serve,
"edit_metadata" : edit_metadata,
"edit_notes" : edit_notes,
"open" : open_paper,
"rename" : rename,
"remove": remove,
"list" : list_papers
}
try:
for cmd_name, cmd_module in list(commands.items()):
subparser = cmd_module.parser(cmd_name, subparsers, config)
args = parser.parse_args()
args.config = config
chosen_command = args.command
del args.command
return commands[chosen_command].command(**vars(args))
except configparser.Error as e:
sys.exit("Missing config parameter(s): %s" % (e))
if __name__ == "__main__":
sys.exit(main())