|
|
#16 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,608
Karma: 28548974
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('.'))))))"
|
|
|
|
|
|
#17 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
|
|
|
|
|
#18 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 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)
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
EDIT: newer version of update code here Last edited by aleyx; 11-19-2013 at 04:57 PM. |
|
|
|
|
|
#19 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,608
Karma: 28548974
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Works for me:
Code:
calibre-debug -c "raise SystemExit(127)"; echo $? 127 |
|
|
|
|
|
#20 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
|
|
|
|
|
#21 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,608
Karma: 28548974
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)?
|
|
|
|
|
|
#22 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,608
Karma: 28548974
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.
|
|
|
|
|
|
#23 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,608
Karma: 28548974
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
|
|
|
|
|
|
#24 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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
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. |
|
|
|
|
|
#26 | |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
|
Quote:
You're welcome ^^ |
|
|
|
|
|
|
#27 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 262
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. |
|
|
|
|
|
#29 | |
|
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
|
|
|
|
|
|
|
#30 | |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 262
Karma: 100000
Join Date: Oct 2012
Device: Calibre
|
Quote:
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. |
|
|
|
|
![]() |
|
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 |