Created
January 3, 2009 01:51
-
-
Save zvoase/42767 to your computer and use it in GitHub Desktop.
djcontriblink - Link and unlink Python modules (usually Django apps) to the Django contrib directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# djcontriblink.sh - Link a Python module (usually a Django app) to the Django contrib directory. | |
# Note: this approach to installing Django apps is not recommended, but some apps require it. | |
# | |
# See http://gist.github.com/42767 for updates. | |
# Check that an argument has been given. If not, print usage string. | |
if [ -z $1 ] | |
then | |
echo "Usage: `basename $0` <path_to_app> [<link_name>]" | |
exit | |
fi | |
# If there is not already a SITE_PACKAGES environment variable, then get it | |
# from Python. | |
if [[ -z $SITE_PACKAGES || ! -d $SITE_PACKAGES ]] | |
then | |
SITE_PACKAGES=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"` | |
fi | |
# Parse the first argument | |
BASE=`basename $1` | |
DIR=`dirname $1` | |
if [ ! -d $SITE_PACKAGES/django/contrib ] | |
then | |
echo "Django not found in site packages directory. Exiting." | |
exit 1 | |
fi | |
# Go into the directory of the first argument | |
pushd $DIR > /dev/null | |
if [ $2 ]; then | |
# If an additional name for the module has been provided, use that as the | |
# link's basename. | |
ln -sfnv `pwd`/$BASE $SITE_PACKAGES/django/contrib/`basename $2` | |
else | |
# Otherwise, use the basename of the given location. | |
ln -sfnv `pwd`/$BASE $SITE_PACKAGES/django/contrib/$BASE | |
fi | |
# Return to where we were before | |
popd > /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# djcontribunlink.sh - Remove a djcontriblinked module from the Django contrib directory. | |
# | |
# See http://gist.github.com/42767 for updates. | |
# Check that an argument has been given. If not, print usage string. | |
if [ -z $1 ] | |
then | |
echo "Usage: `basename $0` <link_name>" | |
exit | |
fi | |
# If there is not already a SITE_PACKAGES environment variable, then get it | |
# from Python. | |
if [[ -z $SITE_PACKAGES || ! -d $SITE_PACKAGES ]] | |
then | |
SITE_PACKAGES=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"` | |
fi | |
if [ ! -d $SITE_PACKAGES/django/contrib ] | |
then | |
echo "Django contrib directory not found. Exiting." | |
exit 1 | |
fi | |
# If given name is a symbolic link in $SITE_PACKAGES/django/contrib | |
if [ -h $SITE_PACKAGES/django/contrib/`basename $1` ]; then | |
# Remove it | |
rm -Rf $SITE_PACKAGES/django/contrib/`basename $1` | |
else | |
# Signal an error. | |
echo "Error: link `basename $1` not found in Django contrib directory." | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment