#!/usr/bin/python3
-import sys, getopt
+import sys, getopt, pathlib
import manga.lib, manga.reader, manga.profile, manga.local
from gi.repository import Gtk, Gdk, GObject
-GObject.threads_init()
-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")
+ out.write(" automanga -L TAG [-o ORDER]\n")
libname = None
search = None
alias = None
settags = False
listtag = None
-opts, args = getopt.getopt(sys.argv[1:], "hl:sSp:a:tL:")
+listorder = None
+opts, args = getopt.getopt(sys.argv[1:], "hl:sSp:a:tL:o:")
for o, a in opts:
if o == "-h":
usage(sys.stdout)
settags = True
elif o == "-L":
listtag = a
+ elif o == "-o":
+ listorder = a
if profile == "":
try:
profile = manga.profile.profile.last()
if listtag is not None:
if profile is not None:
+ results = []
for mprof in profile.bytag(listtag):
try:
mng = mprof.open()
except KeyError:
sys.stderr.write("%s %s: no longer found\n" % (mprof.libnm, mprof.id))
continue
- sys.stdout.write("%s %s: \"%s\"\n" % (mprof.libnm, mprof.id, mng.name))
+ except Exception as exc:
+ sys.stderr.write("%s %s: unexpected error: %s\n" % (mprof.libnm, mprof.id, str(exc)))
+ continue
+ line = "%s %s: \"%s\"" % (mprof.libnm, mprof.id, mng.name)
+ if listorder is None:
+ sys.stdout.write("%s\n" % (line,))
+ else:
+ if listorder == "mtime":
+ key = -mprof.mtime()
+ else:
+ sys.stderr.write("automanga: undefined order: %s\n" % (listorder,))
+ sys.exit(1)
+ results.append((line, key))
+ if len(results) > 0:
+ results.sort(key=lambda o: o[1])
+ for line, key in results:
+ sys.stdout.write("%s\n" % (line,))
return
if alias and (alias.find('=') > 0):
else:
libname = "local"
try:
- if len(args) > 0:
- mdir = args.pop(0)
- else:
- mdir = "."
- mng = manga.local.manga(mdir)
+ if len(args) < 1:
+ usage(sys.stderr)
+ sys.exit(1)
+ mdir = args.pop(0)
+ mng = manga.local.manga(pathlib.Path(mdir))
except TypeError:
sys.stderr.write("automanga: not a valid manga directory: %s\n" % mdir)
sys.exit(1)