mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GwR apple driver wip
This commit is contained in:
parent
d55c7122b5
commit
8a6faa8b75
@ -22,7 +22,6 @@ if isosx:
|
|||||||
import appscript, osax
|
import appscript, osax
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
print "ITUNES: Running under windows"
|
|
||||||
import win32com.client
|
import win32com.client
|
||||||
|
|
||||||
class UserInteractionRequired(Exception):
|
class UserInteractionRequired(Exception):
|
||||||
@ -59,19 +58,18 @@ class ITUNES(DevicePlugin):
|
|||||||
BCD = [0x01]
|
BCD = [0x01]
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
add_list = None
|
|
||||||
cached_books = {}
|
cached_books = {}
|
||||||
cache_dir = os.path.join(config_dir, 'caches', 'itunes')
|
cache_dir = os.path.join(config_dir, 'caches', 'itunes')
|
||||||
iTunes= None
|
iTunes= None
|
||||||
log = Log()
|
log = Log()
|
||||||
path_template = 'iTunes/%s - %s.epub'
|
path_template = 'iTunes/%s - %s.epub'
|
||||||
presync = True
|
presync = False
|
||||||
update_list = None
|
update_list = None
|
||||||
sources = None
|
sources = None
|
||||||
update_msg = None
|
update_msg = None
|
||||||
update_needed = False
|
update_needed = False
|
||||||
use_thumbnail_as_cover = False
|
use_thumbnail_as_cover = False
|
||||||
verbose = False
|
verbose = True
|
||||||
|
|
||||||
# Public methods
|
# Public methods
|
||||||
def add_books_to_metadata(self, locations, metadata, booklists):
|
def add_books_to_metadata(self, locations, metadata, booklists):
|
||||||
@ -183,17 +181,22 @@ class ITUNES(DevicePlugin):
|
|||||||
if isosx:
|
if isosx:
|
||||||
if self.iTunes:
|
if self.iTunes:
|
||||||
# Check for connected book-capable device
|
# Check for connected book-capable device
|
||||||
names = [s.name() for s in self.iTunes.sources()]
|
try:
|
||||||
kinds = [str(s.kind()).rpartition('.')[2] for s in self.iTunes.sources()]
|
names = [s.name() for s in self.iTunes.sources()]
|
||||||
self.sources = sources = dict(zip(kinds,names))
|
kinds = [str(s.kind()).rpartition('.')[2] for s in self.iTunes.sources()]
|
||||||
if 'iPod' in sources:
|
self.sources = sources = dict(zip(kinds,names))
|
||||||
if self.verbose:
|
if 'iPod' in sources:
|
||||||
sys.stdout.write('.')
|
if self.verbose:
|
||||||
sys.stdout.flush()
|
sys.stdout.write('.')
|
||||||
return True
|
sys.stdout.flush()
|
||||||
else:
|
return True
|
||||||
if self.verbose:
|
else:
|
||||||
self.log.info("ITUNES.can_handle(): device ejected")
|
if self.verbose:
|
||||||
|
self.log.info("ITUNES.can_handle(): device ejected")
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
# iTunes connection failed, probably not running anymore
|
||||||
|
self.log.error("ITUNES.can_handle(): lost connection to iTunes")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
# can_handle() is called once before open(), so need to return True
|
# can_handle() is called once before open(), so need to return True
|
||||||
@ -214,9 +217,16 @@ class ITUNES(DevicePlugin):
|
|||||||
:param device_info: On windows a device ID string. On Unix a tuple of
|
:param device_info: On windows a device ID string. On Unix a tuple of
|
||||||
``(vendor_id, product_id, bcd)``.
|
``(vendor_id, product_id, bcd)``.
|
||||||
'''
|
'''
|
||||||
if self.verbose:
|
|
||||||
self.log.info("ITUNES:can_handle_windows()")
|
if self.iTunes:
|
||||||
return True
|
sys.exit(1)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# can_handle() is called once before open(), so need to return True
|
||||||
|
# to keep things going
|
||||||
|
if self.verbose:
|
||||||
|
self.log.info("ITUNES:can_handle(): iTunes not yet instantiated")
|
||||||
|
return True
|
||||||
|
|
||||||
def card_prefix(self, end_session=True):
|
def card_prefix(self, end_session=True):
|
||||||
'''
|
'''
|
||||||
@ -309,7 +319,9 @@ class ITUNES(DevicePlugin):
|
|||||||
Read the file at C{path} on the device and write it to outfile.
|
Read the file at C{path} on the device and write it to outfile.
|
||||||
@param outfile: file object like C{sys.stdout} or the result of an C{open} call
|
@param outfile: file object like C{sys.stdout} or the result of an C{open} call
|
||||||
'''
|
'''
|
||||||
raise NotImplementedError()
|
if self.verbose:
|
||||||
|
self.log.info("ITUNES.get_file(): exporting '%s'" % path)
|
||||||
|
outfile.write(open(self.cached_books[path]['lib_book'].location().path).read())
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
'''
|
'''
|
||||||
@ -380,6 +392,11 @@ class ITUNES(DevicePlugin):
|
|||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.log.info(" existing thumb cache at '%s'" % archive_path)
|
self.log.info(" existing thumb cache at '%s'" % archive_path)
|
||||||
|
|
||||||
|
if iswindows:
|
||||||
|
# Launch iTunes if not already running
|
||||||
|
if self.verbose:
|
||||||
|
self.log.info("ITUNES:open(): Instantiating iTunes")
|
||||||
|
|
||||||
def post_yank_cleanup(self):
|
def post_yank_cleanup(self):
|
||||||
'''
|
'''
|
||||||
Called if the user yanks the device without ejecting it first.
|
Called if the user yanks the device without ejecting it first.
|
||||||
@ -538,7 +555,6 @@ class ITUNES(DevicePlugin):
|
|||||||
|
|
||||||
new_booklist = []
|
new_booklist = []
|
||||||
self.update_list = []
|
self.update_list = []
|
||||||
self.add_list = []
|
|
||||||
|
|
||||||
if isosx:
|
if isosx:
|
||||||
|
|
||||||
@ -549,15 +565,12 @@ class ITUNES(DevicePlugin):
|
|||||||
# for deletion from booklist[0] during add_books_to_metadata
|
# for deletion from booklist[0] during add_books_to_metadata
|
||||||
if path in self.cached_books:
|
if path in self.cached_books:
|
||||||
self.update_list.append(self.cached_books[path])
|
self.update_list.append(self.cached_books[path])
|
||||||
self.add_list.append({'title':metadata[i].title,'author':metadata[i].author[0]})
|
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.log.info("ITUNES.upload_books():")
|
self.log.info("ITUNES.upload_books():")
|
||||||
self.log.info( " deleting existing '%s'" % (path))
|
self.log.info( " deleting existing '%s'" % (path))
|
||||||
self._remove_iTunes_dir(self.cached_books[path])
|
self._remove_iTunes_dir(self.cached_books[path])
|
||||||
self.iTunes.delete(self.cached_books[path]['lib_book'])
|
self.iTunes.delete(self.cached_books[path]['lib_book'])
|
||||||
else:
|
|
||||||
self.add_list.append({'title':metadata[i].title,'author':metadata[i].author[0]})
|
|
||||||
|
|
||||||
# Add to iTunes Library|Books
|
# Add to iTunes Library|Books
|
||||||
added = self.iTunes.add(appscript.mactypes.File(files[i]))
|
added = self.iTunes.add(appscript.mactypes.File(files[i]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user