Workaround for iTunes breaking scripting with version 10.6.3 on OS X. Fixes #1012243 (Cannot connect to update iTunes 10.6.3)

This commit is contained in:
Kovid Goyal 2012-06-27 20:36:00 +05:30
commit ff80d9c8ce

View File

@ -212,11 +212,8 @@ class ITUNES(DriverBase):
"for instructions on using 'Connect to iTunes'") "for instructions on using 'Connect to iTunes'")
ITUNES_SANDBOX_LOCKOUT_MESSAGE = _( ITUNES_SANDBOX_LOCKOUT_MESSAGE = _(
'<p>Unable to communicate with iTunes.</p>' '<p>Unable to communicate with iTunes.</p>'
"<p>As of iTunes version 10.6.3, application 'sandboxing' " '<p>Refer to this '
'was implemented by Apple, disabling inter-application communications ' '<a href="http://www.mobileread.com/forums/showpost.php?p=2113958&postcount=3">forum post</a> '
'between iTunes and third-party applications.</p>'
'<p>Refer to the forum post '
'<a href="http://www.mobileread.com/forums/showpost.php?p=2113958&postcount=3">Apple implements sandboxing for iTunes 10.6.3</a> '
'for more information.</p>' 'for more information.</p>'
'<p></p>') '<p></p>')
@ -232,8 +229,9 @@ class ITUNES(DriverBase):
# 0x12a0 iPhone 4S # 0x12a0 iPhone 4S
# 0x12a2 iPad2 (GSM) # 0x12a2 iPad2 (GSM)
# 0x12a3 iPad2 (CDMA) # 0x12a3 iPad2 (CDMA)
# 0x12a6 iPad3 (GSM)
VENDOR_ID = [0x05ac] VENDOR_ID = [0x05ac]
PRODUCT_ID = [0x1292,0x1293,0x1294,0x1297,0x1299,0x129a,0x129f,0x12a2,0x12a3] PRODUCT_ID = [0x1292,0x1293,0x1294,0x1297,0x1299,0x129a,0x129f,0x12a2,0x12a3,0x12a6]
BCD = [0x01] BCD = [0x01]
# Plugboard ID # Plugboard ID
@ -2362,6 +2360,8 @@ class ITUNES(DriverBase):
if isosx: if isosx:
import appscript import appscript
as_name = appscript.__name__
as_version = appscript.__version__
''' '''
Launch iTunes if not already running Launch iTunes if not already running
''' '''
@ -2371,7 +2371,7 @@ class ITUNES(DriverBase):
if DEBUG: if DEBUG:
logger().info( "ITUNES:_launch_iTunes(): Launching iTunes" ) logger().info( "ITUNES:_launch_iTunes(): Launching iTunes" )
try: try:
self.iTunes = iTunes= appscript.app('iTunes', hide=True) self.iTunes = iTunes = appscript.app('iTunes', hide=True)
except: except:
self.iTunes = None self.iTunes = None
raise UserFeedback(' ITUNES._launch_iTunes(): unable to find installed iTunes', details=None, level=UserFeedback.WARN) raise UserFeedback(' ITUNES._launch_iTunes(): unable to find installed iTunes', details=None, level=UserFeedback.WARN)
@ -2383,19 +2383,26 @@ class ITUNES(DriverBase):
self.initial_status = 'already running' self.initial_status = 'already running'
''' '''
Test OSA. If we can't get the app name, we can't talk to iTunes. Test OSA communication with iTunes.
As of iTunes 10.6.3 (June 2012), sandboxing was implemented disabling OSA
interapp communications.
If unable to communicate with iTunes, set self.iTunes to None, then If unable to communicate with iTunes, set self.iTunes to None, then
report to user in open() report to user in open()
''' '''
as_binding = "dynamic"
try: try:
# Try dynamic binding - works with iTunes <= 10.6.1
foo = self.iTunes.name() foo = self.iTunes.name()
except: except:
self.iTunes = None # Try static binding
if DEBUG: import itunes
logger().info(" unable to communicate with iTunes, raising dialog to user") self.iTunes = appscript.app('iTunes',terms=itunes)
return try:
foo = self.iTunes.name()
as_binding = "static"
except:
self.iTunes = None
if DEBUG:
logger().info(" unable to communicate with iTunes via %s %s using any binding" % (as_name, as_version))
return
''' '''
# Read the current storage path for iTunes media # Read the current storage path for iTunes media
@ -2415,6 +2422,7 @@ class ITUNES(DriverBase):
logger().info(" [OSX %s - %s (%s), driver version %d.%d.%d]" % logger().info(" [OSX %s - %s (%s), driver version %d.%d.%d]" %
(self.iTunes.name(), self.iTunes.version(), self.initial_status, (self.iTunes.name(), self.iTunes.version(), self.initial_status,
self.version[0],self.version[1],self.version[2])) self.version[0],self.version[1],self.version[2]))
logger().info(" communicating with iTunes via %s %s using %s binding" % (as_name, as_version, as_binding))
logger().info(" calibre_library_path: %s" % self.calibre_library_path) logger().info(" calibre_library_path: %s" % self.calibre_library_path)
if iswindows: if iswindows: