diff --git a/src/calibre/ebooks/metadata/book/json_codec.py b/src/calibre/ebooks/metadata/book/json_codec.py index 8e2dc64383..cc9b6f252d 100644 --- a/src/calibre/ebooks/metadata/book/json_codec.py +++ b/src/calibre/ebooks/metadata/book/json_codec.py @@ -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: diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index da2c45fd9c..17f1e47853 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -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 = {} diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py index a61d2dcc3e..d912165734 100644 --- a/src/calibre/library/server/base.py +++ b/src/calibre/library/server/base.py @@ -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:') diff --git a/src/calibre/utils/mdns.py b/src/calibre/utils/mdns.py index 42e846577e..9232aab994 100644 --- a/src/calibre/utils/mdns.py +++ b/src/calibre/utils/mdns.py @@ -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()