Make PRS505 mount point detection more robust on windows and osx

This commit is contained in:
Kovid Goyal 2008-09-05 12:53:14 -07:00
parent b25ca50102
commit 04a5bf16bd
3 changed files with 44 additions and 29 deletions

View File

@ -2,7 +2,7 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
__appname__ = 'calibre' __appname__ = 'calibre'
__version__ = '0.4.84b8' __version__ = '0.4.84b9'
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
''' '''
Various run time constants. Various run time constants.

View File

@ -39,9 +39,7 @@ class PRS505(Device):
MAIN_MEMORY_VOLUME_LABEL = 'Sony Reader Main Memory' MAIN_MEMORY_VOLUME_LABEL = 'Sony Reader Main Memory'
STORAGE_CARD_VOLUME_LABEL = 'Sony Reader Storage Card' STORAGE_CARD_VOLUME_LABEL = 'Sony Reader Storage Card'
OSX_MAIN_NAME = 'Sony PRS-505/UC Media' OSX_NAME = 'Sony PRS-505'
OSX_SD_NAME = 'Sony PRS-505/UC:SD Media'
OSX_MS_NAME = 'Sony PRS-505/UC:MS Media'
CARD_PATH_PREFIX = __appname__ CARD_PATH_PREFIX = __appname__
@ -101,29 +99,42 @@ class PRS505(Device):
return True return True
return False return False
@classmethod
def get_osx_mountpoints(cls, raw=None):
if raw is None:
raw = subprocess.Popen('ioreg -w 0 -S -c IOMedia'.split(),
stdout=subprocess.PIPE).stdout.read()
lines = raw.splitlines()
names = {}
for i, line in enumerate(lines):
if line.strip().endswith('<class IOMedia>') and cls.OSX_NAME in line:
loc = 'stick' if ':MS' in line else 'card' if ':SD' in line else 'main'
for line in lines[i+1:]:
line = line.strip()
if line.endswith('}'):
break
match = re.search(r'"BSD Name"\s+=\s+"(.*?)"', line)
if match is not None:
names[loc] = match.group(1)
break
if len(names.keys()) == 3:
break
return names
def open_osx(self): def open_osx(self):
mount = subprocess.Popen('mount', shell=True, mount = subprocess.Popen('mount', shell=True,
stdout=subprocess.PIPE).stdout.read() stdout=subprocess.PIPE).stdout.read()
src = subprocess.Popen('ioreg -n "%s"'%(self.OSX_MAIN_NAME,), names = self.get_osx_mountpoints()
shell=True, stdout=subprocess.PIPE).stdout.read() dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+'
try: if 'main' not in names.keys():
devname = re.search(r'BSD Name.*=\s+"(\S+)"', src).group(1)
self._main_prefix = re.search('/dev/%s(\w*)\s+on\s+([^\(]+)\s+'%(devname,), mount).group(2) + os.sep
except:
raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__) raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__)
try: main_pat = dev_pat%names['main']
src = subprocess.Popen('ioreg -n "%s"'%(self.OSX_SD_NAME,), self._main_prefix = re.search(main_pat, mount).group(2) + os.sep
shell=True, stdout=subprocess.PIPE).stdout.read() card_pat = names['stick'] if 'stick' in names.keys() else names['card'] if 'card' in names.keys() else None
devname = re.search(r'BSD Name.*=\s+"(\S+)"', src).group(1) if card_pat is not None:
except: card_pat = dev_pat%card_pat
try: self._card_prefix = re.search(card_pat, mount).group(2) + os.sep
src = subprocess.Popen('ioreg -n "%s"'%(self.OSX_MS_NAME,),
shell=True, stdout=subprocess.PIPE).stdout.read()
devname = re.search(r'BSD Name.*=\s+"(\S+)"', src).group(1)
except:
devname = None
if devname is not None:
self._card_prefix = re.search('/dev/%s(\w*)\s+on\s+([^\(]+)\s+'%(devname,), mount).group(2) + os.sep
def open_windows_nowmi(self): def open_windows_nowmi(self):
@ -280,8 +291,15 @@ class PRS505(Device):
if prefix is None: if prefix is None:
return 0, 0 return 0, 0
win32file = __import__('win32file', globals(), locals(), [], -1) win32file = __import__('win32file', globals(), locals(), [], -1)
try:
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \ sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
win32file.GetDiskFreeSpace(prefix[:-1]) win32file.GetDiskFreeSpace(prefix[:-1])
except Exception, err:
if getattr(err, 'args', [None])[0] == 21: # Disk not ready
time.sleep(3)
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
win32file.GetDiskFreeSpace(prefix[:-1])
else: raise
mult = sectors_per_cluster * bytes_per_sector mult = sectors_per_cluster * bytes_per_sector
return total_clusters * mult, free_clusters * mult return total_clusters * mult, free_clusters * mult

View File

@ -79,15 +79,12 @@ Library Management
What formats does |app| read metadata from? What formats does |app| read metadata from?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|app| reads metadata from the following formats: LRF, PDF, LIT, RTF, OPF, MOBI, PRC, EPUB. In addition it can write metadata to: LRF, RTF, OPF |app| reads metadata from the following formats: LRF, PDF, LIT, RTF, OPF, MOBI, PRC, EPUB, FB2, IMP, RB, HTML. In addition it can write metadata to: LRF, RTF, OPF
Where are the book files stored? Where are the book files stored?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|app| use a database to store all books. When you import new books or convert an existing book, the book files are stored in compressed form in the database. The database is a single file named `library1.db` and you can see where it is (or change its location) by clicking the configuration button (the button with the icon of a hammer next to the search bar). When you first run |app|, it will ask you for a folder in which to store your books. Whenever you add a book to |app|, it will copy the book into that folder. Books in the folder are nicely arranged into sub-folders by Author and Title. Metadata about the books is stored in the file ``metadata.db`` (which is a sqlite database).
Can I save my books to the disk?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can save your books to the disk by selecting the books and clicking the "Save to disk" button. Your books will be saved in nicely organized folders.
Content From The Web Content From The Web
--------------------- ---------------------