mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Delete mount dir after eject on linux if it is in /media. Also add eject command to ebook-device
This commit is contained in:
parent
1323f26b83
commit
c941abc652
@ -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():
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user