Python API documentation (SDoc)

$TITLE
Modules

- M cuisine

Show: private protected

# Method __init__

`__init__( self, value=None )`
Undocumented

# str

`'CUISINE_MODE_LOCAL'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

# wrapper_descriptor

# 1.repr_() <==> repr(x)

# wrapper_descriptor

# 1.str_() <==> str(x)

# Class mode_local

Sets Cuisine into local mode, where run/sudo won't go through Fabric's API, but directly through a popen. This allows you to easily test your Cuisine scripts without using Fabric.

# Method __init__

`__init__( self, value=None )`
Undocumented

# bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

# Class mode_remote

Comes back to Fabric's API for run/sudo. This basically reverts the effect of calling `mode_local()`.

# Method __init__

`__init__( self, value=None )`
Undocumented

# str

`'CUISINE_MODE_SUDO'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Class mode_sudo

Cuisine functions will be executed with sudo.

# Method __init__

`__init__( self, value=None )`
Undocumented

# Class mode_user

Cuisine functions will be executed as the current user.

# Function _init

`_init( )`
Undocumented

# Function apt_get

`apt_get( cmd )`
Undocumented

# Function command_check

`command_check( command )`

Tests if the given command is available on the system.

# Function command_ensure

`command_ensure( command, package=None )`

Ensures that the given command is present, if not installs the package with the given name, which is the same as the command by default.

# Function connect

`connect( host, user='root' )`

Sets Fabric's current host to the given host. This is useful when using Cuisine in standalone.

# Function dir_attribs

`dir_attribs( location, mode=None, owner=None, group=None, recursive=False )`

Updates the mode/owner/group for the given remote directory.

# Function dir_ensure

`dir_ensure( location, recursive=False, mode=None, owner=None, group=None )`

Ensures that there is a remote directory at the given location, optionally updating its mode/owner/group.

If we are not updating the owner/group then this can be done as a single ssh call, so use that method, otherwise set owner/group after creation.

# Function dir_exists

`dir_exists( location )`

Tells if there is a remote directory at the given location.

# Function dir_remove

`dir_remove( location, recursive=True )`

Removes a directory

# Function dispatch

`dispatch( prefix=None )`

Dispatches the current function to specific implementation. The `prefix` parameter indicates the common option prefix, and the `select_[option]()` function will determine the function suffix.

For instance the package functions are defined like this:

{{{ @dispatch("package") def packageensure(...): ... def packageensureapt(...): ... def packageensure_yum(…): … }}}

and then when a user does

{{{ cuisine.selectpackage("yum") cuisine.packageensure(…) }}}

then the `dispatch` function will dispatch `package_ensure` to `package_ensure_yum`.

If your prefix is the first word of the function name before the first `_` then you can simply use `@dispatch` without parameters.

# Function file_append

`file_append( location, content, mode=None, owner=None, group=None )`

Appends the given content to the remote file at the given location, optionally updating its mode/owner/group.

# Function file_attribs

`file_attribs( location, mode=None, owner=None, group=None )`

Updates the mode/owner/group for the remote file at the given location.

# Function file_attribs_get

`file_attribs_get( location )`

Return mode, owner, and group for remote path. Return mode, owner, and group if remote path exists, `None` otherwise.

# Function file_ensure

`file_ensure( location, mode=None, owner=None, group=None, scp=False )`

Updates the mode/owner/group for the remote file at the given location.

# Function file_exists

`file_exists( location )`

Tests if there is a remote file at the given location.

# Function file_is_dir

`file_is_dir( location )`
Undocumented

# Function file_is_file

`file_is_file( location )`
Undocumented

# Function file_is_link

`file_is_link( location )`
Undocumented

# Function file_link

`file_link( source, destination, symbolic=True, mode=None, owner=None, group=None )`

Creates a (symbolic) link between source and destination on the remote host, optionally setting its mode/owner/group.

# Function file_local_read

`file_local_read( location )`

Reads a local file from the given location, expanding `~` and shell variables.

# Function file_md5

`file_md5( location )`

Returns the MD5 sum (as a hex string) for the remote file at the given location.

# Function file_read

`file_read( location )`

Reads the remote file at the given location.

# Function file_sha256

`file_sha256( location )`

Returns the SHA-256 sum (as a hex string) for the remote file at the given location.

# Function file_unlink

`file_unlink( path )`
Undocumented

# Function file_update

`file_update( location, updater= at 0x27d20c8> )`

Updates the content of the given by passing the existing content of the remote file at the given location to the `updater` function.

For instance, if you'd like to convert an existing file to all uppercase, simply do:

    file_update("/etc/myfile", lambda _:_.upper())

# Function file_upload

`file_upload( remote, local, sudo=None, scp=False )`

Uploads the local file to the remote location only if the remote location does not exists or the content are different.

# Function file_write

`file_write( location, content, mode=None, owner=None, group=None, sudo=None, check=True, scp=False )`

Writes the given content to the file at the given remote location, optionally setting mode/owner/group.

# Function group_check

`group_check( name )`

