diff --git a/src/calibre/devices/prs500/cli/main.py b/src/calibre/devices/prs500/cli/main.py index 74529c6d58..7603acb98a 100755 --- a/src/calibre/devices/prs500/cli/main.py +++ b/src/calibre/devices/prs500/cli/main.py @@ -180,7 +180,8 @@ def main(): if not cols: # On windows terminal width is unknown cols = 80 - parser = OptionParser(usage="usage: %prog [options] command args\n\ncommand is one of: info, books, df, ls, cp, mkdir, touch, cat, rm\n\n"+ + parser = OptionParser(usage="usage: %prog [options] command args\n\ncommand "+ + "is one of: info, books, df, ls, cp, mkdir, touch, cat, rm, eject\n\n"+ "For help on a particular command: %prog command", version=__appname__+" version: " + __version__) parser.add_option("--log-packets", help="print out packet stream to stdout. "+\ "The numbers in the left column are byte offsets that allow the packet size to be read off easily.", @@ -222,6 +223,8 @@ def main(): for i in range(3): print "%-10s\t%s\t%s\t%s\t%s"%(where[i], human_readable(total[i]), human_readable(total[i]-free[i]), human_readable(free[i]),\ str(0 if total[i]==0 else int(100*(total[i]-free[i])/(total[i]*1.)))+"%") + elif command == 'eject': + dev.eject() elif command == "books": print "Books in main memory:" for book in dev.books(): diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index e1e8f3890c..c4819307a4 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -7,7 +7,7 @@ intended to be subclassed with the relevant parts implemented for a particular device. This class handles device detection. ''' -import os, subprocess, time, re, sys, glob +import os, subprocess, time, re, sys, glob, shutil from itertools import repeat from calibre.devices.interface import DevicePlugin @@ -548,13 +548,23 @@ class Device(DeviceConfig, DevicePlugin): drives = self.find_device_nodes() for drive in drives: if drive: - cmd = ['pumount'] + cmd = ['pumount', '-l'] try: p = subprocess.Popen(cmd + [drive]) except: pass while p.poll() is None: time.sleep(0.1) + if p.returncode == 0: + for x in ('_main_prefix', '_card_a_prefix', '_card_b_prefix'): + x = getattr(self, x, None) + if x is not None: + if x.startswith('/media/') and os.path.exists(x): + try: + shutil.rmtree(x) + except: + pass + def eject(self): if islinux: