mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge from trunk
This commit is contained in:
commit
479ec4ab65
@ -385,6 +385,14 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
fname = sanitize(fname)
|
||||
ext = os.path.splitext(fname)[1]
|
||||
|
||||
try:
|
||||
# If the device asked for it, try to use the UUID as the file name.
|
||||
# Fall back to the template if the UUID doesn't exist.
|
||||
if self.client_wants_uuid_file_names and mdata.uuid:
|
||||
return (mdata.uuid + ext)
|
||||
except:
|
||||
pass
|
||||
|
||||
maxlen = (self.MAX_PATH_LEN - (self.PATH_FUDGE_FACTOR +
|
||||
self.exts_path_lengths.get(ext, self.PATH_FUDGE_FACTOR)))
|
||||
|
||||
@ -845,6 +853,10 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
self._close_device_socket()
|
||||
return False
|
||||
|
||||
self.client_wants_uuid_file_names = result.get('useUuidFileNames', False)
|
||||
self._debug('Device wants UUID file names', self.client_wants_uuid_file_names)
|
||||
|
||||
|
||||
config = self._configProxy()
|
||||
config['format_map'] = exts
|
||||
self._debug('selected formats', config['format_map'])
|
||||
@ -1253,6 +1265,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
self.connection_attempts = {}
|
||||
self.client_can_stream_books = False
|
||||
self.client_can_stream_metadata = False
|
||||
self.client_wants_uuid_file_names = False
|
||||
|
||||
self._debug("All IP addresses", get_all_ips())
|
||||
|
||||
|
@ -291,6 +291,8 @@ def set_metadata(stream, mi, apply_null=False, update_timestamp=False):
|
||||
|
||||
|
||||
reader.opf.smart_update(mi)
|
||||
if getattr(mi, 'uuid', None):
|
||||
reader.opf.application_id = mi.uuid
|
||||
if apply_null:
|
||||
if not getattr(mi, 'series', None):
|
||||
reader.opf.series = None
|
||||
|
@ -941,12 +941,11 @@ class OPF(object): # {{{
|
||||
return self.get_text(match) or None
|
||||
|
||||
def fset(self, val):
|
||||
matches = self.application_id_path(self.metadata)
|
||||
if not matches:
|
||||
for x in tuple(self.application_id_path(self.metadata)):
|
||||
x.getparent().remove(x)
|
||||
attrib = {'{%s}scheme'%self.NAMESPACES['opf']: 'calibre'}
|
||||
matches = [self.create_metadata_element('identifier',
|
||||
attrib=attrib)]
|
||||
self.set_text(matches[0], unicode(val))
|
||||
self.set_text(self.create_metadata_element(
|
||||
'identifier', attrib=attrib), unicode(val))
|
||||
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
|
@ -117,6 +117,9 @@ class MergeMetadata(object):
|
||||
self.oeb.metadata.add('identifier', mi.uuid, id='uuid_id',
|
||||
scheme='uuid')
|
||||
self.oeb.uid = self.oeb.metadata.identifier[-1]
|
||||
if mi.application_id is not None:
|
||||
m.filter('identifier', lambda x:x.scheme=='calibre')
|
||||
self.oeb.metadata.add('identifier', mi.application_id, scheme='calibre')
|
||||
|
||||
def set_cover(self, mi, prefer_metadata_cover):
|
||||
cdata, ext = '', 'jpg'
|
||||
|
@ -26,6 +26,7 @@ def create_opf_file(db, book_id):
|
||||
mi.application_id = uuid.uuid4()
|
||||
old_cover = mi.cover
|
||||
mi.cover = None
|
||||
mi.application_id = mi.uuid
|
||||
raw = metadata_to_opf(mi)
|
||||
mi.cover = old_cover
|
||||
opf_file = PersistentTemporaryFile('.opf')
|
||||
|
@ -133,8 +133,8 @@ class CSV_XML(CatalogPlugin):
|
||||
elif field in ['authors', 'tags']:
|
||||
item = ', '.join(item)
|
||||
elif field == 'isbn':
|
||||
# Could be 9, 10 or 13 digits
|
||||
item = u'%s' % re.sub(r'[\D]', '', item)
|
||||
# Could be 9, 10 or 13 digits, with hyphens, possibly ending in 'X'
|
||||
item = u'%s' % re.sub(r'[^\dX-]', '', item)
|
||||
elif field in ['pubdate', 'timestamp']:
|
||||
item = isoformat(item)
|
||||
elif field == 'comments':
|
||||
|
@ -239,6 +239,8 @@ class BrowseServer(object):
|
||||
self.browse_details)
|
||||
connect('browse_book', base_href+'/book/{id}',
|
||||
self.browse_book)
|
||||
connect('browse_random', base_href+'/random',
|
||||
self.browse_random)
|
||||
connect('browse_category_icon', base_href+'/icon/{name}',
|
||||
self.browse_icon)
|
||||
|
||||
@ -351,6 +353,7 @@ class BrowseServer(object):
|
||||
cats = [
|
||||
(_('Newest'), 'newest', 'forward.png'),
|
||||
(_('All books'), 'allbooks', 'book.png'),
|
||||
(_('Random book'), 'randombook', 'random.png'),
|
||||
]
|
||||
|
||||
def getter(x):
|
||||
@ -599,6 +602,9 @@ class BrowseServer(object):
|
||||
elif category == 'allbooks':
|
||||
raise cherrypy.InternalRedirect(prefix +
|
||||
'/browse/matches/allbooks/dummy')
|
||||
elif category == 'randombook':
|
||||
raise cherrypy.InternalRedirect(prefix +
|
||||
'/browse/random')
|
||||
else:
|
||||
ans = self.browse_category(category, category_sort)
|
||||
|
||||
@ -885,6 +891,13 @@ class BrowseServer(object):
|
||||
|
||||
return json.dumps(ans, ensure_ascii=False)
|
||||
|
||||
@Endpoint()
|
||||
def browse_random(self, *args, **kwargs):
|
||||
import random
|
||||
book_id = random.choice(tuple(self.db.all_ids()))
|
||||
ans = self.browse_render_details(book_id)
|
||||
return self.browse_template('').format(
|
||||
title='', script='book();', main=ans)
|
||||
|
||||
@Endpoint()
|
||||
def browse_book(self, id=None, category_sort=None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user