mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Apple driver: Delay load appscript and pythoncom
This commit is contained in:
parent
959afbd350
commit
eb98a1e66b
@ -103,17 +103,6 @@ class AppleOpenFeedback(OpenFeedback):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if isosx:
|
|
||||||
try:
|
|
||||||
import appscript
|
|
||||||
appscript
|
|
||||||
except:
|
|
||||||
# appscript fails to load on 10.4
|
|
||||||
appscript = None
|
|
||||||
|
|
||||||
if iswindows:
|
|
||||||
import pythoncom, win32com.client
|
|
||||||
|
|
||||||
class DriverBase(DeviceConfig, DevicePlugin):
|
class DriverBase(DeviceConfig, DevicePlugin):
|
||||||
# Needed for config_widget to work
|
# Needed for config_widget to work
|
||||||
FORMATS = ['epub', 'pdf']
|
FORMATS = ['epub', 'pdf']
|
||||||
@ -467,6 +456,7 @@ class ITUNES(DriverBase):
|
|||||||
self._purge_orphans(library_books, cached_books)
|
self._purge_orphans(library_books, cached_books)
|
||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
|
import pythoncom, win32com.client
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
||||||
@ -533,6 +523,11 @@ class ITUNES(DriverBase):
|
|||||||
instantiate iTunes if necessary
|
instantiate iTunes if necessary
|
||||||
This gets called ~1x/second while device fingerprint is sensed
|
This gets called ~1x/second while device fingerprint is sensed
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
|
import appscript
|
||||||
|
appscript
|
||||||
|
except:
|
||||||
|
appscript = None
|
||||||
if appscript is None:
|
if appscript is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -600,6 +595,7 @@ class ITUNES(DriverBase):
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
if self.iTunes:
|
if self.iTunes:
|
||||||
|
import pythoncom
|
||||||
# We've previously run, so the user probably ejected the device
|
# We've previously run, so the user probably ejected the device
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
@ -709,6 +705,7 @@ class ITUNES(DriverBase):
|
|||||||
if self.manual_sync_mode:
|
if self.manual_sync_mode:
|
||||||
self._remove_from_device(self.cached_books[path])
|
self._remove_from_device(self.cached_books[path])
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
|
import pythoncom, win32com.client
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
||||||
@ -754,6 +751,8 @@ class ITUNES(DriverBase):
|
|||||||
self.iTunes.eject(self.sources['iPod'])
|
self.iTunes.eject(self.sources['iPod'])
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
if 'iPod' in self.sources:
|
if 'iPod' in self.sources:
|
||||||
|
import pythoncom, win32com.client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
||||||
@ -788,6 +787,7 @@ class ITUNES(DriverBase):
|
|||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
if 'iPod' in self.sources:
|
if 'iPod' in self.sources:
|
||||||
|
import pythoncom, win32com.client
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -1098,6 +1098,8 @@ class ITUNES(DriverBase):
|
|||||||
_('%(num)d of %(tot)d') % dict(num=i+1, tot=file_count))
|
_('%(num)d of %(tot)d') % dict(num=i+1, tot=file_count))
|
||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
|
import pythoncom, win32com.client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
||||||
@ -1163,6 +1165,7 @@ class ITUNES(DriverBase):
|
|||||||
'''
|
'''
|
||||||
logger().info(" ITUNES._add_device_book()")
|
logger().info(" ITUNES._add_device_book()")
|
||||||
if isosx:
|
if isosx:
|
||||||
|
import appscript
|
||||||
if 'iPod' in self.sources:
|
if 'iPod' in self.sources:
|
||||||
connected_device = self.sources['iPod']
|
connected_device = self.sources['iPod']
|
||||||
device = self.iTunes.sources[connected_device]
|
device = self.iTunes.sources[connected_device]
|
||||||
@ -1257,6 +1260,7 @@ class ITUNES(DriverBase):
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info(" ITUNES._add_library_book()")
|
logger().info(" ITUNES._add_library_book()")
|
||||||
if isosx:
|
if isosx:
|
||||||
|
import appscript
|
||||||
added = self.iTunes.add(appscript.mactypes.File(file))
|
added = self.iTunes.add(appscript.mactypes.File(file))
|
||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
@ -1541,6 +1545,7 @@ class ITUNES(DriverBase):
|
|||||||
if wait:
|
if wait:
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
if isosx:
|
if isosx:
|
||||||
|
import appscript
|
||||||
connected_device = self.sources['iPod']
|
connected_device = self.sources['iPod']
|
||||||
dev_books = None
|
dev_books = None
|
||||||
device = self.iTunes.sources[connected_device]
|
device = self.iTunes.sources[connected_device]
|
||||||
@ -2077,6 +2082,7 @@ class ITUNES(DriverBase):
|
|||||||
|
|
||||||
device_books = []
|
device_books = []
|
||||||
if isosx:
|
if isosx:
|
||||||
|
import appscript
|
||||||
if 'iPod' in self.sources:
|
if 'iPod' in self.sources:
|
||||||
connected_device = self.sources['iPod']
|
connected_device = self.sources['iPod']
|
||||||
device = self.iTunes.sources[connected_device]
|
device = self.iTunes.sources[connected_device]
|
||||||
@ -2104,6 +2110,8 @@ class ITUNES(DriverBase):
|
|||||||
logger().info()
|
logger().info()
|
||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
|
import pythoncom
|
||||||
|
|
||||||
if 'iPod' in self.sources:
|
if 'iPod' in self.sources:
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
@ -2171,6 +2179,7 @@ class ITUNES(DriverBase):
|
|||||||
lib = None
|
lib = None
|
||||||
|
|
||||||
if isosx:
|
if isosx:
|
||||||
|
import appscript
|
||||||
for source in self.iTunes.sources():
|
for source in self.iTunes.sources():
|
||||||
if source.kind() == appscript.k.library:
|
if source.kind() == appscript.k.library:
|
||||||
lib = source
|
lib = source
|
||||||
@ -2341,6 +2350,7 @@ class ITUNES(DriverBase):
|
|||||||
logger().info(" ITUNES:_launch_iTunes():\n Instantiating iTunes")
|
logger().info(" ITUNES:_launch_iTunes():\n Instantiating iTunes")
|
||||||
|
|
||||||
if isosx:
|
if isosx:
|
||||||
|
import appscript
|
||||||
'''
|
'''
|
||||||
Launch iTunes if not already running
|
Launch iTunes if not already running
|
||||||
'''
|
'''
|
||||||
@ -2382,6 +2392,8 @@ class ITUNES(DriverBase):
|
|||||||
logger().info(" calibre_library_path: %s" % self.calibre_library_path)
|
logger().info(" calibre_library_path: %s" % self.calibre_library_path)
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
import win32com.client
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Launch iTunes if not already running
|
Launch iTunes if not already running
|
||||||
Assumes pythoncom wrapper
|
Assumes pythoncom wrapper
|
||||||
@ -2752,6 +2764,8 @@ class ITUNES(DriverBase):
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
print
|
print
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
|
import pythoncom, win32com.client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
||||||
@ -3088,6 +3102,12 @@ class ITUNES_ASYNC(ITUNES):
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info("ITUNES_ASYNC:__init__()")
|
logger().info("ITUNES_ASYNC:__init__()")
|
||||||
|
|
||||||
|
try:
|
||||||
|
import appscript
|
||||||
|
appscript
|
||||||
|
except:
|
||||||
|
appscript = None
|
||||||
|
|
||||||
if isosx and appscript is None:
|
if isosx and appscript is None:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
raise UserFeedback('OSX 10.5 or later required', details=None, level=UserFeedback.WARN)
|
raise UserFeedback('OSX 10.5 or later required', details=None, level=UserFeedback.WARN)
|
||||||
@ -3099,6 +3119,8 @@ class ITUNES_ASYNC(ITUNES):
|
|||||||
self._launch_iTunes()
|
self._launch_iTunes()
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
import pythoncom
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self._launch_iTunes()
|
self._launch_iTunes()
|
||||||
@ -3180,6 +3202,8 @@ class ITUNES_ASYNC(ITUNES):
|
|||||||
_('%(num)d of %(tot)d') % dict(num=i+1, tot=book_count))
|
_('%(num)d of %(tot)d') % dict(num=i+1, tot=book_count))
|
||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
|
import pythoncom, win32com.client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
self.iTunes = win32com.client.Dispatch("iTunes.Application")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user