See also
Check if a path exists, and is a symbolic link.
Get the mode (permissions) of a file or directory.
Returns a string such as '0755', representing permissions as an octal number.
Upload a template file.
This is a wrapper around fabric.contrib.files.upload_template() that adds some extra parameters.
If mkdir is True, then the remote directory will be created, as the current user or as user if specified.
If chown is True, then it will ensure that the current user (or user if specified) is the owner of the remote file.
Context manager to watch for changes to the contents of some files.
The filenames argument can be either a string (single filename) or a list (multiple filenames).
You can read the changed attribute at the end of the block to check if the contents of any of the watched files has changed.
You can also provide a callback that will be called at the end of the block if the contents of any of the watched files has changed.
Example using an explicit check:
from fabric.contrib.files import comment, uncomment
from fabtools.files import watch
from fabtools.services import restart
# Edit configuration file
with watch('/etc/daemon.conf') as config:
uncomment('/etc/daemon.conf', 'someoption')
comment('/etc/daemon.conf', 'otheroption')
# Restart daemon if needed
if config.changed:
restart('daemon')
Same example using a callback:
from functools import partial
from fabric.contrib.files import comment, uncomment
from fabtools.files import watch
from fabtools.services import restart
with watch('/etc/daemon.conf', callback=partial(restart, 'daemon')):
uncomment('/etc/daemon.conf', 'someoption')
comment('/etc/daemon.conf', 'otheroption')
Get the lines of a remote file, ignoring empty or commented ones
Return the time of last modification of path. The return value is a number giving the number of seconds since the epoch
Same as os.path.getmtime()