Checks if there is a group defined with the given name, returning its information as a `{"name":<str>,"gid":<str>,"members":<list[str]>}` or `None` if the group does not exists.

# Function group_create

`group_create( name, gid=None )`

Creates a group with the given name, and optionally given gid.

# Function group_ensure

`group_ensure( name, gid=None )`

Ensures that the group with the given name (and optional gid) exists.

# Function group_user_add

`group_user_add( group, user )`

Adds the given user/list of users to the given group/groups.

# Function group_user_check

`group_user_check( group, user )`

Checks if the given user is a member of the given group. It will return `False` if the group does not exist.

# Function group_user_del

`group_user_del( group, user )`

remove the given user from the given group.

# Function group_user_ensure

`group_user_ensure( group, user )`

Ensure that a given user is a member of a given group.

# Function is_local

`is_local( )`
Undocumented

# Function is_remote

`is_remote( )`
Undocumented

# Function is_sudo

`is_sudo( )`
Undocumented

# Function locale_check

`locale_check( locale )`
Undocumented

# Function locale_ensure

`locale_ensure( locale )`
Undocumented

# Function mode

`mode( key )`

Queries the given Cuisine mode (ie. MODELOCAL, MODESUDO)

# Function package_clean

`package_clean( *args, **kwargs )`

Clean the repository for un-needed files.

# Function package_clean_apt

`package_clean_apt( package=None )`
Undocumented

# Function package_clean_emerge

`package_clean_emerge( package=None )`
Undocumented

# Function package_clean_pacman

`package_clean_pacman( )`
Undocumented

# Function package_clean_pkgin

`package_clean_pkgin( package=None )`
Undocumented

# Function package_clean_yum

`package_clean_yum( package=None )`
Undocumented

# Function package_clean_zypper

`package_clean_zypper( )`
Undocumented

# Function package_ensure

`package_ensure( *args, **kwargs )`

Tests if the given package is installed, and installs it in case it's not already there. If `update` is true, then the package will be updated if it already exists.

# Function package_ensure_apt

`package_ensure_apt( package, update=False )`

Ensure apt packages are installed

# Function package_ensure_emerge

`package_ensure_emerge( package, update=False )`
Undocumented

# Function package_ensure_pacman

`package_ensure_pacman( package, update=False )`

Ensure apt packages are installed

# Function package_ensure_pkgin

`package_ensure_pkgin( package, update=False )`
Undocumented

# Function package_ensure_yum

`package_ensure_yum( package, update=False )`
Undocumented

# Function package_ensure_zypper

`package_ensure_zypper( package, update=False )`
Undocumented

# Function package_install

`package_install( *args, **kwargs )`

Installs the given package/list of package, optionally updating the package database.

# Function package_install_apt

`package_install_apt( package, update=False )`
Undocumented

# Function package_install_emerge

`package_install_emerge( package, update=False )`
Undocumented

# Function package_install_pacman

`package_install_pacman( package, update=False )`
Undocumented

# Function package_install_pkgin

`package_install_pkgin( package, update=False )`
Undocumented

# Function package_install_yum

`package_install_yum( package, update=False )`
Undocumented

# Function package_install_zypper

`package_install_zypper( package, update=False )`
Undocumented

# Function package_remove

`package_remove( *args, **kwargs )`

Remove package and optionally clean unused packages

# Function package_remove_apt

`package_remove_apt( package, autoclean=False )`
Undocumented

# Function package_remove_emerge

`package_remove_emerge( package, autoclean=False )`
Undocumented

# Function package_remove_pacman

`package_remove_pacman( package, autoclean=False )`
Undocumented

# Function package_update

`package_update( *args, **kwargs )`

Updates the package database (when no argument) or update the package or list of packages given as argument.

# Function package_update_apt

`package_update_apt( package=None )`
Undocumented

# Function package_update_emerge

`package_update_emerge( package=None )`
Undocumented

# Function package_update_pacman

`package_update_pacman( package=None )`
Undocumented

# Function package_update_pkgin

`package_update_pkgin( package=None )`
Undocumented

# Function package_update_yum

`package_update_yum( package=None )`
Undocumented

# Function package_update_zypper

`package_update_zypper( package=None )`
Undocumented

# Function package_upgrade

`package_upgrade( *args, **kwargs )`

Updates every package present on the system.

# Function package_upgrade_apt

`package_upgrade_apt( distupgrade=False )`
Undocumented

# Function package_upgrade_emerge

`package_upgrade_emerge( distupgrade=False )`
Undocumented

# Function package_upgrade_pacman

`package_upgrade_pacman( )`
Undocumented

# Function package_upgrade_pkgin

`package_upgrade_pkgin( )`
Undocumented

# Function package_upgrade_yum

`package_upgrade_yum( )`
Undocumented

# Function package_upgrade_zypper

`package_upgrade_zypper( )`
Undocumented

# Function process_find

`process_find( name, exact=False )`

Returns the pids of processes with the given name. If exact is `False` it will return the list of all processes that start with the given `name`.

# Function process_kill

`process_kill( name, signal=9, exact=False )`

