我正在使用Python脚本装载osx卷。当卷已装入时(因此脚本无法装载到本地目录),如何防止出现错误?在
def volumeMounter(remote_dir, local_dir):
# Create local dir if it does not exist
if not os.path.exists( local_dir ):
os.makedirs( local_dir )
local_dir = os.path.abspath(local_dir)
# Attempt mounting of server share
retcode = subprocess.call(["/sbin/mount", "-t", "smbfs", remote_dir, local_dir])
if retcode != 0:
raise OSError("Mount operation failed")
你有几个比赛条件。Pythonic(和系统管理)原则是请求原谅比请求许可更容易。在这种情况下,这意味着最好尝试某个操作并检查其结果,而不是试图猜测该操作是否可能成功。在
您可以在/Volumes处检查装载路径,如下所示:
相关问题 更多 >
编程相关推荐