Skip to content

Commit

Permalink
Add the hacking directory to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
sivel committed Jun 3, 2015
1 parent c3caff5 commit c89f981
Show file tree
Hide file tree
Showing 9 changed files with 1,090 additions and 0 deletions.
48 changes: 48 additions & 0 deletions v1/hacking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'Hacking' directory tools
=========================

Env-setup
---------

The 'env-setup' script modifies your environment to allow you to run
ansible from a git checkout using python 2.6+. (You may not use
python 3 at this time).

First, set up your environment to run from the checkout:

$ source ./hacking/env-setup

You will need some basic prerequisites installed. If you do not already have them
and do not wish to install them from your operating system package manager, you
can install them from pip

$ easy_install pip # if pip is not already available
$ pip install pyyaml jinja2 nose passlib pycrypto

From there, follow ansible instructions on docs.ansible.com as normal.

Test-module
-----------

'test-module' is a simple program that allows module developers (or testers) to run
a module outside of the ansible program, locally, on the current machine.

Example:

$ ./hacking/test-module -m lib/ansible/modules/core/commands/shell -a "echo hi"

This is a good way to insert a breakpoint into a module, for instance.

Module-formatter
----------------

The module formatter is a script used to generate manpages and online
module documentation. This is used by the system makefiles and rarely
needs to be run directly.

Authors
-------
'authors' is a simple script that generates a list of everyone who has
contributed code to the ansible repository.


14 changes: 14 additions & 0 deletions v1/hacking/authors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# script from http://stackoverflow.com/questions/12133583
set -e

# Get a list of authors ordered by number of commits
# and remove the commit count column
AUTHORS=$(git --no-pager shortlog -nse | cut -f 2- | sort -f)
if [ -z "$AUTHORS" ] ; then
echo "Authors list was empty"
exit 1
fi

# Display the authors list and write it to the file
echo "$AUTHORS" | tee "$(git rev-parse --show-toplevel)/AUTHORS.TXT"
78 changes: 78 additions & 0 deletions v1/hacking/env-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# usage: source hacking/env-setup [-q]
# modifies environment for running Ansible from checkout

# Default values for shell variables we use
PYTHONPATH=${PYTHONPATH-""}
PATH=${PATH-""}
MANPATH=${MANPATH-""}
verbosity=${1-info} # Defaults to `info' if unspecified

if [ "$verbosity" = -q ]; then
verbosity=silent
fi

# When run using source as directed, $0 gets set to bash, so we must use $BASH_SOURCE
if [ -n "$BASH_SOURCE" ] ; then
HACKING_DIR=$(dirname "$BASH_SOURCE")
elif [ $(basename -- "$0") = "env-setup" ]; then
HACKING_DIR=$(dirname "$0")
# Works with ksh93 but not pdksh
elif [ -n "$KSH_VERSION" ] && echo $KSH_VERSION | grep -qv '^@(#)PD KSH'; then
HACKING_DIR=$(dirname "${.sh.file}")
else
HACKING_DIR="$PWD/hacking"
fi
# The below is an alternative to readlink -fn which doesn't exist on OS X
# Source: http://stackoverflow.com/a/1678636
FULL_PATH=$(python -c "import os; print(os.path.realpath('$HACKING_DIR'))")
ANSIBLE_HOME=$(dirname "$FULL_PATH")

PREFIX_PYTHONPATH="$ANSIBLE_HOME"
PREFIX_PATH="$ANSIBLE_HOME/bin"
PREFIX_MANPATH="$ANSIBLE_HOME/docs/man"

expr "$PYTHONPATH" : "${PREFIX_PYTHONPATH}.*" > /dev/null || export PYTHONPATH="$PREFIX_PYTHONPATH:$PYTHONPATH"
expr "$PATH" : "${PREFIX_PATH}.*" > /dev/null || export PATH="$PREFIX_PATH:$PATH"
expr "$MANPATH" : "${PREFIX_MANPATH}.*" > /dev/null || export MANPATH="$PREFIX_MANPATH:$MANPATH"

#
# Generate egg_info so that pkg_resources works
#

# Do the work in a function so we don't repeat ourselves later
gen_egg_info()
{
if [ -e "$PREFIX_PYTHONPATH/ansible.egg-info" ] ; then
rm -r "$PREFIX_PYTHONPATH/ansible.egg-info"
fi
python setup.py egg_info
}

if [ "$ANSIBLE_HOME" != "$PWD" ] ; then
current_dir="$PWD"
else
current_dir="$ANSIBLE_HOME"
fi
cd "$ANSIBLE_HOME"
if [ "$verbosity" = silent ] ; then
gen_egg_info > /dev/null 2>&1
else
gen_egg_info
fi
cd "$current_dir"

if [ "$verbosity" != silent ] ; then
cat <<- EOF

Setting up Ansible to run out of checkout...

PATH=$PATH
PYTHONPATH=$PYTHONPATH
MANPATH=$MANPATH

Remember, you may wish to specify your host file with -i

Done!

EOF
fi
67 changes: 67 additions & 0 deletions v1/hacking/env-setup.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env fish
# usage: . ./hacking/env-setup [-q]
# modifies environment for running Ansible from checkout
set HACKING_DIR (dirname (status -f))
set FULL_PATH (python -c "import os; print(os.path.realpath('$HACKING_DIR'))")
set ANSIBLE_HOME (dirname $FULL_PATH)
set PREFIX_PYTHONPATH $ANSIBLE_HOME/
set PREFIX_PATH $ANSIBLE_HOME/bin
set PREFIX_MANPATH $ANSIBLE_HOME/docs/man

# Set PYTHONPATH
if not set -q PYTHONPATH
set -gx PYTHONPATH $PREFIX_PYTHONPATH
else
switch PYTHONPATH
case "$PREFIX_PYTHONPATH*"
case "*"
echo "Appending PYTHONPATH"
set -gx PYTHONPATH "$PREFIX_PYTHONPATH:$PYTHONPATH"
end
end

# Set PATH
if not contains $PREFIX_PATH $PATH
set -gx PATH $PREFIX_PATH $PATH
end

# Set MANPATH
if not contains $PREFIX_MANPATH $MANPATH
if not set -q MANPATH
set -gx MANPATH $PREFIX_MANPATH
else
set -gx MANPATH $PREFIX_MANPATH $MANPATH
end
end

set -gx ANSIBLE_LIBRARY $ANSIBLE_HOME/library

# Generate egg_info so that pkg_resources works
pushd $ANSIBLE_HOME
python setup.py egg_info
if test -e $PREFIX_PYTHONPATH/ansible*.egg-info
rm -r $PREFIX_PYTHONPATH/ansible*.egg-info
end
mv ansible*egg-info $PREFIX_PYTHONPATH
popd


if set -q argv
switch $argv
case '-q' '--quiet'
case '*'
echo ""
echo "Setting up Ansible to run out of checkout..."
echo ""
echo "PATH=$PATH"
echo "PYTHONPATH=$PYTHONPATH"
echo "ANSIBLE_LIBRARY=$ANSIBLE_LIBRARY"
echo "MANPATH=$MANPATH"
echo ""

echo "Remember, you may wish to specify your host file with -i"
echo ""
echo "Done!"
echo ""
end
end
29 changes: 29 additions & 0 deletions v1/hacking/get_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

# (c) 2014, Will Thames <[email protected]>
#
# This file is part of Ansible
#
# Ansible 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.
#
# Ansible 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 Ansible. If not, see <http://www.gnu.org/licenses/>.
#

import ansible.constants as C
import sys

def main():
print C.DEFAULT_MODULE_PATH
return 0

if __name__ == '__main__':
sys.exit(main())
Loading

0 comments on commit c89f981

Please sign in to comment.