Skip to content

Commit 98fa030

Browse files
committed
Chore: use template only for letter
1 parent d740ae2 commit 98fa030

File tree

9 files changed

+25
-26
lines changed

9 files changed

+25
-26
lines changed

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def shares():
3131
if config is not None and "shares" in config:
3232
sharesConfig = config["shares"]
3333

34-
if not "nameTemplate" in sharesConfig:
35-
sharesConfig["nameTemplate"] = constants.defaultShareNameTemplate
34+
if not "letterTemplate" in sharesConfig:
35+
sharesConfig["letterTemplate"] = constants.defaultShareLetterTemplate
3636

3737
return sharesConfig
3838

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
shareMountBasepath = "/home/{}/media"
1111
hiddenShareMountBasepath = "/srv/samba/{}"
1212
machineAccountSysvolMountPath = "/var/lib/samba/sysvol"
13-
defaultShareNameTemplate = "{label} ({letter}:)"
13+
defaultShareLetterTemplate = " ({letter}:)"
1414

1515
etcBaseDir = "/etc/linuxmuster-linuxclient7"
1616
shareBaseDir = "/usr/share/linuxmuster-linuxclient7"

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/gpo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ def _processDrivesPolicy(policyBasepath):
239239

240240
for drive in shareList:
241241
if drive["useLetter"] == "1":
242-
nameTemplate = config.shares()["nameTemplate"]
243-
shareName = nameTemplate.format(label=drive['label'], letter=drive['letter'])
242+
formattedLetter = config.shares()["letterTemplate"].format(letter=drive['letter'])
243+
shareName = f"{drive['label']}{formattedLetter}"
244244
else:
245245
shareName = drive["label"]
246246

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/files/config/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
shares:
2-
nameTemplate: "{label}_{letter}"
2+
letterTemplate: "_{letter}"
33

44
network:
55
serverHostname: server.linuxmuster.lan

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ def test_network_invalid():
5050
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"{MOCK_FILE_PATH}/config.yml")
5151
def test_shares():
5252
sharesConfig = config.shares()
53-
assert "nameTemplate" in sharesConfig
54-
assert sharesConfig["nameTemplate"] == "{label}_{letter}"
53+
assert "letterTemplate" in sharesConfig
54+
assert sharesConfig["letterTemplate"] == "_{letter}"
5555

5656
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf")
5757
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/does/not/exist/config.yml")
5858
def test_shares_none():
5959
sharesConfig = config.shares()
60-
assert "nameTemplate" in sharesConfig
61-
assert sharesConfig["nameTemplate"] == config.constants.defaultShareNameTemplate
60+
assert "letterTemplate" in sharesConfig
61+
assert sharesConfig["letterTemplate"] == config.constants.defaultShareLetterTemplate
6262

6363
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf")
6464
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"{MOCK_FILE_PATH}/config.no-shares.yml")
6565
def test_shares_missing():
6666
sharesConfig = config.shares()
67-
assert "nameTemplate" in sharesConfig
68-
assert sharesConfig["nameTemplate"] == config.constants.defaultShareNameTemplate
67+
assert "letterTemplate" in sharesConfig
68+
assert sharesConfig["letterTemplate"] == config.constants.defaultShareLetterTemplate
6969

7070
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf")
7171
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"{MOCK_FILE_PATH}/config.invalid-syntax.yml")
@@ -91,7 +91,7 @@ def test_writeNetworkConfig():
9191
assert networkConfig["serverHostname"] == "server.linuxmuster.new"
9292
assert networkConfig["domain"] == "linuxmuster.new"
9393
assert networkConfig["realm"] == "LINUXMUSTER.NEW"
94-
assert config.shares() == {"nameTemplate": "{label}_{letter}"}
94+
assert config.shares() == {"letterTemplate": "_{letter}"}
9595

9696

9797
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/tmp/config.yml")
@@ -206,7 +206,7 @@ def test_deleteNetworkConfig():
206206
assert config.deleteNetworkConfig()
207207
assert os.path.exists("/tmp/config.yml")
208208
assert config.network() == (False, None)
209-
assert config.shares() == {"nameTemplate": "{label}_{letter}"}
209+
assert config.shares() == {"letterTemplate": "_{letter}"}
210210

211211
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf")
212212
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/does/not/exist/config.yml")

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_gpo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_allOkAllTrue(mockUserSchool, mockLdapHelperSearchOne, mockSharesGetMoun
5454
@mock.patch("linuxmusterLinuxclient7.gpo.shares.getMountpointOfRemotePath")
5555
@mock.patch("linuxmusterLinuxclient7.gpo.ldapHelper.searchOne")
5656
@mock.patch("linuxmusterLinuxclient7.gpo.user.school")
57-
def test_customShareNameTemplate(mockUserSchool, mockLdapHelperSearchOne, mockSharesGetMountpointOfRemotePath, mockSharesmMountShare, mockPrintersInstallPrinter, mockUserIsInGroup, mockComputerIsInGroup, mockConfigShares):
57+
def test_customShareLetterTemplate(mockUserSchool, mockLdapHelperSearchOne, mockSharesGetMountpointOfRemotePath, mockSharesmMountShare, mockPrintersInstallPrinter, mockUserIsInGroup, mockComputerIsInGroup, mockConfigShares):
5858
mockUserSchool.return_value = (True, "school1")
5959
mockLdapHelperSearchOne.return_value = (True, {
6060
"distinguishedName": "policy1",
@@ -66,7 +66,7 @@ def test_customShareNameTemplate(mockUserSchool, mockLdapHelperSearchOne, mockSh
6666
mockUserIsInGroup.return_value = True
6767
mockComputerIsInGroup.return_value = True
6868
mockConfigShares.return_value = {
69-
"nameTemplate": "{label}_{letter}"
69+
"letterTemplate": "_{letter}"
7070
}
7171

7272
assert gpo.processAllPolicies()
@@ -78,7 +78,7 @@ def test_customShareNameTemplate(mockUserSchool, mockLdapHelperSearchOne, mockSh
7878

7979
# Test without letter
8080
mockConfigShares.return_value = {
81-
"nameTemplate": "{label}"
81+
"letterTemplate": ""
8282
}
8383
assert gpo.processAllPolicies()
8484
assert len(mockSharesmMountShare.call_args_list) == 6

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ def test_getHomeShareMountpoint(mockUsername, mockReadAttributes):
140140
@mock.patch("linuxmusterLinuxclient7.gpo.config.shares")
141141
@mock.patch("linuxmusterLinuxclient7.user.readAttributes")
142142
@mock.patch("linuxmusterLinuxclient7.user.username")
143-
def test_getHomeShareMountpointCustomShareNameTemplate(mockUsername, mockReadAttributes, mockConfigShares):
143+
def test_getHomeShareMountpointCustomShareLetterTemplate(mockUsername, mockReadAttributes, mockConfigShares):
144144
mockUsername.return_value = "user1"
145145
mockReadAttributes.return_value = (True, {"homeDrive": "H:"})
146146
mockConfigShares.return_value = {
147-
"nameTemplate": "{label}_{letter}"
147+
"letterTemplate": "_{letter}"
148148
}
149149

150150
rc, homeShareMountpoint = user.getHomeShareMountpoint()
@@ -153,7 +153,7 @@ def test_getHomeShareMountpointCustomShareNameTemplate(mockUsername, mockReadAtt
153153

154154
# Test without letter
155155
mockConfigShares.return_value = {
156-
"nameTemplate": "{label}"
156+
"letterTemplate": ""
157157
}
158158
rc, homeShareMountpoint = user.getHomeShareMountpoint()
159159
assert rc

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def _getHomeShareName(userAttributes=None):
146146

147147
if rc:
148148
try:
149-
nameTemplate = config.shares()["nameTemplate"]
150149
letter = userAttributes['homeDrive'].replace(':', '')
151-
shareName = nameTemplate.format(label=username(), letter=letter)
150+
formattedLetter = config.shares()["letterTemplate"].format(letter=letter)
151+
shareName = f"{username()}{formattedLetter}"
152152
return True, shareName
153153

154154
except Exception as e:

wiki/Usage/Configuration.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
- using the linuxmuster-webui `client configuration -> Drives` menu
44
- using gpedit on a Windows client
55
- modifying the file `/var/lib/samba/sysvol/linuxmuster.lan/Policies/{someUUID}/User/Preferences/Drives/Drives.xml` on the linuxmuster server. (Replace `someUUID` with the UUID of the policy)
6-
- If you want to customize the naming of shares which have drive letters, you can use the `nameTemplate` parameter in the `shares`-section of the config file (`/etc/linuxmuster-linuxclient7/config.yml`):
6+
- If you want to customize how drive letters are formatted, you can use the `letterTemplate` parameter in the `shares`-section of the config file (`/etc/linuxmuster-linuxclient7/config.yml`):
77
```yaml
88
shares:
9-
nameTemplate: "{label} ({letter}:)"
9+
letterTemplate: " ({letter}:)"
1010
```
11-
- Shares without drive letters always have the label as a name
12-
- For the users home share, the label is the username
11+
- The letter template is directly appended to the share label
1312
1413
# Printers
1514
- Printers MUST have the same name in cups and devices.csv!

0 commit comments

Comments
 (0)