From: Fredrik Tolf Date: Wed, 25 Dec 2019 21:50:21 +0000 (+0100) Subject: anndata: Replaced with new Python version. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=f8775f9c59566ff6c5d90f04f471f0bcbf2316d7;p=utils.git anndata: Replaced with new Python version. --- diff --git a/anndata b/anndata index 7ed3e13..76b88a0 100755 --- a/anndata +++ b/anndata @@ -1,70 +1,49 @@ -#!/usr/bin/perl -w - -use Getopt::Long; -use Anime::ANN; - -binmode STDOUT, ":utf8"; -GetOptions(\%options, "l=s", "b=s", "d") || exit 1; - -if($options{"l"}) { - @list = Anime::ANN::getlist($options{"l"}); - foreach $name (@list) { - print "$name\n"; - } - exit 0; -} - -$browse = ""; -if($options{"b"}) { - $browse = $options{"b"}; -} elsif($options{"d"}) { - $browse = `basename "\$(pwd)"`; -} -if($browse) { - $id = Anime::ANN::getid $browse; - if(defined($id)) { - exec "htmlview", Anime::ANN::geturl($id); - } else { - printf STDERR "could not find " . $browse . "\n"; - exit 1; - } -} - -if(!defined($ARGV[0])) { - printf STDERR "usage: anndata NAME\n"; - exit 1; -} - -unless($id = Anime::ANN::getid $ARGV[0]) { - printf STDERR "could not find $ARGV[0]\n"; - exit 1; -} - -$info = Anime::ANN::getseries $id; - -sub refdump -{ - my($ref, $ind); - ($ref, $ind) = @_; - if(!defined($ind)) { - $ind = 0; - } - - if(ref $ref eq "HASH") { - for $key (sort keys %{$ref}) { - print ((" " x $ind) . "$key: " . (" " x (20 - length $key)) . "(" . $ref->{$key} . ")\n"); - refdump($ref->{$key}, $ind + 1) if ref $ref->{$key}; - } - } elsif(ref $ref eq "ARRAY") { - for($i = 0; $i < @{$ref}; $i++) { - print ((" " x $ind) . "$i: " . $ref->[$i] . "\n"); - refdump($ref->[$i], $ind + 1) if ref $ref->[$i]; - } - } elsif(ref $ref eq "SCALAR") { - print ((" " x $ind) . $$ref . "\n"); - } else { - print ((" " x $ind) . "Unknown ref: $ref\n"); - } -} - -refdump $info; +#!/usr/bin/python3 + +import sys, os, getopt, ann + +def usage(out): + out.write("usage:\tanndata -h\n") + out.write("\tanndata -l PREFIX\n") + out.write("\tanndata [-b] {-d|NAME}\n") + +opts, args = getopt.getopt(sys.argv[1:], "hl:bd") +lsn = None +browse = False +here = False +for o, a in opts: + if o == "-h": + usage(sys.stdout) + sys.exit(0) + elif o == "-l": + lsn = a + elif o == "-b": + browse = True + elif o == "-d": + here = True + +if lsn is not None: + for s in ann.getlist(lsn): + sys.stdout.write("%s\n" % s.rawname) +else: + if here: + nm = os.path.basename(os.getcwd) + else: + if len(args) < 1: + usage(sys.stderr) + sys.exit(1) + nm = args[0] + ls = ann.getlist(nm) + if len(ls) < 1: + sys.stderr.write("anndata: could not find %s\n" % nm) + sys.exit(1) + s = ls[0] + if len(ls) > 1: + sys.stderr.write("anndata: more than one match, using %s\n" % s.rawname) + if browse: + os.execlp("htmlview", "htmlview", s.url) + else: + sys.stdout.write("name: %s\n" % s.name) + sys.stdout.write("vintage: %s\n" % s.vintage) + sys.stdout.write("genres: %s\n" % ", ".join(s.genres)) + sys.stdout.write("themes: %s\n" % ", ".join(s.themes))