nuka.tasks.file

file related tasks

nuka.tasks.file.cat

nuka.tasks.file.cat(src=None, **kwargs)[source]

cat a file

Example:

res = await file.cat('/etc/default/useradd')
assert res.content

nuka.tasks.file.chmod

nuka.tasks.file.chmod(dst=None, mod='644', recursive=False, **kwargs)[source]

apply chmod to dst

nuka.tasks.file.chown

nuka.tasks.file.chown(dst=None, own='root:root', recursive=False, **kwargs)[source]

apply chown to dst

nuka.tasks.file.exists

nuka.tasks.file.exists(dst=None, **kwargs)[source]

return True if a path exists

Example:

res = await file.exists('/tmp')
assert bool(res) is True

res = await file.exists('/nope')
assert bool(res) is False

nuka.tasks.file.mkdir

nuka.tasks.file.mkdir(dst=None, mod=None, own=None, **kwargs)[source]

create a directory

Example:

if not await file.exists('/tmp/doc'):
    await file.mkdir('/tmp/doc')

nuka.tasks.file.mkdirs

nuka.tasks.file.mkdirs(directories=None, **kwargs)[source]

create directories

nuka.tasks.file.mv

nuka.tasks.file.mv(src=None, dst=None, **kwargs)[source]

rename/move a file or a directory

nuka.tasks.file.put

nuka.tasks.file.put(files=None, **kwargs)[source]

put files on the remote host

Example:

await file.put([
    dict(src='/etc/resolv.conf', dst='/tmp/resolv.conf'),
    dict(src='docs/utils.py', dst='/tmp/utils.py', executable=True),
    # jinja2 template
    dict(src='example.j2', dst='/tmp/xx1', mod='600'),
    # symlink
    dict(linkto='/etc/hosts', dst='/etc/hosts2'),
], ctx=dict(name='example'))

nuka.tasks.file.rm

nuka.tasks.file.rm(dst=None, **kwargs)[source]

rm a file or directory

Example:

await file.rm('/tmp/doc')

nuka.tasks.file.scripts

nuka.tasks.file.scripts(files=None, **kwargs)[source]

put and execute scripts on the remote host

nuka.tasks.file.update

nuka.tasks.file.update(dst=None, replaces=None, appends=None, **kwargs)[source]

update a file

Example:

await file.update(
    dst='/etc/default/useradd',
    replaces=[(r'^\# HOME=/home', 'HOME=/new_home')])