From 04a5bf16bd7a5e52ea0f772eaae4b8decf1ee95f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 5 Sep 2008 12:53:14 -0700 Subject: [PATCH] Make PRS505 mount point detection more robust on windows and osx --- src/calibre/constants.py | 2 +- src/calibre/devices/prs505/driver.py | 64 ++++++++++++++++++---------- src/calibre/manual/faq.rst | 7 +-- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/calibre/constants.py b/src/calibre/constants.py index dde7a4d7e9..3fd76f21d9 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -2,7 +2,7 @@ __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __appname__ = 'calibre' -__version__ = '0.4.84b8' +__version__ = '0.4.84b9' __author__ = "Kovid Goyal " ''' Various run time constants. diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index 5fc2b0c1cd..a33b85a7dc 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -39,9 +39,7 @@ class PRS505(Device): MAIN_MEMORY_VOLUME_LABEL = 'Sony Reader Main Memory' STORAGE_CARD_VOLUME_LABEL = 'Sony Reader Storage Card' - OSX_MAIN_NAME = 'Sony PRS-505/UC Media' - OSX_SD_NAME = 'Sony PRS-505/UC:SD Media' - OSX_MS_NAME = 'Sony PRS-505/UC:MS Media' + OSX_NAME = 'Sony PRS-505' CARD_PATH_PREFIX = __appname__ @@ -101,29 +99,42 @@ class PRS505(Device): return True 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('') 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): mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read() - src = subprocess.Popen('ioreg -n "%s"'%(self.OSX_MAIN_NAME,), - shell=True, stdout=subprocess.PIPE).stdout.read() - try: - 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: + names = self.get_osx_mountpoints() + dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+' + if 'main' not in names.keys(): raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__) - try: - src = subprocess.Popen('ioreg -n "%s"'%(self.OSX_SD_NAME,), - shell=True, stdout=subprocess.PIPE).stdout.read() - devname = re.search(r'BSD Name.*=\s+"(\S+)"', src).group(1) - except: - try: - 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 + main_pat = dev_pat%names['main'] + self._main_prefix = re.search(main_pat, mount).group(2) + os.sep + card_pat = names['stick'] if 'stick' in names.keys() else names['card'] if 'card' in names.keys() else None + if card_pat is not None: + card_pat = dev_pat%card_pat + self._card_prefix = re.search(card_pat, mount).group(2) + os.sep def open_windows_nowmi(self): @@ -280,8 +291,15 @@ class PRS505(Device): if prefix is None: return 0, 0 win32file = __import__('win32file', globals(), locals(), [], -1) - sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \ + try: + sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \ 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 return total_clusters * mult, free_clusters * mult diff --git a/src/calibre/manual/faq.rst b/src/calibre/manual/faq.rst index bf8a8723ef..9bfb0e225a 100644 --- a/src/calibre/manual/faq.rst +++ b/src/calibre/manual/faq.rst @@ -79,15 +79,12 @@ Library Management 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -|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 ---------------------