I'm trying to tweak calibre-web (a Python web app using Flask) to allow using calibredb to process new books instead of it doing its own thing. The purpose is to allow uploading books that need certain plugins to be processed, like uploading a KePub file as KePub format. Why not just use calibre-server? calibre-web has the Kobo sync server and I really prefer doing things from one interface as much as possible.
- I have a test calibre library (created with the calibre GUI initially) at /home/jgoguen/calibre-library and a test config dir at /home/jgoguen/calibre-config I'm using for testing this out.
- I've set the environment variable CALIBRE_CONFIG_DIRECTORY=/home/jgoguen/calibre-config, and from within the Python script I can verify that's set correctly (both by inspecting os.environ and making subprocess.run() print the result of running "export" in a shell).
- No other calibre instance is running while I'm testing (normally I have calibre-server running, but using ~/.config/calibre as the config directory and "~/Documents/Calibre Library" as the library directory)
- From a shell, I can run 'calibredb add --library-path=/home/jgoguen/calibre-library test-book.epub' and see it get added to the test library path given (and calibredb prints out the ID of the new book).
- From a Python REPL, I can run calibredb via subprocess and also see it add the book:
Code:
>>> proc=subprocess.run(["/opt/calibre/calibredb", "add", "--library-path=/home/jgoguen/calibre-library", "/home/jgoguen/test-book.epub"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
>>> proc.returncode
0
>>> print(proc.stdout)
Added book ids: 8
proc.stderr here is empty. However, from within the Python code of calibre-web, that exact same subprocess call (whether exact copy/paste or using the appropriate variables in calibre-web, and same result if I pass "shell=True" to subprocess.run()) "succeeds" with return code 0 but calibredb fails as if I called calibredb with no arguments.
Code:
Usage: calibredb command [options] [arguments]
calibredb is the command line interface to the calibre books database.
command is one of:
list
add
...
As with the Python REPL, that's on STDOUT and STDERR is empty.
Is there some way I can better debug what's happening here? Or is there something else I need to do to make calibredb work when called from a Python web app? Or maybe there's something stupid I'm doing wrong here?