/
fs.py
37 lines (27 loc) · 1.18 KB
/
fs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Fabfile functions for ensuring the state the filesystem
"""
import cuisine
from fabric.api import run, sudo
from cuisine_sweet.utils import completed_ok
@completed_ok(arg_output=[0])
def dir_created(path, recursive=False, mode=None, owner=None, group=None):
"""
Ensure that the directory is created and with proper permissions.
Wraps ``cuisine.dir_ensure`` function
:param path: *required* str; path to the directory
:param recursive: bool; recursively create if not present
:param mode: int; octal mode passed to chmod (e.g. 755, 600)
:param owner: str; user/uid that should own the file, as passed to chown
:param group: str; user/uid that should own the file, as passed to chgrp
"""
cuisine.dir_ensure(name, recursive=recursive, mode=mode, owner=owner, group=group)
@completed_ok(arg_output=[0,1])
def dir_symlink_created(src, dest):
"""
Ensure that a symlink at `dest` pointing to `src` is created.
:param src: *required* str; path to the source real directory
:param dest: *required* str; path to the destination symlink
"""
run('ln -s %s %s >& /dev/null; true' % (src, dest))
run('test -L %s && test -d %s' % (dest, dest))