From 5c000565c156ae32de0480e83d98f12e65f14f03 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 2 Dec 2013 02:03:35 +0100 Subject: [PATCH] Added argument syntax for automanga to edit and list tags. --- automanga | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/automanga b/automanga index e581b74..8fad817 100755 --- a/automanga +++ b/automanga @@ -10,13 +10,17 @@ gtk.gdk.threads_init() def usage(out): out.write("usage: automanga [-h] [-p PROFILE] {DIRECTORY|-l LIBRARY ID|-a ALIAS}\n") out.write(" automanga -a ALIAS=LIBRARY:ID\n") + out.write(" automanga -t {DIRECTORY|-l LIBRARY ID|-a ALIAS} [-]TAG...\n") out.write(" automanga -{s|S} LIBRARY NAME\n") + out.write(" automanga -L TAG\n") libname = None search = None profile = "" alias = None -opts, args = getopt.getopt(sys.argv[1:], "hl:sSp:a:") +settags = False +listtag = None +opts, args = getopt.getopt(sys.argv[1:], "hl:sSp:a:tL:") for o, a in opts: if o == "-h": usage(sys.stdout) @@ -34,6 +38,10 @@ for o, a in opts: profile = None else: profile = a + elif o == "-t": + settags = True + elif o == "-L": + listtag = a if profile == "": try: profile = manga.profile.profile.last() @@ -68,6 +76,13 @@ def main(): sys.stdout.write("\"%s\": %s\n" % (mng.name, mng.id)) return + if listtag is not None: + if profile is not None: + for mprof in profile.bytag(listtag): + mng = mprof.open() + sys.stdout.write("%s %s: \"%s\"\n" % (mprof.libnm, mprof.id, mng.name)) + return + if alias and (alias.find('=') > 0): tgt, nm = alias.split('=', 1) if not ':' in nm: @@ -113,7 +128,7 @@ def main(): sys.stderr.write("automanga: no such library: %s\n" % libname) sys.exit(1) try: - mng = lib.byid(args[0]) + mng = lib.byid(args.pop(0)) except KeyError as e: sys.stderr.write("automanga: no such manga: %s\n" % str(e)) sys.exit(1) @@ -121,7 +136,7 @@ def main(): libname = "local" try: if len(args) > 0: - mdir = args[0] + mdir = args.pop(0) else: mdir = "." mng = manga.local.manga(mdir) @@ -133,6 +148,15 @@ def main(): if profile is not None: profile.setlast() + if settags: + if mprof is not None: + ntags = [tag for tag in args if tag[:1] != "-"] + rtags = [tag[1:] for tag in args if tag[:1] == "-"] + print ntags, rtags + if ntags: mprof.tags.add(*ntags) + if rtags: mprof.tags.remove(*rtags) + return + reader = manga.reader.reader(mng, mprof) reader.show() gtk.main() -- 2.11.0