Kills the given processes with the given name. If exact is `False` it will return the list of all processes that start with the given `name`.

# Function python_package_ensure

`python_package_ensure( *args, **kwargs )`

Tests if the given python package is installed, and installes it in case it's not already there.

# Function python_package_ensure_easy_install

`python_package_ensure_easy_install( package )`

The "package" argument, defines the name of the package that will be ensured.

# Function python_package_ensure_pip

`python_package_ensure_pip( package=None, r=None, pip=None )`

The "package" argument, defines the name of the package that will be ensured. The argument "r" referes to the requirements file that will be used by pip and is equivalent to the "-r" parameter of pip. Either "package" or "r" needs to be provided

# Function python_package_install

`python_package_install( *args, **kwargs )`

Installs the given python package/list of python packages.

# Function python_package_install_easy_install

`python_package_install_easy_install( package )`

The "package" argument, defines the name of the package that will be installed.

# Function python_package_install_pip

`python_package_install_pip( package=None, r=None, pip=None )`

The "package" argument, defines the name of the package that will be installed. The argument "r" referes to the requirements file that will be used by pip and is equivalent to the "-r" parameter of pip. Either "package" or "r" needs to be provided The optional argument "E" is equivalent to the "-E" parameter of pip. E is the path to a virtualenv. If provided, it will be added to the pip call.

# Function python_package_remove

`python_package_remove( *args, **kwargs )`

Removes the given python package.

# Function python_package_remove_easy_install

`python_package_remove_easy_install( package )`

The "package" argument, defines the name of the package that will be removed.

# Function python_package_remove_pip

`python_package_remove_pip( package, pip=None )`

The "package" argument, defines the name of the package that will be ensured. The argument "r" referes to the requirements file that will be used by pip and is equivalent to the "-r" parameter of pip. Either "package" or "r" needs to be provided

# Function python_package_upgrade

`python_package_upgrade( *args, **kwargs )`

Upgrades the defined python package.

# Function python_package_upgrade_easy_install

`python_package_upgrade_easy_install( package )`

The "package" argument, defines the name of the package that will be upgraded.

# Function python_package_upgrade_pip

`python_package_upgrade_pip( package )`

The "package" argument, defines the name of the package that will be upgraded.

# Function repository_ensure_apt

`repository_ensure_apt( repository )`
Undocumented

# Function repository_ensure_emerge

`repository_ensure_emerge( repository )`
Undocumented

# Function repository_ensure_pacman

`repository_ensure_pacman( repository )`
Undocumented

# Function repository_ensure_pkgin

`repository_ensure_pkgin( repository )`
Undocumented

# Function repository_ensure_yum

`repository_ensure_yum( repository )`
Undocumented

# Function repository_ensure_zypper

`repository_ensure_zypper( repository )`
Undocumented

# Function run

`run( *args, **kwargs )`

A wrapper to Fabric's run/sudo commands that takes into account the `MODE_LOCAL` and `MODE_SUDO` modes of Cuisine.

# Function run_local

`run_local( command, sudo=False, shell=True, pty=True, combine_stderr=None )`

Local implementation of fabric.api.run() using subprocess.

Note: pty option exists for function signature compatibility and is ignored.

# Function select_package

`select_package( selection=None )`

Selects the type of package subsystem to use (ex:apt, yum, zypper, pacman, or emerge).

# Function select_python_package

`select_python_package( selection=None )`
Undocumented

# Function ssh_authorize

`ssh_authorize( user, key )`

Adds the given key to the `.ssh/authorized_keys` for the given user.

# Function ssh_keygen

`ssh_keygen( user, keytype='dsa' )`

Generates a pair of ssh keys in the user's home .ssh directory.

# Function ssh_unauthorize

`ssh_unauthorize( user, key )`

Removes the given key to the `.ssh/authorized_keys` for the given user.

# Function sudo

`sudo( *args, **kwargs )`

A wrapper to Fabric's run/sudo commands, using the 'cuisine.MODE_SUDO' global to tell whether the command should be run as regular user or sudo.

# Function sudo_password

`sudo_password( password=None )`

Sets the password for the sudo command.

# Function system_uuid

`system_uuid( )`

Gets a machines UUID (Universally Unique Identifier).

# Function system_uuid_alias_add

`system_uuid_alias_add( )`

Adds system UUID alias to /etc/hosts. Some tools/processes rely/want the hostname as an alias in /etc/hosts e.g. `127.0.0.1 localhost <hostname>`.

# Function text_detect_eol

`text_detect_eol( text )`
Undocumented

# Function text_ensure_line

`text_ensure_line( text, *lines )`

Ensures that the given lines are present in the given text, otherwise appends the lines that are not already in the text at the end of it.

# Function text_get_line

`text_get_line( text, predicate )`

Returns the first line that matches the given predicate.

# Function text_normalize

`text_normalize( text )`

Converts tabs and spaces to single space and strips the text.

# Function text_nospace

`text_nospace( text )`

Converts tabs and spaces to single space and strips the text.

# Function text_replace_line

`text_replace_line( text, old, new, find= at 0x27c7848>, process= at 0x27c78c0> )`

