def _find_device_root(device_book):
'''
Given the full path to a book on the device, return the path to the Kindle device
eg. "C:\", "/Volumes/Kindle"
'''
device_root = None
if sys.platform == "win32":
device_root = os.path.join(device_book.split(os.sep)[0], os.sep)
elif sys.platform == "darwin" or "linux" in sys.platform:
# Find "documents" in path hierarchy, we want to include the first os.sep so slice one further than we find it
index = device_book.index("%sdocuments%s" % (os.sep, os.sep))
device_root = device_book[:index+1]
else:
raise EnvironmentError(errno.EINVAL, "Unknown platform %s" % (sys.platform))
magic_file = os.path.join(device_root, "system", "version.txt")
if os.path.exists(magic_file) and open(magic_file).readline().startswith("Kindle"):
return device_root
raise EnvironmentError(errno.ENOENT, "Kindle device not found (%s)" % (device_root))
评论列表
文章目录