From e42bf614130c81906c8ef237cdf042f08dca9245 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 8 Feb 2012 22:05:48 +0100 Subject: [PATCH] new type: __package_pip Signed-off-by: Nico Schottelius --- conf/type/__package_pip/explorer/state | 48 ++++++++++++++++++++ conf/type/__package_pip/gencode-remote | 50 ++++++++++++++++++++ conf/type/__package_pip/man.text | 53 ++++++++++++++++++++++ conf/type/__package_pip/parameter/optional | 1 + conf/type/__package_pip/parameter/required | 1 + 5 files changed, 153 insertions(+) create mode 100644 conf/type/__package_pip/explorer/state create mode 100644 conf/type/__package_pip/gencode-remote create mode 100644 conf/type/__package_pip/man.text create mode 100644 conf/type/__package_pip/parameter/optional create mode 100644 conf/type/__package_pip/parameter/required diff --git a/conf/type/__package_pip/explorer/state b/conf/type/__package_pip/explorer/state new file mode 100644 index 00000000..3a086e58 --- /dev/null +++ b/conf/type/__package_pip/explorer/state @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Development supported by Local AG (www.local.ch) +# + +nameparam="$__object/parameter/name" +if [ -f "$nameparam" ]; then + name=$(cat "$nameparam") +else + name="$__object_id" +fi + +pipparam="$__object/parameter/pip" +if [ -f "$pipparam" ]; then + pip=$(cat "$pipparam") +else + pip="pip" +fi + +# which is not posix, but command is :-) +if ! command -v "$pip" >/dev/null 2>&1; then + echo "No usable pip found at path \"$pip\"" >&2 + exit 1 +fi + +if "$pip" freeze | grep -i -q "^$name=="; then + echo present +else + echo absent +fi diff --git a/conf/type/__package_pip/gencode-remote b/conf/type/__package_pip/gencode-remote new file mode 100644 index 00000000..e60d74c5 --- /dev/null +++ b/conf/type/__package_pip/gencode-remote @@ -0,0 +1,50 @@ +#!/bin/sh +# +# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Development supported by Local AG (www.local.ch) +# + +state_is=$(cat "$__object/explorer/state") +state_should=$(cat "$__object/parameter/state") + +[ "$state_is" = "$state_should" ] && exit 0 + +nameparam="$__object/parameter/name" +if [ -f "$nameparam" ]; then + name=$(cat "$nameparam") +else + name="$__object_id" +fi + +pipparam="$__object/parameter/pip" +if [ -f "$pipparam" ]; then + pip=$(cat "$pipparam") +else + pip="pip" +fi + +case "$state_should" in + present) + echo $pip install -q pyro + ;; + absent) + echo $pip uninstall -q -y pyro + ;; +esac diff --git a/conf/type/__package_pip/man.text b/conf/type/__package_pip/man.text new file mode 100644 index 00000000..1822ffca --- /dev/null +++ b/conf/type/__package_pip/man.text @@ -0,0 +1,53 @@ +cdist-type__package_pip(7) +============================= +Nico Schottelius + + +NAME +---- +cdist-type__package_pip - Manage packages with pip + + +DESCRIPTION +----------- +Pip is used in Python environments to install packages. +It is also included in the python virtualenv environment. + + +REQUIRED PARAMETERS +------------------- +state:: + Either "present" or "absent". + + +OPTIONAL PARAMETERS +------------------- +name:: + If supplied, use the name and not the object id as the package name. + +pip:: + Instead of using pip from PATH, use the specific pip path. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Install a package +__package_pip pyro --state present + +# Use pip in a virtualenv located at /root/shinken_virtualenv +__package_pip pyro --state present --pip /root/shinken_virtualenv/bin/pip +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__package(7) + + +COPYING +------- +Copyright \(C) 2012 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__package_pip/parameter/optional b/conf/type/__package_pip/parameter/optional new file mode 100644 index 00000000..a1b589e3 --- /dev/null +++ b/conf/type/__package_pip/parameter/optional @@ -0,0 +1 @@ +pip diff --git a/conf/type/__package_pip/parameter/required b/conf/type/__package_pip/parameter/required new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/conf/type/__package_pip/parameter/required @@ -0,0 +1 @@ +state