Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 06-26-2024, 02:02 PM   #1
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
Execute calibredb from Python code?

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?
jgoguen is offline   Reply With Quote
Old 06-26-2024, 06:35 PM   #2
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
I have absolutely no idea what I may have changed, but suddenly it's working exactly as expected.
jgoguen is offline   Reply With Quote
Advert
Old 06-26-2024, 08:35 PM   #3
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 40,506
Karma: 156983616
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Ahhh! Another I don't believe in miracles, I just depend on them moment.
DNSB is offline   Reply With Quote
Old 06-26-2024, 08:43 PM   #4
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
Half the time programming is staring at code wondering why it doesn’t work, the other half is wondering how it does work ��
jgoguen is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting ePub Python coding books to PDF outputs Python code far too small lysakowski Conversion 9 04-30-2023 06:44 AM
'calibredb add' throws python error when calibre-server is running CubGeek Server 2 09-17-2021 12:01 PM
How to debug calibredb error using Python tools? plo233 Development 1 07-01-2019 01:39 PM
Python error when accessing content server with calibredb drawson1 Library Management 1 06-19-2018 01:08 PM
Security Researcher Demoes Bug To Execute Unsigned Code on iOS Devices kjk Apple Devices 0 11-07-2011 08:09 PM


All times are GMT -4. The time now is 03:07 PM.


MobileRead.com is a privately owned, operated and funded community.