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
61ddf184f0
@ -160,7 +160,6 @@ class JsonCodec(object):
|
|||||||
js = []
|
js = []
|
||||||
try:
|
try:
|
||||||
js = json.load(file_, encoding='utf-8')
|
js = json.load(file_, encoding='utf-8')
|
||||||
self.raw_to_booklist(js, booklist, book_class, prefix)
|
|
||||||
for item in js:
|
for item in js:
|
||||||
booklist.append(self.raw_to_book(item, book_class, prefix))
|
booklist.append(self.raw_to_book(item, book_class, prefix))
|
||||||
except:
|
except:
|
||||||
|
@ -967,6 +967,11 @@ class DeviceMixin(object): # {{{
|
|||||||
|
|
||||||
fmt = None
|
fmt = None
|
||||||
if specific:
|
if specific:
|
||||||
|
if (not self.device_connected or not self.device_manager or
|
||||||
|
self.device_manager.device is None):
|
||||||
|
error_dialog(self, _('No device'),
|
||||||
|
_('No device connected'), show=True)
|
||||||
|
return
|
||||||
formats = []
|
formats = []
|
||||||
aval_out_formats = available_output_formats()
|
aval_out_formats = available_output_formats()
|
||||||
format_count = {}
|
format_count = {}
|
||||||
|
@ -78,13 +78,18 @@ class BonJour(SimplePlugin): # {{{
|
|||||||
SimplePlugin.__init__(self, engine)
|
SimplePlugin.__init__(self, engine)
|
||||||
self.port = port
|
self.port = port
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
self.mdns_services = [
|
||||||
|
('Books in calibre', '_stanza._tcp', self.port,
|
||||||
|
{'path':self.prefix+'/stanza'}),
|
||||||
|
('Books in calibre', '_calibre._tcp', self.port,
|
||||||
|
{'path':self.prefix+'/opds'}),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
try:
|
try:
|
||||||
publish_zeroconf('Books in calibre', '_stanza._tcp',
|
for s in self.mdns_services:
|
||||||
self.port, {'path':self.prefix+'/stanza'})
|
publish_zeroconf(*s)
|
||||||
publish_zeroconf('Books in calibre', '_calibre._tcp',
|
|
||||||
self.port, {'path':self.prefix+'/opds'})
|
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
cherrypy.log.error('Failed to start BonJour:')
|
cherrypy.log.error('Failed to start BonJour:')
|
||||||
@ -94,10 +99,8 @@ class BonJour(SimplePlugin): # {{{
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
try:
|
try:
|
||||||
unpublish_zeroconf('Books in calibre', '_stanza._tcp',
|
for s in self.mdns_services:
|
||||||
self.port, {'path':self.prefix+'/stanza'})
|
unpublish_zeroconf(*s)
|
||||||
unpublish_zeroconf('Books in calibre', '_calibre._tcp',
|
|
||||||
self.port, {'path':self.prefix+'/opds'})
|
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
cherrypy.log.error('Failed to stop BonJour:')
|
cherrypy.log.error('Failed to stop BonJour:')
|
||||||
|
@ -47,6 +47,25 @@ def start_server():
|
|||||||
|
|
||||||
return _server
|
return _server
|
||||||
|
|
||||||
|
def create_service(desc, type, port, properties, add_hostname):
|
||||||
|
port = int(port)
|
||||||
|
try:
|
||||||
|
hostname = socket.gethostname().partition('.')[0]
|
||||||
|
except:
|
||||||
|
hostname = 'Unknown'
|
||||||
|
|
||||||
|
if add_hostname:
|
||||||
|
desc += ' (on %s)'%hostname
|
||||||
|
local_ip = get_external_ip()
|
||||||
|
type = type+'.local.'
|
||||||
|
from calibre.utils.Zeroconf import ServiceInfo
|
||||||
|
return ServiceInfo(type, desc+'.'+type,
|
||||||
|
address=socket.inet_aton(local_ip),
|
||||||
|
port=port,
|
||||||
|
properties=properties,
|
||||||
|
server=hostname+'.local.')
|
||||||
|
|
||||||
|
|
||||||
def publish(desc, type, port, properties=None, add_hostname=True):
|
def publish(desc, type, port, properties=None, add_hostname=True):
|
||||||
'''
|
'''
|
||||||
Publish a service.
|
Publish a service.
|
||||||
@ -57,23 +76,8 @@ def publish(desc, type, port, properties=None, add_hostname=True):
|
|||||||
:param properties: An optional dictionary whose keys and values will be put
|
:param properties: An optional dictionary whose keys and values will be put
|
||||||
into the TXT record.
|
into the TXT record.
|
||||||
'''
|
'''
|
||||||
port = int(port)
|
|
||||||
server = start_server()
|
server = start_server()
|
||||||
try:
|
service = create_service(desc, type, port, properties, add_hostname)
|
||||||
hostname = socket.gethostname().partition('.')[0]
|
|
||||||
except:
|
|
||||||
hostname = 'Unknown'
|
|
||||||
|
|
||||||
if add_hostname:
|
|
||||||
desc += ' (on %s)'%hostname
|
|
||||||
local_ip = get_external_ip()
|
|
||||||
type = type+'.local.'
|
|
||||||
from calibre.utils.Zeroconf import ServiceInfo
|
|
||||||
service = ServiceInfo(type, desc+'.'+type,
|
|
||||||
address=socket.inet_aton(local_ip),
|
|
||||||
port=port,
|
|
||||||
properties=properties,
|
|
||||||
server=hostname+'.local.')
|
|
||||||
server.registerService(service)
|
server.registerService(service)
|
||||||
|
|
||||||
def unpublish(desc, type, port, properties=None, add_hostname=True):
|
def unpublish(desc, type, port, properties=None, add_hostname=True):
|
||||||
@ -82,23 +86,8 @@ def unpublish(desc, type, port, properties=None, add_hostname=True):
|
|||||||
|
|
||||||
The parameters must be the same as used in the corresponding call to publish
|
The parameters must be the same as used in the corresponding call to publish
|
||||||
'''
|
'''
|
||||||
port = int(port)
|
|
||||||
server = start_server()
|
server = start_server()
|
||||||
try:
|
service = create_service(desc, type, port, properties, add_hostname)
|
||||||
hostname = socket.gethostname().partition('.')[0]
|
|
||||||
except:
|
|
||||||
hostname = 'Unknown'
|
|
||||||
|
|
||||||
if add_hostname:
|
|
||||||
desc += ' (on %s)'%hostname
|
|
||||||
local_ip = get_external_ip()
|
|
||||||
type = type+'.local.'
|
|
||||||
from calibre.utils.Zeroconf import ServiceInfo
|
|
||||||
service = ServiceInfo(type, desc+'.'+type,
|
|
||||||
address=socket.inet_aton(local_ip),
|
|
||||||
port=port,
|
|
||||||
properties=properties,
|
|
||||||
server=hostname+'.local.')
|
|
||||||
server.unregisterService(service)
|
server.unregisterService(service)
|
||||||
if server.countRegisteredServices() == 0:
|
if server.countRegisteredServices() == 0:
|
||||||
stop_server()
|
stop_server()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user