开发者

How do I install the Django snippet dumpscript?

How do I install a Django snippet, in particular snippet 818 - dumpscript, on Linux?

Update 2. The question was about Linux, but for reference I have listed the corresponding way to install dumpscript on Windows below, e.g. for use during development. (But it can also be done the other/standard way if there are no file access restrictions.)

Update 1. This will install it for an application named "programRelease" (in a Linux command-line window, Bash shell):

cd /home/msquant/www/GoogleCodeHost/programRelease
mkdir management
touch management/__init__.py
mkdir management/commands
touch management/commands/__init__.py
wget  http://www.djangosnippets.org/snippets/818/download/ --output-document=/home/msquant/818.py
cp /home/msquant/818.py management/commands/dumpscript.py

The snippet dumpscript is now part of Django Custom Management Command Extensions but I can't install it as this is on the hosting server where I have no rights to touch the Python installation. This is the error message when running "python setup.py install" to install the command extentions:

error: could not create '/usr/lib/python2.5/site-packages/django_extensions': Permission denied

Instead I just want to install the snippet and use it.

I have tried to install it this way on the hosting server:

cd /home/msquant/
wget  http://www.djangosnippets.org/snippets/818/download/  --o开发者_运维技巧utput-document=818.py
cp /home/msquant/818.py /home/msquant/www/GoogleCodeHost/dumpscript.py

And using it this way:

cd /home/msquant/www/GoogleCodeHost
python manage.py dumpscript programRelease 

Error message:

Unknown command: 'dumpscript'
Type 'manage.py help' for usage.

The built-in dumpdata works (outputting in the JSON format):

cd /home/msquant/www/GoogleCodeHost
python manage.py dumpdata programRelease 

Ref "Update 2" above:

To install on Windows (assumes EXE file wget lives in directory D:\wget, and that the temporary directory, d:\temp2, exists):

d:
cd D:\dproj\MSQall\website\GoogleCodeHost
mkdir management
echo. > management\__init__.py
mkdir management\commands
echo. > management\commands\__init__.py
D:\wget\wget.exe  http://www.djangosnippets.org/snippets/818/download/ --output-document=d:\temp2\818.py
copy d:\temp2\818.py management\commands\dumpscript.py


Just put the snippet in {appname}/management/commands/, where {appname} is the name of an installed app. Each Python module in that directory will be auto-discovered and registered as a command that can be executed as an action when you run manage.py.

You'll need to put an empty __init__.py in both {appname}/management/ and {appname}/management/commands/ for this to work, if those files don't already exist.

See the docs for more on writing custom commands (obviously in your case, the command is already written).


I haven't updated that djangosnippets version for a while, I hope it works for you.

Note that, you don't need to "install" pure python apps like django_extensions; you can use it by just putting the folder on your path somewhere (like where you project's directory is). Failing that, try and use the dumpscript.py file found in django_extensions (it's newer)

I should have some time in the next few weeks to develop dumpscript a little further and get it to play better with some of the newer django features :-)

Cheers, Will

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