Commit | Line | Data |
---|---|---|
f8775f9c FT |
1 | #!/usr/bin/python3 |
2 | ||
3 | import sys, os, getopt, ann | |
4 | ||
5 | def usage(out): | |
6 | out.write("usage:\tanndata -h\n") | |
7 | out.write("\tanndata -l PREFIX\n") | |
8 | out.write("\tanndata [-b] {-d|NAME}\n") | |
9 | ||
10 | opts, args = getopt.getopt(sys.argv[1:], "hl:bd") | |
11 | lsn = None | |
12 | browse = False | |
13 | here = False | |
14 | for o, a in opts: | |
15 | if o == "-h": | |
16 | usage(sys.stdout) | |
17 | sys.exit(0) | |
18 | elif o == "-l": | |
19 | lsn = a | |
20 | elif o == "-b": | |
21 | browse = True | |
22 | elif o == "-d": | |
23 | here = True | |
24 | ||
25 | if lsn is not None: | |
26 | for s in ann.getlist(lsn): | |
27 | sys.stdout.write("%s\n" % s.rawname) | |
28 | else: | |
29 | if here: | |
30 | nm = os.path.basename(os.getcwd) | |
31 | else: | |
32 | if len(args) < 1: | |
33 | usage(sys.stderr) | |
34 | sys.exit(1) | |
35 | nm = args[0] | |
36 | ls = ann.getlist(nm) | |
37 | if len(ls) < 1: | |
38 | sys.stderr.write("anndata: could not find %s\n" % nm) | |
39 | sys.exit(1) | |
40 | s = ls[0] | |
41 | if len(ls) > 1: | |
42 | sys.stderr.write("anndata: more than one match, using %s\n" % s.rawname) | |
43 | if browse: | |
44 | os.execlp("htmlview", "htmlview", s.url) | |
45 | else: | |
46 | sys.stdout.write("name: %s\n" % s.name) | |
47 | sys.stdout.write("vintage: %s\n" % s.vintage) | |
48 | sys.stdout.write("genres: %s\n" % ", ".join(s.genres)) | |
49 | sys.stdout.write("themes: %s\n" % ", ".join(s.themes)) |