Skip to content

Commit a472663

Browse files
committed
Set %DesktopDir% as the default path if the Windows variable is unknown
1 parent 9424c2c commit a472663

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

gpoa/util/windows.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import ipaddress
4747
import netifaces
4848
import random
49+
import re
4950

5051
class smbcreds (smbopts):
5152

@@ -327,9 +328,11 @@ def expand_windows_var(text, username=None):
327328

328329
result = text
329330
for var in variables.keys():
330-
result = result.replace('%{}%'.format(var),
331-
variables[var] if variables[var][-1] == '/'
332-
else variables[var] +'/')
331+
if var in result:
332+
result = result.replace('%{}%'.format(var), variables[var] if variables[var][-1] == '/' else variables[var] +'/')
333+
else:
334+
default_path = re.sub(r'%[^%]+%', f"%{var}%", result)
335+
return default_path.replace('%{}%'.format(var), variables['DesktopDir'] if variables['DesktopDir'][-1] == '/' else variables['DesktopDir'] +'/')
333336

334337
return result
335338

0 commit comments

Comments
 (0)