Merge from trunk

This commit is contained in:
Charles Haley 2012-07-23 21:46:21 +02:00
commit 61ddf184f0
4 changed files with 37 additions and 41 deletions

View File

@ -160,7 +160,6 @@ class JsonCodec(object):
js = []
try:
js = json.load(file_, encoding='utf-8')
self.raw_to_booklist(js, booklist, book_class, prefix)
for item in js:
booklist.append(self.raw_to_book(item, book_class, prefix))
except:

View File

@ -967,6 +967,11 @@ class DeviceMixin(object): # {{{
fmt = None
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 = []
aval_out_formats = available_output_formats()
format_count = {}

View File

@ -78,13 +78,18 @@ class BonJour(SimplePlugin): # {{{
SimplePlugin.__init__(self, engine)
self.port = port
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):
try:
publish_zeroconf('Books in calibre', '_stanza._tcp',
self.port, {'path':self.prefix+'/stanza'})
publish_zeroconf('Books in calibre', '_calibre._tcp',
self.port, {'path':self.prefix+'/opds'})
for s in self.mdns_services:
publish_zeroconf(*s)
except:
import traceback
cherrypy.log.error('Failed to start BonJour:')
@ -94,10 +99,8 @@ class BonJour(SimplePlugin): # {{{
def stop(self):
try:
unpublish_zeroconf('Books in calibre', '_stanza._tcp',
self.port, {'path':self.prefix+'/stanza'})
unpublish_zeroconf('Books in calibre', '_calibre._tcp',
self.port, {'path':self.prefix+'/opds'})
for s in self.mdns_services:
unpublish_zeroconf(*s)
except:
import traceback
cherrypy.log.error('Failed to stop BonJour:')

View File

@ -47,6 +47,25 @@ def start_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):
'''
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
into the TXT record.
'''
port = int(port)
server = start_server()
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
service = ServiceInfo(type, desc+'.'+type,
address=socket.inet_aton(local_ip),
port=port,
properties=properties,
server=hostname+'.local.')
service = create_service(desc, type, port, properties, add_hostname)
server.registerService(service)
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
'''
port = int(port)
server = start_server()
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
service = ServiceInfo(type, desc+'.'+type,
address=socket.inet_aton(local_ip),
port=port,
properties=properties,
server=hostname+'.local.')
service = create_service(desc, type, port, properties, add_hostname)
server.unregisterService(service)
if server.countRegisteredServices() == 0:
stop_server()