Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 11-05-2013, 04:49 AM   #16
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Here's a one liner:

Code:
calibre-debug -c "import urllib as u; from calibre.constants import numeric_version; raise SystemExit(int(numeric_version < (tuple(map(int, u.urlopen('http://calibre-ebook.com/downloads/latest_version').read().split('.'))))))"
kovidgoyal is offline   Reply With Quote
Old 11-05-2013, 04:52 AM   #17
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
Good to know, thanks!

I'd put that in a -c one-liner, but sys.exit() seems to hiccup when used that way. I'll find a way.

Code:
#!/usr/bin/env python
## -*- coding: utf-8 -*-
import urllib as u
from calibre.constants import numeric_version

if numeric_version < tuple(map(int, u.urlopen('http://calibre-ebook.com/downloads/latest_version').read()[:-1].split("."))):
        sys.exit(0)
else:
        sys.exit(1)
aleyx is offline   Reply With Quote
Old 11-11-2013, 02:29 PM   #18
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
Seems like calibre-debug returns 0 regardless of the way the script (or -c command) exits. All of those return 0:

Code:
aleyx@grey:~/bin$ calibre-debug -c "sys.exit(1)"; echo $?
0
aleyx@grey:~/bin$ calibre-debug -c "sys.exit(0)"; echo $?
0
aleyx@grey:~/bin$ calibre-debug -c "raise SystemExit(0)"; echo $?
0
aleyx@grey:~/bin$ calibre-debug -c "raise SystemExit(1)"; echo $?
0
So my calibre-check.py becomes:

Code:
#!/usr/bin/env python
## -*- coding: utf-8 -*-
import urllib as u
from calibre.constants import numeric_version

if numeric_version < tuple(map(int, u.urlopen('http://calibre-ebook.com/downloads/latest_version').read()[:-1].split("."))):
        print "obsolete"
        raise SystemExit(1)
else:
        print "up-to-date"
        raise SystemExit(0)
And calibre-update.sh becomes:
Code:
#!/bin/bash
if calibre-debug $HOME/bin/calibre-check.py | grep -q "obsolete"; then
        killall calibre-server
        sudo python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.cali
bre-ebook.com/linux_installer').read()); main(install_dir='/opt')"
        $HOME/bin/calibre-server.sh
else
        echo "Calibre is up-to-date"
fi
Seems to work so far.

EDIT: newer version of update code here

Last edited by aleyx; 11-19-2013 at 04:57 PM.
aleyx is offline   Reply With Quote
Old 11-11-2013, 09:42 PM   #19
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Works for me:

Code:
calibre-debug -c "raise SystemExit(127)"; echo $?
127
kovidgoyal is offline   Reply With Quote
Old 11-12-2013, 03:21 AM   #20
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
There must be something wrong with my setup then, because I get 0 for that one as well.

Strange, and therefore interesting. I'll have to look deeper into this.
aleyx is offline   Reply With Quote
Old 11-12-2013, 05:39 AM   #21
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It might be that the binary linux build doesn't handle exit codes in this situation. The binary builds are not vanilla python but python inside a C wrapper program and it may be that the wrapper program only reports error codes if no exception is raised. Although it should be reporting the error code as 1 not 0 when raising an exception. What happens if you raise a normal exception (not SystemExit)?
kovidgoyal is offline   Reply With Quote
Old 11-12-2013, 05:42 AM   #22
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You can also try doing os._exit(code) which will bypass the machinery associated with python sgutdown.
kovidgoyal is offline   Reply With Quote
Old 11-12-2013, 05:51 AM   #23
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Here's a fix for the binary build not handing SystemExit correctly. https://github.com/kovidgoyal/calibr...f473326a41e38e
kovidgoyal is offline   Reply With Quote
Old 11-19-2013, 01:25 PM   #24
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
Following v1.11.0, here's the corrected calibre-update.sh:
Code:
#!/bin/bash

calibre-debug -c "import urllib as u; from calibre.constants import numeric_version; raise SystemExit(int(numeric_version  < (tuple(map(int, u.urlopen('http://calibre-ebook.com/downloads/latest_version').read().split('.'))))))"

