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):
|
||||
shutil.rmtree(dst)
|
||||
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 'Adding IPython'
|
||||
|
@ -63,9 +63,12 @@ def roman(num):
|
||||
def fmt_sidx(i, fmt='%.2f', use_roman=False):
|
||||
if i is None:
|
||||
i = 1
|
||||
if int(i) == i:
|
||||
return roman(i) if use_roman else '%d'%i
|
||||
return fmt%i
|
||||
if int(i) == float(i):
|
||||
return roman(int(i)) if use_roman else '%d'%int(i)
|
||||
try:
|
||||
return fmt%i
|
||||
except TypeError:
|
||||
return fmt%float(i)
|
||||
|
||||
|
||||
class Resource(object):
|
||||
|
@ -7,14 +7,18 @@ __docformat__ = 'restructuredtext en'
|
||||
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 logging.handlers import RotatingFileHandler
|
||||
from datetime import datetime
|
||||
from threading import Thread
|
||||
|
||||
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.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
|
||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
||||
try:
|
||||
if QApplication.instance() is None:
|
||||
QApplication([])
|
||||
|
||||
im = QImage()
|
||||
im.loadFromData(cover)
|
||||
if im.isNull():
|
||||
f = cStringIO.StringIO(cover)
|
||||
try:
|
||||
im = PILImage.open(f)
|
||||
except IOError:
|
||||
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,
|
||||
60 if thumbnail else self.max_cover_width,
|
||||
80 if thumbnail else self.max_cover_height)
|
||||
if not scaled:
|
||||
return cover
|
||||
im = im.scaled(width, height, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
||||
ba = QByteArray()
|
||||
buf = QBuffer(ba)
|
||||
buf.open(QBuffer.WriteOnly)
|
||||
im.save(buf, 'PNG')
|
||||
return str(ba.data())
|
||||
im = im.resize((int(width), int(height)), PILImage.ANTIALIAS)
|
||||
of = cStringIO.StringIO()
|
||||
im.convert('RGB').save(of, 'JPEG')
|
||||
return of.getvalue()
|
||||
except Exception, err:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
@ -294,7 +294,7 @@ class LibraryServer(object):
|
||||
series = record[FIELD_MAP['series']]
|
||||
if 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'
|
||||
mimetype = guess_type('dummy.'+fmt)[0]
|
||||
books.append(self.STANZA_ENTRY.generate(
|
||||
@ -343,7 +343,7 @@ class LibraryServer(object):
|
||||
for record in items[start:start+num]:
|
||||
aus = record[2] if record[2] else __builtins__._('Unknown')
|
||||
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'))
|
||||
updated = self.db.last_modified()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user