Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Browse pydoc locally ... (See related posts)

Opens pydoc in your browser. If pydoc has not been started it starts it for you.

#!/bin/bash

PYDOC=`which pydoc`
if [ ! -x ${PYDOC} ]
then
    echo "could not find executable pydoc (tried: ${PYDOC})"
    exit 1
fi

# passthru ...
if [ $# -gt 0 ]
then
    ${PYDOC} $@
    exit $?
fi

#--------------------------------------
# or else... start it up automagically :

PYDOC_PORT=9000
PYDOC_SERVER=http://localhost:${PYDOC_PORT}/
running=0
pydoc_pses=0

function browse_docs()
{
    open ${PYDOC_SERVER}
}

for ps in `ps ax | grep "${PYDOC}" | awk '{ print $1 }'`
do
    let pydoc_pses++
done

if [ $pydoc_pses -ge 2 ]
then
    browse_docs
else
    ${PYDOC} -p ${PYDOC_PORT} &
    until `curl -o /dev/null ${PYDOC_SERVER} &>/dev/null`
    do
        echo "waiting for pydoc server ..."
        sleep 2
    done
    browse_docs
fi
exit 0

You need to create an account or log in to post comments to this site.


Click here to browse all 4839 code snippets

Related Posts