3
3
from pathlib import Path
4
4
5
5
def mountShare (networkPath , shareName = None , hiddenShare = False , username = None ):
6
+ """
7
+ Mount a given path of a samba share
8
+
9
+ :param networkPath: Network path of the share
10
+ :type networkPath: str
11
+ :param shareName: The name of the share (name of the folder the share is being mounted to)
12
+ :type shareName: str
13
+ :param hiddenShare: If the share sould be visible in Nautilus
14
+ :type hiddenShare: bool
15
+ :param username: The user in whoms context the share should be mounted
16
+ :type username: str
17
+ :return: Tuple: (success, mountpoint)
18
+ :rtype: tuple
19
+ """
6
20
networkPath = networkPath .replace ("\\ " , "/" )
7
21
username = _getDefaultUsername (username )
8
22
shareName = _getDefaultShareName (networkPath , shareName )
@@ -15,6 +29,23 @@ def mountShare(networkPath, shareName = None, hiddenShare = False, username = No
15
29
return _mountShareWithoutRoot (networkPath , shareName , hiddenShare ), mountpoint
16
30
17
31
def getMountpointOfRemotePath (remoteFilePath , hiddenShare = False , username = None , autoMount = True ):
32
+ """
33
+ Get the local path of a remote samba share path.
34
+ This function automatically checks if the shares is already mounted.
35
+ It optionally automatically mounts the top path of the remote share:
36
+ If the remote path is `//server/sysvol/linuxmuster.lan/Policies` it mounts `//server/sysvol`
37
+
38
+ :param remoteFilePath: Remote path
39
+ :type remoteFilePath: str
40
+ :param hiddenShare: If the share sould be visible in Nautilus
41
+ :type hiddenShare: bool
42
+ :param username: The user in whoms context the share should be mounted
43
+ :type username: str
44
+ :parama autoMount: If the share should be mouted automatically if it is not already mounted
45
+ :type autoMount: bool
46
+ :return: Tuple: (success, mountpoint)
47
+ :rtype: tuple
48
+ """
18
49
remoteFilePath = remoteFilePath .replace ("\\ " , "/" )
19
50
username = _getDefaultUsername (username )
20
51
@@ -41,6 +72,14 @@ def getMountpointOfRemotePath(remoteFilePath, hiddenShare = False, username = No
41
72
return True , localFilePath
42
73
43
74
def unmountAllSharesOfUser (username ):
75
+ """
76
+ Unmount all shares of a given user and safely delete the mountpoints and the parent directory.
77
+
78
+ :param username: The username of the user
79
+ :type username: str
80
+ :return: True or False
81
+ :rtype: bool
82
+ """
44
83
logging .info ("=== Trying to unmount all shares of user {0} ===" .format (username ))
45
84
for basedir in [constants .shareMountBasepath , constants .hiddenShareMountBasepath ]:
46
85
shareMountBasedir = basedir .format (username )
@@ -56,7 +95,7 @@ def unmountAllSharesOfUser(username):
56
95
57
96
if len (os .listdir (shareMountBasedir )) > 0 :
58
97
logging .warning ("* Mount basedir {} is not empty so not removed!" .format (shareMountBasedir ))
59
- return
98
+ return False
60
99
else :
61
100
# Delete the directory
62
101
logging .info ("Deleting {0}..." .format (shareMountBasedir ))
@@ -65,10 +104,18 @@ def unmountAllSharesOfUser(username):
65
104
except Exception as e :
66
105
logging .error ("FAILED!" )
67
106
logging .exception (e )
107
+ return False
68
108
69
109
logging .info ("===> Finished unmounting all shares of user {0} ===" .format (username ))
110
+ return True
70
111
71
112
def getLocalSysvolPath ():
113
+ """
114
+ Get the local mountpoint of the sysvol
115
+
116
+ :return: Full path of the mountpoint
117
+ :rtype: str
118
+ """
72
119
rc , networkConfig = config .network ()
73
120
if not rc :
74
121
return False , None
0 commit comments