mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibre-server nows runs on linux without requiring a X server
This commit is contained in:
parent
3011d1e002
commit
2c39eda812
@ -264,6 +264,14 @@ _check_symlinks_prescript()
|
|||||||
if os.path.exists(dst):
|
if os.path.exists(dst):
|
||||||
shutil.rmtree(dst)
|
shutil.rmtree(dst)
|
||||||
shutil.copytree('/usr/local/etc/fonts', dst, symlinks=False)
|
shutil.copytree('/usr/local/etc/fonts', dst, symlinks=False)
|
||||||
|
for x in os.listdir('/usr/local/etc/fonts'):
|
||||||
|
dst = os.path.join(frameworks_dir, x)
|
||||||
|
y = os.path.join('/usr/local/etc/fonts', x)
|
||||||
|
if os.path.isdir(dst):
|
||||||
|
if os.path.exists(dst): shutil.rmtree(dst)
|
||||||
|
shutil.copytree(y, dst)
|
||||||
|
else:
|
||||||
|
os.link(y, dst)
|
||||||
|
|
||||||
print
|
print
|
||||||
print 'Adding IPython'
|
print 'Adding IPython'
|
||||||
|
@ -63,9 +63,12 @@ def roman(num):
|
|||||||
def fmt_sidx(i, fmt='%.2f', use_roman=False):
|
def fmt_sidx(i, fmt='%.2f', use_roman=False):
|
||||||
if i is None:
|
if i is None:
|
||||||
i = 1
|
i = 1
|
||||||
if int(i) == i:
|
if int(i) == float(i):
|
||||||
return roman(i) if use_roman else '%d'%i
|
return roman(int(i)) if use_roman else '%d'%int(i)
|
||||||
return fmt%i
|
try:
|
||||||
|
return fmt%i
|
||||||
|
except TypeError:
|
||||||
|
return fmt%float(i)
|
||||||
|
|
||||||
|
|
||||||
class Resource(object):
|
class Resource(object):
|
||||||
|
@ -7,14 +7,18 @@ __docformat__ = 'restructuredtext en'
|
|||||||
HTTP server for remote access to the calibre database.
|
HTTP server for remote access to the calibre database.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys, textwrap, operator, os, re, logging
|
import sys, textwrap, operator, os, re, logging, cStringIO
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import cherrypy
|
import cherrypy
|
||||||
from PyQt4.Qt import QImage, QApplication, QByteArray, Qt, QBuffer
|
try:
|
||||||
|
from PIL import Image as PILImage
|
||||||
|
PILImage
|
||||||
|
except ImportError:
|
||||||
|
import Image as PILImage
|
||||||
|
|
||||||
from calibre.constants import __version__, __appname__
|
from calibre.constants import __version__, __appname__
|
||||||
from calibre.utils.genshi.template import MarkupTemplate
|
from calibre.utils.genshi.template import MarkupTemplate
|
||||||
@ -195,25 +199,21 @@ class LibraryServer(object):
|
|||||||
updated = datetime.utcfromtimestamp(os.stat(path).st_mtime) if path and os.access(path, os.R_OK) else build_time
|
updated = datetime.utcfromtimestamp(os.stat(path).st_mtime) if path and os.access(path, os.R_OK) else build_time
|
||||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
||||||
try:
|
try:
|
||||||
if QApplication.instance() is None:
|
f = cStringIO.StringIO(cover)
|
||||||
QApplication([])
|
try:
|
||||||
|
im = PILImage.open(f)
|
||||||
im = QImage()
|
except IOError:
|
||||||
im.loadFromData(cover)
|
|
||||||
if im.isNull():
|
|
||||||
raise cherrypy.HTTPError(404, 'No valid cover found')
|
raise cherrypy.HTTPError(404, 'No valid cover found')
|
||||||
width, height = im.width(), im.height()
|
width, height = im.size
|
||||||
scaled, width, height = fit_image(width, height,
|
scaled, width, height = fit_image(width, height,
|
||||||
60 if thumbnail else self.max_cover_width,
|
60 if thumbnail else self.max_cover_width,
|
||||||
80 if thumbnail else self.max_cover_height)
|
80 if thumbnail else self.max_cover_height)
|
||||||
if not scaled:
|
if not scaled:
|
||||||
return cover
|
return cover
|
||||||
im = im.scaled(width, height, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
im = im.resize((int(width), int(height)), PILImage.ANTIALIAS)
|
||||||
ba = QByteArray()
|
of = cStringIO.StringIO()
|
||||||
buf = QBuffer(ba)
|
im.convert('RGB').save(of, 'JPEG')
|
||||||
buf.open(QBuffer.WriteOnly)
|
return of.getvalue()
|
||||||
im.save(buf, 'PNG')
|
|
||||||
return str(ba.data())
|
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@ -294,7 +294,7 @@ class LibraryServer(object):
|
|||||||
series = record[FIELD_MAP['series']]
|
series = record[FIELD_MAP['series']]
|
||||||
if series:
|
if series:
|
||||||
extra.append('SERIES: %s [%s]<br />'%(series,
|
extra.append('SERIES: %s [%s]<br />'%(series,
|
||||||
fmt_sidx(record[FIELD_MAP['series_index']])))
|
fmt_sidx(float(record[FIELD_MAP['series_index']]))))
|
||||||
fmt = 'epub' if 'EPUB' in r else 'pdb'
|
fmt = 'epub' if 'EPUB' in r else 'pdb'
|
||||||
mimetype = guess_type('dummy.'+fmt)[0]
|
mimetype = guess_type('dummy.'+fmt)[0]
|
||||||
books.append(self.STANZA_ENTRY.generate(
|
books.append(self.STANZA_ENTRY.generate(
|
||||||
@ -343,7 +343,7 @@ class LibraryServer(object):
|
|||||||
for record in items[start:start+num]:
|
for record in items[start:start+num]:
|
||||||
aus = record[2] if record[2] else __builtins__._('Unknown')
|
aus = record[2] if record[2] else __builtins__._('Unknown')
|
||||||
authors = '|'.join([i.replace('|', ',') for i in aus.split(',')])
|
authors = '|'.join([i.replace('|', ',') for i in aus.split(',')])
|
||||||
r[10] = fmt_sidx(r[10])
|
record[10] = fmt_sidx(float(record[10]))
|
||||||
books.append(book.generate(r=record, authors=authors).render('xml').decode('utf-8'))
|
books.append(book.generate(r=record, authors=authors).render('xml').decode('utf-8'))
|
||||||
updated = self.db.last_modified()
|
updated = self.db.last_modified()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user