Added rename function

Wanted to move a file, but didn't want to use os.
This commit is contained in:
James Albert 2013-06-16 21:05:04 -06:00
parent aeefe2f894
commit 1e304d0b0a

View File

@ -925,6 +925,22 @@ def symlink(src, link):
raise CommandExecutionError('Could not create "{0}"'.format(link))
return False
def rename(src, dst):
'''
Rename a file or directory
CLI Example
salt '*' file.rename /path/to/src /path/to/dst
'''
if not os.path.isabs(src):
raise SaltInvocationError('File path must be absolute.')
try:
os.rename(src, dst)
return True
except OSError:
raise CommandExecutionError('Could not rename "{0}" to "{1}"'.format(src, dst))
return False
def stats(path, hash_type='md5', follow_symlink=False):
'''
Return a dict containing the stats for a given file