mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
Merge pull request #16845 from Tanoti/add-file.move-to-modules
Add 'move' to modules.file for #16842
This commit is contained in:
commit
9c42ced98a
@ -4197,3 +4197,37 @@ def join(*args):
|
||||
salt '*' file.join '/' 'usr' 'local' 'bin'
|
||||
'''
|
||||
return os.path.join(*args)
|
||||
|
||||
|
||||
def move(src, dst):
|
||||
'''
|
||||
Move a file or directory
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' file.move /path/to/src /path/to/dst
|
||||
'''
|
||||
src = os.path.expanduser(src)
|
||||
dst = os.path.expanduser(dst)
|
||||
|
||||
if not os.path.isabs(src):
|
||||
raise SaltInvocationError('Source path must be absolute.')
|
||||
|
||||
if not os.path.isabs(dst):
|
||||
raise SaltInvocationError('Destination path must be absolute.')
|
||||
|
||||
ret = {
|
||||
'result': True,
|
||||
'comment': "'{0}' moved to '{1}'".format(src, dst),
|
||||
}
|
||||
|
||||
try:
|
||||
shutil.move(src, dst)
|
||||
except (OSError, IOError) as exc:
|
||||
raise CommandExecutionError(
|
||||
"Unable to move '{0}' to '{1}': {2}".format(src, dst, exc)
|
||||
)
|
||||
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user