Replaces lines equal to `old` with `new`, returning the new text and the count of replacements.

# Function text_strip_margin

`text_strip_margin( text, margin='|' )`
Undocumented

# Function text_template

`text_template( text, variables )`

Substitutes `${PLACEHOLDER}`s within the text with the corresponding values from variables.

# Function upstart_ensure

`upstart_ensure( name )`

Ensures that the given upstart service is running, restarting it if necessary.

# Function user_check

`user_check( name=None, uid=None, need_passwd=True )`

Checks if there is a user defined with the given name, returning its information as a `{"name":<str>,"uid":<str>,"gid":<str>,"home":<str>,"shell":<str>}` or `None` if the user does not exists. need_passwd (Boolean) indicates if password to be included in result or not. If set to True it parses `getent shadow` and needs sudo access

# Function user_create

`user_create( name, passwd=None, home=None, uid=None, gid=None, shell=None, uid_min=None, uid_max=None, encrypted_passwd=True, fullname=None, createhome=True )`

Creates the user with the given name, optionally giving a specific password/home/uid/gid/shell.

# Function user_ensure

`user_ensure( name, passwd=None, home=None, uid=None, gid=None, shell=None, fullname=None, encrypted_passwd=True )`

Ensures that the given users exists, optionally updating their passwd/home/uid/gid/shell.

# Function user_passwd

`user_passwd( name, passwd, encrypted_passwd=True )`

Sets the given user password. Password is expected to be encrypted by default.

# Function user_remove

`user_remove( name, rmhome=None )`

Removes the user with the given name, optionally removing the home directory and mail spool.

# dict

`{'python_package': ['easy_install', 'pip'], 'package': ['apt', 'yum', 'zypper', 'pacman', 'emerge', 'pkgin']}`

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

# str

`'DEBIAN_FRONTEND=noninteractive apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" '`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# dict

`{'python_package': 'pip', 'package': 'apt'}`

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

# str

`'\n'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# str

`'CUISINE_OPTION_PACKAGE'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# str

`'CUISINE_OPTION_PYTHON_PACKAGE'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# SRE_Pattern

Compiled regular expression objects

# str

`'CUISINE_SUDO_PASSWORD'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# str

`'0.6.4'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# str

`'\r\n'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Module cuisine

`cuisine` makes it easy to write automatic server installation and configuration recipes by wrapping common administrative tasks (installing packages, creating users and groups) in Python functions.

`cuisine` is designed to work with Fabric and provide all you need for getting your new server up and running in minutes.

Note, that right now, Cuisine only supports Debian-based Linux systems.

See also:

- Deploying Django with Fabric http://lethain.com/entry/2008/nov/04/deploying-django-with-fabric

- Notes on Python Fabric 0.9b1 http://www.saltycrane.com/blog/2009/10/notes-python-fabric-09b1`_

- EC2, fabric, and "err: stdin: is not a tty" http://blog.markfeeney.com/2009/12/ec2-fabric-and-err-stdin-is-not-tty.html`_

:copyright: (c) 2011-2013 by Sébastien Pierre. :license: BSD, see LICENSE for more details.

# Function python_package_upgrade

`python_package_upgrade( *args, **kwargs )`

Upgrades the defined python package.

# Function file_unlink

`file_unlink( path )`
Undocumented

# Function python_package_install_easy_install

`python_package_install_easy_install( package )`

The "package" argument, defines the name of the package that will be installed.

# Function text_ensure_line

`text_ensure_line( text, *lines )`

Ensures that the given lines are present in the given text, otherwise appends the lines that are not already in the text at the end of it.

# dict

`{'python_package': 'pip', 'package': 'apt'}`

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

# Function package_clean_apt

`package_clean_apt( package=None )`
Undocumented

# Function repository_ensure_apt

`repository_ensure_apt( repository )`
Undocumented

# Function package_upgrade_emerge

`package_upgrade_emerge( distupgrade=False )`
Undocumented

# Function package_install_pacman

`package_install_pacman( package, update=False )`
Undocumented

# Function system_uuid_alias_add

`system_uuid_alias_add( )`

Adds system UUID alias to /etc/hosts. Some tools/processes rely/want the hostname as an alias in /etc/hosts e.g. `127.0.0.1 localhost <hostname>`.

# Function upstart_ensure

`upstart_ensure( name )`

Ensures that the given upstart service is running, restarting it if necessary.

# Function package_update_apt

`package_update_apt( package=None )`
Undocumented

# Function package_ensure_emerge

`package_ensure_emerge( package, update=False )`
Undocumented

# Function select_package

`select_package( selection=None )`

Selects the type of package subsystem to use (ex:apt, yum, zypper, pacman, or emerge).

# Function is_sudo

`is_sudo( )`
Undocumented

# Function python_package_ensure_easy_install

`python_package_ensure_easy_install( package )`

The "package" argument, defines the name of the package that will be ensured.

# Function is_local

`is_local( )`
Undocumented

# Function is_remote

`is_remote( )`
Undocumented

# Function group_create

`group_create( name, gid=None )`

Creates a group with the given name, and optionally given gid.

# Function group_ensure

`group_ensure( name, gid=None )`

Ensures that the group with the given name (and optional gid) exists.

# Function file_write

`file_write( location, content, mode=None, owner=None, group=None, sudo=None, check=True, scp=False )`

Writes the given content to the file at the given remote location, optionally setting mode/owner/group.

# Function group_check

`group_check( name )`

Checks if there is a group defined with the given name, returning its information as a `{"name":<str>,"gid":<str>,"members":<list[str]>}` or `None` if the group does not exists.

# Function group_user_del

`group_user_del( group, user )`

remove the given user from the given group.

# Function group_user_ensure

`group_user_ensure( group, user )`

Ensure that a given user is a member of a given group.

# Function group_user_add

`group_user_add( group, user )`

Adds the given user/list of users to the given group/groups.

# Function group_user_check

`group_user_check( group, user )`

Checks if the given user is a member of the given group. It will return `False` if the group does not exist.

# Function file_md5

`file_md5( location )`

Returns the MD5 sum (as a hex string) for the remote file at the given location.

# Function file_read

`file_read( location )`

Reads the remote file at the given location.

# Function file_link

`file_link( source, destination, symbolic=True, mode=None, owner=None, group=None )`

Creates a (symbolic) link between source and destination on the remote host, optionally setting its mode/owner/group.

# Function file_local_read

`file_local_read( location )`

Reads a local file from the given location, expanding `~` and shell variables.

# Function file_update

`file_update( location, updater= at 0x27d20c8> )`

Updates the content of the given by passing the existing content of the remote file at the given location to the `updater` function.

For instance, if you'd like to convert an existing file to all uppercase, simply do:

    file_update("/etc/myfile", lambda _:_.upper())

# Function file_upload

`file_upload( remote, local, sudo=None, scp=False )`

Uploads the local file to the remote location only if the remote location does not exists or the content are different.

# Function file_sha256

`file_sha256( location )`

Returns the SHA-256 sum (as a hex string) for the remote file at the given location.

# Function locale_ensure

`locale_ensure( locale )`
Undocumented

# Function file_attribs_get

`file_attribs_get( location )`

Return mode, owner, and group for remote path. Return mode, owner, and group if remote path exists, `None` otherwise.

# Function file_ensure

`file_ensure( location, mode=None, owner=None, group=None, scp=False )`

Updates the mode/owner/group for the remote file at the given location.

# Function file_attribs

`file_attribs( location, mode=None, owner=None, group=None )`

Updates the mode/owner/group for the remote file at the given location.

# Function file_is_file

`file_is_file( location )`
Undocumented

# Function file_is_link

`file_is_link( location )`
Undocumented

# Function file_exists

`file_exists( location )`

Tests if there is a remote file at the given location.

# Function file_is_dir

`file_is_dir( location )`
Undocumented

# Function file_append

`file_append( location, content, mode=None, owner=None, group=None )`

Appends the given content to the remote file at the given location, optionally updating its mode/owner/group.

# Function dir_remove

`dir_remove( location, recursive=True )`

Removes a directory

# Function dispatch

`dispatch( prefix=None )`

Dispatches the current function to specific implementation. The `prefix` parameter indicates the common option prefix, and the `select_[option]()` function will determine the function suffix.

For instance the package functions are defined like this:

{{{ @dispatch("package") def packageensure(...): ... def packageensureapt(...): ... def packageensure_yum(…): … }}}

and then when a user does

{{{ cuisine.selectpackage("yum") cuisine.packageensure(…) }}}

then the `dispatch` function will dispatch `package_ensure` to `package_ensure_yum`.

If your prefix is the first word of the function name before the first `_` then you can simply use `@dispatch` without parameters.

# Function sudo

`sudo( *args, **kwargs )`

A wrapper to Fabric's run/sudo commands, using the 'cuisine.MODE_SUDO' global to tell whether the command should be run as regular user or sudo.

# Function package_install

`package_install( *args, **kwargs )`

Installs the given package/list of package, optionally updating the package database.

# Function command_check

`command_check( command )`

Tests if the given command is available on the system.

# Function command_ensure

`command_ensure( command, package=None )`

Ensures that the given command is present, if not installs the package with the given name, which is the same as the command by default.

# Function _init

`_init( )`
Undocumented

# Function apt_get

`apt_get( cmd )`
Undocumented

# Function dir_ensure

`dir_ensure( location, recursive=False, mode=None, owner=None, group=None )`

Ensures that there is a remote directory at the given location, optionally updating its mode/owner/group.

If we are not updating the owner/group then this can be done as a single ssh call, so use that method, otherwise set owner/group after creation.

# Function dir_exists

`dir_exists( location )`

Tells if there is a remote directory at the given location.

# Function connect

`connect( host, user='root' )`

Sets Fabric's current host to the given host. This is useful when using Cuisine in standalone.

# Function dir_attribs

`dir_attribs( location, mode=None, owner=None, group=None, recursive=False )`

Updates the mode/owner/group for the given remote directory.

# bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

# Class mode_sudo

Cuisine functions will be executed with sudo.

# Function package_update_emerge

`package_update_emerge( package=None )`
Undocumented

# Method __init__

`__init__( self, value=None )`
Undocumented

# Class mode_user

Cuisine functions will be executed as the current user.

# Method __init__

`__init__( self, value=None )`
Undocumented

# Method __init__

`__init__( self, value=None )`
Undocumented

# str

`'CUISINE_MODE_SUDO'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Class mode_local

Sets Cuisine into local mode, where run/sudo won't go through Fabric's API, but directly through a popen. This allows you to easily test your Cuisine scripts without using Fabric.

# Method __init__

`__init__( self, value=None )`
Undocumented

# Module cuisine

`cuisine` makes it easy to write automatic server installation and configuration recipes by wrapping common administrative tasks (installing packages, creating users and groups) in Python functions.

`cuisine` is designed to work with Fabric and provide all you need for getting your new server up and running in minutes.

Note, that right now, Cuisine only supports Debian-based Linux systems.

See also:

- Deploying Django with Fabric http://lethain.com/entry/2008/nov/04/deploying-django-with-fabric

- Notes on Python Fabric 0.9b1 http://www.saltycrane.com/blog/2009/10/notes-python-fabric-09b1`_

- EC2, fabric, and "err: stdin: is not a tty" http://blog.markfeeney.com/2009/12/ec2-fabric-and-err-stdin-is-not-tty.html`_

:copyright: (c) 2011-2013 by Sébastien Pierre. :license: BSD, see LICENSE for more details.

# wrapper_descriptor

# 1.repr_() <==> repr(x)

# wrapper_descriptor

# 1.str_() <==> str(x)

# str

`'CUISINE_MODE_LOCAL'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function package_clean_zypper

`package_clean_zypper( )`
Undocumented

# Function package_ensure_pkgin

`package_ensure_pkgin( package, update=False )`
Undocumented

# Function ssh_authorize

`ssh_authorize( user, key )`

Adds the given key to the `.ssh/authorized_keys` for the given user.

# Function package_update_zypper

`package_update_zypper( package=None )`
Undocumented

# Function user_remove

`user_remove( name, rmhome=None )`

Removes the user with the given name, optionally removing the home directory and mail spool.

# Function text_replace_line

`text_replace_line( text, old, new, find= at 0x27c7848>, process= at 0x27c78c0> )`

Replaces lines equal to `old` with `new`, returning the new text and the count of replacements.

# Function package_clean_pacman

`package_clean_pacman( )`
Undocumented

# Function repository_ensure_pacman

`repository_ensure_pacman( repository )`
Undocumented

# str

`'CUISINE_OPTION_PACKAGE'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function package_upgrade_pkgin

`package_upgrade_pkgin( )`
Undocumented

# Function python_package_remove

`python_package_remove( *args, **kwargs )`

Removes the given python package.

# Function package_install_yum

`package_install_yum( package, update=False )`
Undocumented

# Class mode_remote

Comes back to Fabric's API for run/sudo. This basically reverts the effect of calling `mode_local()`.

# Function user_check

`user_check( name=None, uid=None, need_passwd=True )`

Checks if there is a user defined with the given name, returning its information as a `{"name":<str>,"uid":<str>,"gid":<str>,"home":<str>,"shell":<str>}` or `None` if the user does not exists. need_passwd (Boolean) indicates if password to be included in result or not. If set to True it parses `getent shadow` and needs sudo access

# Function user_create

`user_create( name, passwd=None, home=None, uid=None, gid=None, shell=None, uid_min=None, uid_max=None, encrypted_passwd=True, fullname=None, createhome=True )`

Creates the user with the given name, optionally giving a specific password/home/uid/gid/shell.

# Function package_update_pacman

`package_update_pacman( package=None )`
Undocumented

# Function process_find

`process_find( name, exact=False )`

Returns the pids of processes with the given name. If exact is `False` it will return the list of all processes that start with the given `name`.

# str

`'CUISINE_SUDO_PASSWORD'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function python_package_install

`python_package_install( *args, **kwargs )`

Installs the given python package/list of python packages.

# Function python_package_upgrade_pip

`python_package_upgrade_pip( package )`

The "package" argument, defines the name of the package that will be upgraded.

# Function package_clean

`package_clean( *args, **kwargs )`

Clean the repository for un-needed files.

# Function system_uuid

`system_uuid( )`

Gets a machines UUID (Universally Unique Identifier).

# Function package_install_emerge

`package_install_emerge( package, update=False )`
Undocumented

# Function package_upgrade_yum

`package_upgrade_yum( )`
Undocumented

# str

`'CUISINE_OPTION_PYTHON_PACKAGE'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

mode_sudo
Inhertied Methods
≡constructor
Values
•MODE_KEY
•MODE_VALUE
Inhertied Values
≡string repr
≡string conversion

# Function repository_ensure_zypper

`repository_ensure_zypper( repository )`
Undocumented

# Function run_local

`run_local( command, sudo=False, shell=True, pty=True, combine_stderr=None )`

Local implementation of fabric.api.run() using subprocess.

Note: pty option exists for function signature compatibility and is ignored.

# Function package_ensure_apt

`package_ensure_apt( package, update=False )`

Ensure apt packages are installed

# bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

# Function package_update_pkgin

`package_update_pkgin( package=None )`
Undocumented

# Function user_ensure

`user_ensure( name, passwd=None, home=None, uid=None, gid=None, shell=None, fullname=None, encrypted_passwd=True )`

Ensures that the given users exists, optionally updating their passwd/home/uid/gid/shell.

# Function text_get_line

`text_get_line( text, predicate )`

Returns the first line that matches the given predicate.

# Function package_install_zypper

`package_install_zypper( package, update=False )`
Undocumented

# Function locale_check

`locale_check( locale )`
Undocumented

# Function python_package_remove_pip

`python_package_remove_pip( package, pip=None )`

The "package" argument, defines the name of the package that will be ensured. The argument "r" referes to the requirements file that will be used by pip and is equivalent to the "-r" parameter of pip. Either "package" or "r" needs to be provided

# Function package_upgrade_apt

`package_upgrade_apt( distupgrade=False )`
Undocumented

# str

`'DEBIAN_FRONTEND=noninteractive apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" '`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function ssh_keygen

`ssh_keygen( user, keytype='dsa' )`

Generates a pair of ssh keys in the user's home .ssh directory.

# Function package_ensure_yum

`package_ensure_yum( package, update=False )`
Undocumented

# Function package_clean_yum

`package_clean_yum( package=None )`
Undocumented
mode_remote
Inhertied Methods
≡constructor
Values
•MODE_KEY
•MODE_VALUE
Inhertied Values
≡string repr
≡string conversion

# Function python_package_ensure

`python_package_ensure( *args, **kwargs )`

Tests if the given python package is installed, and installes it in case it's not already there.

# str

`'\r\n'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function select_python_package

`select_python_package( selection=None )`
Undocumented

# Function package_ensure_pacman

`package_ensure_pacman( package, update=False )`

Ensure apt packages are installed

# Function package_remove

`package_remove( *args, **kwargs )`

Remove package and optionally clean unused packages

# Function text_normalize

`text_normalize( text )`

Converts tabs and spaces to single space and strips the text.

# Function repository_ensure_yum

`repository_ensure_yum( repository )`
Undocumented

# Function user_passwd

`user_passwd( name, passwd, encrypted_passwd=True )`

Sets the given user password. Password is expected to be encrypted by default.

# Function package_update_yum

`package_update_yum( package=None )`
Undocumented

# Function repository_ensure_emerge

`repository_ensure_emerge( repository )`
Undocumented

# Function package_clean_emerge

`package_clean_emerge( package=None )`
Undocumented

# Function package_ensure_zypper

`package_ensure_zypper( package, update=False )`
Undocumented

# Function ssh_unauthorize

`ssh_unauthorize( user, key )`

Removes the given key to the `.ssh/authorized_keys` for the given user.

mode_local
Inhertied Methods
≡constructor
Values
•MODE_KEY
•MODE_VALUE
Inhertied Values
≡string repr
≡string conversion

# Function python_package_install_pip

`python_package_install_pip( package=None, r=None, pip=None )`

The "package" argument, defines the name of the package that will be installed. The argument "r" referes to the requirements file that will be used by pip and is equivalent to the "-r" parameter of pip. Either "package" or "r" needs to be provided The optional argument "E" is equivalent to the "-E" parameter of pip. E is the path to a virtualenv. If provided, it will be added to the pip call.

# Function text_detect_eol

`text_detect_eol( text )`
Undocumented

# Function package_install_pkgin

`package_install_pkgin( package, update=False )`
Undocumented

# Function package_remove_emerge

`package_remove_emerge( package, autoclean=False )`
Undocumented
mode_user
Inhertied Methods
≡constructor
Values
•MODE_KEY
•MODE_VALUE
Inhertied Values
≡string repr
≡string conversion

# SRE_Pattern

Compiled regular expression objects

# Function package_upgrade_zypper

`package_upgrade_zypper( )`
Undocumented

# Function python_package_ensure_pip

`python_package_ensure_pip( package=None, r=None, pip=None )`

The "package" argument, defines the name of the package that will be ensured. The argument "r" referes to the requirements file that will be used by pip and is equivalent to the "-r" parameter of pip. Either "package" or "r" needs to be provided

# Function mode

`mode( key )`

Queries the given Cuisine mode (ie. MODELOCAL, MODESUDO)

# Function python_package_upgrade_easy_install

`python_package_upgrade_easy_install( package )`

The "package" argument, defines the name of the package that will be upgraded.

# Function text_nospace

`text_nospace( text )`

Converts tabs and spaces to single space and strips the text.

# Function package_remove_apt

`package_remove_apt( package, autoclean=False )`
Undocumented

# Function package_upgrade_pacman

`package_upgrade_pacman( )`
Undocumented

# str

`'\n'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function package_ensure

`package_ensure( *args, **kwargs )`

Tests if the given package is installed, and installs it in case it's not already there. If `update` is true, then the package will be updated if it already exists.

# Function run

`run( *args, **kwargs )`

A wrapper to Fabric's run/sudo commands that takes into account the `MODE_LOCAL` and `MODE_SUDO` modes of Cuisine.

# Function text_strip_margin

`text_strip_margin( text, margin='|' )`
Undocumented

# Function package_remove_pacman

`package_remove_pacman( package, autoclean=False )`
Undocumented

# str

`'0.6.4'`

str(object='') -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

# Function process_kill

`process_kill( name, signal=9, exact=False )`

Kills the given processes with the given name. If exact is `False` it will return the list of all processes that start with the given `name`.

# Function package_install_apt

`package_install_apt( package, update=False )`
Undocumented

# Function sudo_password

`sudo_password( password=None )`

Sets the password for the sudo command.

# dict

`{'python_package': ['easy_install', 'pip'], 'package': ['apt', 'yum', 'zypper', 'pacman', 'emerge', 'pkgin']}`

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

# Function package_upgrade

`package_upgrade( *args, **kwargs )`

Updates every package present on the system.

cuisine
Classes
Τ mode_local
Τ mode_remote
Τ mode_sudo
Τ mode_user
Functions
λ _init
λ apt_get
λ command_check
λ command_ensure
λ connect
λ dir_attribs
λ dir_ensure
λ dir_exists
λ dir_remove
λ dispatch
λ file_append
λ file_attribs
λ file_attribs_get
λ file_ensure
λ file_exists
λ file_is_dir
λ file_is_file
λ file_is_link
λ file_link
λ file_local_read
λ file_md5
λ file_read
λ file_sha256
λ file_unlink
λ file_update
λ file_upload
λ file_write
λ group_check
λ group_create
λ group_ensure
λ group_user_add
λ group_user_check
λ group_user_del
λ group_user_ensure
λ is_local
λ is_remote
λ is_sudo
λ locale_check
λ locale_ensure
λ mode
λ package_clean
λ package_clean_apt
λ package_clean_emerge
λ package_clean_pacman
λ package_clean_pkgin
λ package_clean_yum
λ package_clean_zypper
λ package_ensure
λ package_ensure_apt
λ package_ensure_emerge
λ package_ensure_pacman
λ package_ensure_pkgin
λ package_ensure_yum
λ package_ensure_zypper
λ package_install
λ package_install_apt
λ package_install_emerge
λ package_install_pacman
λ package_install_pkgin
λ package_install_yum
λ package_install_zypper
λ package_remove
λ package_remove_apt
λ package_remove_emerge
λ package_remove_pacman
λ package_update
λ package_update_apt
λ package_update_emerge
λ package_update_pacman
λ package_update_pkgin
λ package_update_yum
λ package_update_zypper
λ package_upgrade
λ package_upgrade_apt
λ package_upgrade_emerge
λ package_upgrade_pacman
λ package_upgrade_pkgin
λ package_upgrade_yum
λ package_upgrade_zypper
λ process_find
λ process_kill
λ python_package_ensure
λ python_package_ensure_easy_install
λ python_package_ensure_pip
λ python_package_install
λ python_package_install_easy_install
λ python_package_install_pip
λ python_package_remove
λ python_package_remove_easy_install
λ python_package_remove_pip
λ python_package_upgrade
λ python_package_upgrade_easy_install
λ python_package_upgrade_pip
λ repository_ensure_apt
λ repository_ensure_emerge
λ repository_ensure_pacman
λ repository_ensure_pkgin
λ repository_ensure_yum
λ repository_ensure_zypper
λ run
λ run_local
λ select_package
λ select_python_package
λ ssh_authorize
λ ssh_keygen
λ ssh_unauthorize
λ sudo
λ sudo_password
λ system_uuid
λ system_uuid_alias_add
λ text_detect_eol
λ text_ensure_line
λ text_get_line
λ text_normalize
λ text_nospace
λ text_replace_line
λ text_strip_margin
λ text_template
λ upstart_ensure
λ user_check
λ user_create
λ user_ensure
λ user_passwd
λ user_remove
Values
•AVAILABLE_OPTIONS
•CMD_APT_GET
•DEFAULT_OPTIONS
•MAC_EOL
•MODE_LOCAL
•MODE_SUDO
•OPTION_PACKAGE
•OPTION_PYTHON_PACKAGE
•RE_SPACES
•SUDO_PASSWORD
•UNIX_EOL
•VERSION
•WINDOWS_EOL

# Function package_update

`package_update( *args, **kwargs )`

Updates the package database (when no argument) or update the package or list of packages given as argument.

# Function text_template

`text_template( text, variables )`

Substitutes `${PLACEHOLDER}`s within the text with the corresponding values from variables.

# Function python_package_remove_easy_install

`python_package_remove_easy_install( package )`

The "package" argument, defines the name of the package that will be removed.

# Function repository_ensure_pkgin

`repository_ensure_pkgin( repository )`
Undocumented

# Function package_clean_pkgin

`package_clean_pkgin( package=None )`
Undocumented