Merge pull request #24305 from twangboy/win_path_docs

Added documentation, fixed formatting
This commit is contained in:
Justin Anderson 2015-06-04 13:40:54 -06:00
commit efba1a94b4

View file

@ -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: