59 |
59 |
60 # check |
60 # check |
61 if not os.path.isdir(self.mnt) : |
61 if not os.path.isdir(self.mnt) : |
62 raise MountError("Mountpoint is not a directory: {mnt}".format(mnt=self.mnt)) |
62 raise MountError("Mountpoint is not a directory: {mnt}".format(mnt=self.mnt)) |
63 |
63 |
64 if os.path.ismount(self.mnt) : |
64 if self.is_mounted() : |
65 raise MountError("Mountpoint is already mounted: {mnt}".format(mnt=self.mnt)) |
65 raise MountError("Mountpoint is already mounted: {mnt}".format(mnt=self.mnt)) |
66 |
66 |
67 if not os.path.exists(self.dev) : |
67 if not os.path.exists(self.dev) : |
68 raise MountError("Device does not exist: {dev}".format(dev=self.dev)) |
68 raise MountError("Device does not exist: {dev}".format(dev=self.dev)) |
69 |
69 |
70 # mount |
70 # mount |
71 invoke(self.MOUNT, optargs(self.dev, self.mnt, options=self.options()), sudo=self.sudo) |
71 invoke(self.MOUNT, optargs(self.dev, self.mnt, options=self.options()), sudo=self.sudo) |
72 |
72 |
|
73 def is_mounted (self) : |
|
74 """ |
|
75 Test if the given mountpoint is mounted. |
|
76 """ |
|
77 |
|
78 # workaround http://bugs.python.org/issue2466 |
|
79 if os.path.exists(self.mnt) and not os.path.exists(os.path.join(self.mnt, '.')) : |
|
80 # this is a sign of a mountpoint that we do not have access to |
|
81 return True |
|
82 |
|
83 return os.path.ismount(self.mnt) |
|
84 |
73 def close (self) : |
85 def close (self) : |
74 """ |
86 """ |
75 Un-mount |
87 Un-mount |
76 """ |
88 """ |
77 |
89 |
78 # check |
90 # check |
79 if not os.path.ismount(self.mnt): |
91 if not self.is_mounted() : |
80 raise MountError("Mountpoint is not mounted: {mnt}".format(mnt=self.mnt)) |
92 raise MountError("Mountpoint is not mounted: {mnt}".format(mnt=self.mnt)) |
81 |
93 |
82 # umount |
94 # umount |
83 invoke(self.UMOUNT, optargs(self.mnt), sudo=self.sudo) |
95 invoke(self.UMOUNT, optargs(self.mnt), sudo=self.sudo) |
84 |
96 |