mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
7879c5b97b
@ -31,6 +31,7 @@ from calibre.ebooks.metadata import title_sort
|
|||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
||||||
from calibre.library import current_library_name
|
from calibre.library import current_library_name
|
||||||
|
from calibre.library.server import server_config as content_server_config
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.config import from_json, tweaks
|
from calibre.utils.config import from_json, tweaks
|
||||||
@ -98,9 +99,16 @@ class ConnectionListener (Thread):
|
|||||||
try:
|
try:
|
||||||
packet = self.driver.broadcast_socket.recvfrom(100)
|
packet = self.driver.broadcast_socket.recvfrom(100)
|
||||||
remote = packet[1]
|
remote = packet[1]
|
||||||
|
content_server_port = b'';
|
||||||
|
try :
|
||||||
|
content_server_port = \
|
||||||
|
str(content_server_config().parse().port)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
message = str(self.driver.ZEROCONF_CLIENT_STRING + b' (on ' +
|
message = str(self.driver.ZEROCONF_CLIENT_STRING + b' (on ' +
|
||||||
str(socket.gethostname().partition('.')[0]) +
|
str(socket.gethostname().partition('.')[0]) +
|
||||||
b'),' + str(self.driver.port))
|
b');' + content_server_port +
|
||||||
|
b',' + str(self.driver.port))
|
||||||
self.driver._debug('received broadcast', packet, message)
|
self.driver._debug('received broadcast', packet, message)
|
||||||
self.driver.broadcast_socket.sendto(message, remote)
|
self.driver.broadcast_socket.sendto(message, remote)
|
||||||
except:
|
except:
|
||||||
@ -163,7 +171,9 @@ class SDBook(Book):
|
|||||||
|
|
||||||
class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||||
name = 'SmartDevice App Interface'
|
name = 'SmartDevice App Interface'
|
||||||
gui_name = _('SmartDevice')
|
gui_name = gui_name_base = _('Wireless Device')
|
||||||
|
gui_name_template = '%s: %s'
|
||||||
|
|
||||||
icon = I('devices/galaxy_s3.png')
|
icon = I('devices/galaxy_s3.png')
|
||||||
description = _('Communicate with Smart Device apps')
|
description = _('Communicate with Smart Device apps')
|
||||||
supported_platforms = ['windows', 'osx', 'linux']
|
supported_platforms = ['windows', 'osx', 'linux']
|
||||||
@ -321,28 +331,30 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
self.client_can_stream_metadata = False
|
self.client_can_stream_metadata = False
|
||||||
|
|
||||||
def _debug(self, *args):
|
def _debug(self, *args):
|
||||||
if not DEBUG:
|
# manual synchronization so we don't lose the calling method name
|
||||||
return
|
with self.sync_lock:
|
||||||
total_elapsed = time.time() - self.debug_start_time
|
if not DEBUG:
|
||||||
elapsed = time.time() - self.debug_time
|
return
|
||||||
print('SMART_DEV (%7.2f:%7.3f) %s'%(total_elapsed, elapsed,
|
total_elapsed = time.time() - self.debug_start_time
|
||||||
inspect.stack()[1][3]), end='')
|
elapsed = time.time() - self.debug_time
|
||||||
for a in args:
|
print('SMART_DEV (%7.2f:%7.3f) %s'%(total_elapsed, elapsed,
|
||||||
try:
|
inspect.stack()[1][3]), end='')
|
||||||
if isinstance(a, dict):
|
for a in args:
|
||||||
printable = {}
|
try:
|
||||||
for k,v in a.iteritems():
|
if isinstance(a, dict):
|
||||||
if isinstance(v, (str, unicode)) and len(v) > 50:
|
printable = {}
|
||||||
printable[k] = 'too long'
|
for k,v in a.iteritems():
|
||||||
else:
|
if isinstance(v, (str, unicode)) and len(v) > 50:
|
||||||
printable[k] = v
|
printable[k] = 'too long'
|
||||||
prints('', printable, end='')
|
else:
|
||||||
else:
|
printable[k] = v
|
||||||
prints('', a, end='')
|
prints('', printable, end='')
|
||||||
except:
|
else:
|
||||||
prints('', 'value too long', end='')
|
prints('', a, end='')
|
||||||
print()
|
except:
|
||||||
self.debug_time = time.time()
|
prints('', 'value too long', end='')
|
||||||
|
print()
|
||||||
|
self.debug_time = time.time()
|
||||||
|
|
||||||
# local utilities
|
# local utilities
|
||||||
|
|
||||||
@ -825,6 +837,9 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
self.client_can_receive_book_binary = result.get('canReceiveBookBinary', False)
|
self.client_can_receive_book_binary = result.get('canReceiveBookBinary', False)
|
||||||
self._debug('Device can receive book binary', self.client_can_stream_metadata)
|
self._debug('Device can receive book binary', self.client_can_stream_metadata)
|
||||||
|
|
||||||
|
self.client_device_kind = result.get('deviceKind', '')
|
||||||
|
self._debug('Client device kind', self.client_device_kind)
|
||||||
|
|
||||||
self.max_book_packet_len = result.get('maxBookContentPacketLen',
|
self.max_book_packet_len = result.get('maxBookContentPacketLen',
|
||||||
self.BASE_PACKET_LEN)
|
self.BASE_PACKET_LEN)
|
||||||
self._debug('max_book_packet_len', self.max_book_packet_len)
|
self._debug('max_book_packet_len', self.max_book_packet_len)
|
||||||
@ -886,6 +901,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
raise
|
raise
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_gui_name(self):
|
||||||
|
if self.client_device_kind:
|
||||||
|
return self.gui_name_template%(self.gui_name, self.client_device_kind)
|
||||||
|
return self.gui_name
|
||||||
|
|
||||||
|
|
||||||
@synchronous('sync_lock')
|
@synchronous('sync_lock')
|
||||||
def get_device_information(self, end_session=True):
|
def get_device_information(self, end_session=True):
|
||||||
self._debug()
|
self._debug()
|
||||||
@ -1035,10 +1056,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
def eject(self):
|
def eject(self):
|
||||||
self._debug()
|
self._debug()
|
||||||
self._close_device_socket()
|
self._close_device_socket()
|
||||||
|
self.gui_name = self.gui_name_base
|
||||||
|
|
||||||
@synchronous('sync_lock')
|
@synchronous('sync_lock')
|
||||||
def post_yank_cleanup(self):
|
def post_yank_cleanup(self):
|
||||||
self._debug()
|
self._debug()
|
||||||
|
self.gui_name = self.gui_name_base
|
||||||
|
|
||||||
@synchronous('sync_lock')
|
@synchronous('sync_lock')
|
||||||
def upload_books(self, files, names, on_card=None, end_session=True,
|
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||||
|
@ -608,6 +608,8 @@ class BuiltinApproximateFormats(BuiltinFormatterFunction):
|
|||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals):
|
def evaluate(self, formatter, kwargs, mi, locals):
|
||||||
fmt_data = mi.get('db_approx_formats', [])
|
fmt_data = mi.get('db_approx_formats', [])
|
||||||
|
if not fmt_data:
|
||||||
|
return ''
|
||||||
data = sorted(fmt_data)
|
data = sorted(fmt_data)
|
||||||
return ','.join(v.upper() for v in data)
|
return ','.join(v.upper() for v in data)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user