UP_TO_DATE=$?

if [ $UP_TO_DATE = 0 ]; then
        echo "Calibre is up-to-date"
else
        killall calibre-server
        $HOME/bin/calibre-backup.sh
        sudo python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.calibre-ebook.com/linux_installer').read()); main(install_dir='/opt')"
        $HOME/bin/calibre-server.sh
fi
With Kovid's one-liner for the check, the separate calibre-check.py file is now unnecessary.

Should I go back in my previous posts and remove the obsolete versions? I usually hate to delete code when there's no version control (yeah, even little snippets like those; code is code), but I don't really know if there's a policy here regarding code obsolescence.
aleyx is offline   Reply With Quote
Old 11-19-2013, 02:58 PM   #25
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Just make a note:

EDIT: newer version of update code here.

Thanks for the update.
eschwartz is offline   Reply With Quote
Old 11-19-2013, 05:01 PM   #26
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
Quote:
Originally Posted by eschwartz View Post
Just make a note:

EDIT: newer version of update code here.
Thanks, I'll do that.
Quote:
Originally Posted by eschwartz View Post
Thanks for the update.
You're welcome ^^
aleyx is offline   Reply With Quote
Old 01-31-2014, 10:42 AM   #27
Geremia
Addict
Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!
 
Posts: 258
Karma: 100000
Join Date: Oct 2012
Device: Calibre
I get this error:
Code:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 356, in main
  File "<string>", line 192, in prints
TypeError: encode() argument 1 must be string, not None

Last edited by Geremia; 01-31-2014 at 10:48 AM.
Geremia is offline   Reply With Quote
Old 01-31-2014, 11:51 AM   #28
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
Do you run the code posted here?

If not, what command do you run?
aleyx is offline   Reply With Quote
Old 01-31-2014, 12:21 PM   #29
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
I know the answer to this one!

Quote:
Originally Posted by eschwartz View Post
And Kovid fixed that. See here: Official calibre PPA? where we discussed updating via a script using that check.

This thread also has a nice elegant way of checking if there is an update available -- Kovid helped us thrash it out.

Here it is:

Code:
#!/bin/bash

calibre-debug -c "import urllib as u; from calibre.constants import numeric_version; raise SystemExit(int(numeric_version  < (tuple(map(int, u.urlopen('http://calibre-ebook.com/downloads/latest_version').read().split('.'))))))"

UP_TO_DATE=$?

if [ $UP_TO_DATE = 0 ]; then
        echo "Calibre is up-to-date"
else
        killall calibre calibre-server
        sudo python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.calibre-ebook.com/linux_installer').read()); main(install_dir='/opt')"
fi
Quote:
Originally Posted by Geremia View Post
Wow, thanks for that, but I get this error:
Code:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 356, in main
  File "<string>", line 192, in prints
TypeError: encode() argument 1 must be string, not None
eschwartz is offline   Reply With Quote
Old 02-07-2014, 04:35 PM   #30
Geremia
Addict
Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!Geremia rocks like Gibraltar!
 
Posts: 258
Karma: 100000
Join Date: Oct 2012
Device: Calibre
Quote:
Originally Posted by aleyx View Post
Do you run the code posted here?
Yes, exactly that code

Of course, I only get this problem when Calibre isn't up-to-date, so the script does successfully detect Calibre is up-to-date.

Last edited by Geremia; 02-07-2014 at 04:38 PM.
Geremia is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
0.7 Linux Ubuntu ppa dicknskip Sigil 21 04-20-2013 04:29 AM
Official Calibre ereader app for mobile devices? mcandre Calibre 15 12-18-2012 03:27 PM
New official covers gers1978 Amazon Kindle 20 10-07-2011 11:15 AM
Firmware Update 3.0.2 is official mrzerga Amazon Kindle 33 10-23-2010 07:32 AM
It's Official BuddyBoy Sony Reader 9 11-09-2006 05:21 PM


All times are GMT -4. The time now is 10:09 PM.


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