mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #24305 from twangboy/win_path_docs
Added documentation, fixed formatting
This commit is contained in:
commit
efba1a94b4
1 changed files with 42 additions and 6 deletions
|
@ -44,16 +44,35 @@ def _normalize_dir(string):
|
|||
|
||||
def rehash():
|
||||
'''
|
||||
Send a WM_SETTINGCHANGE Broadcast to Windows to rehash the Environment variables
|
||||
Send a WM_SETTINGCHANGE Broadcast to Windows to refresh the Environment variables
|
||||
|
||||
CLI Example:
|
||||
|
||||
... code-block:: bash
|
||||
|
||||
salt '*' win_path.rehash
|
||||
'''
|
||||
return win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment', 0, 10000)[0] == 1
|
||||
return win32gui.SendMessageTimeout(win32con.HWND_BROADCAST,
|
||||
win32con.WM_SETTINGCHANGE,
|
||||
0,
|
||||
'Environment',
|
||||
0,
|
||||
10000)[0] == 1
|
||||
|
||||
|
||||
def get_path():
|
||||
'''
|
||||
Returns the system path
|
||||
Returns a list of items in the SYSTEM path
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' win_path.get_path
|
||||
'''
|
||||
ret = __salt__['reg.read_key']('HKEY_LOCAL_MACHINE', 'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', 'PATH').split(';')
|
||||
ret = __salt__['reg.read_key']('HKEY_LOCAL_MACHINE',
|
||||
'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',
|
||||
'PATH').split(';')
|
||||
|
||||
# Trim ending backslash
|
||||
return map(_normalize_dir, ret)
|
||||
|
@ -64,6 +83,9 @@ def exists(path):
|
|||
Check if the directory is configured in the SYSTEM path
|
||||
Case-insensitive and ignores trailing backslash
|
||||
|
||||
Returns:
|
||||
boolean True if path exists, False if not
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -82,6 +104,9 @@ def add(path, index=0):
|
|||
'''
|
||||
Add the directory to the SYSTEM path in the index location
|
||||
|
||||
Returns:
|
||||
boolean True if successful, False if unsuccessful
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -121,7 +146,7 @@ def add(path, index=0):
|
|||
'PATH',
|
||||
';'.join(sysPath),
|
||||
'REG_EXPAND_SZ'
|
||||
)
|
||||
)
|
||||
|
||||
# Broadcast WM_SETTINGCHANGE to Windows
|
||||
if regedit:
|
||||
|
@ -131,11 +156,22 @@ def add(path, index=0):
|
|||
|
||||
|
||||
def remove(path):
|
||||
'''
|
||||
r'''
|
||||
Remove the directory from the SYSTEM path
|
||||
|
||||
Returns:
|
||||
boolean True if successful, False if unsuccessful
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Will remove C:\Python27 from the path
|
||||
salt '*' win_path.remove 'c:\\python27'
|
||||
'''
|
||||
path = _normalize_dir(path)
|
||||
sysPath = get_path()
|
||||
|
||||
try:
|
||||
sysPath.remove(path)
|
||||
except ValueError:
|
||||
|
|
Loading…
Add table
Reference in a new issue