3

I`m trying to develop a simple plugin for the Editra editor for django development. Right now it can create django projects and apps from within the editor. The editor is based on wxPython and I want to start the devserver from within the editor, show a simple form with the option to stop or kill/restart the server.

The goal is to minimize the need to do repetetive tasks in the console/shell. My reason for doing this is that I am working in a Microsoft only company where you seldom do stuff using the command line. Selling django is hard when I am in and out of the shell/command line to start/restart the server, syncdb, migrate etc. To make the job of selling django to my co-workers and hopefully make development easier ( at least for the django developers who likes to work in an IDE ) I have started the work on a plugin for Editra.

Right now the plugin adds a menu item called Django with two subitems; create project and create app. A context menu is in the works which will give different options depending on the content of the file being edited; right click in a window holding settings.py will give you the option to start the devserver, call syncdb, migrate if south is installed, create superuser etc. A right click in views.py will give you options to help you generate views or templates, in models.py scaffolding or generation of admin.py etc.

The only thing I cannot get my head around is how to start/kill/restart the devserver from inside the app. What I really like is to have a small window floating around with two buttons; stop or restart, which will -- stop or restart the devserver. Or a play and stop button inside the editor doing the same thing. The problem is controlling the devserver process from within the app.

If anybody has any information about this I would be very grateful. Any help, input, comments or ideas are appreciated.

Regards, Thomas Weholt

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Weholt
  • 1,889
  • 5
  • 22
  • 35

1 Answers1

1

You'll want to use Python's subprocess module to launch and kill the dev server process, I imagine: http://docs.python.org/library/subprocess.html

You're probably most interested in the Popen object. With it you can launch and kill the dev server.

Jake
  • 2,515
  • 5
  • 26
  • 41
  • Hmmm ... I`ve tried to use subprocess, and starting the server works fine, but stopping it does not. The process is still there after the kill or terminate call has been sent. – Weholt Apr 01 '11 at 07:53
  • You can see me code @ https://bitbucket.org/weholt/django-lime/src/38fb5f27c0f7/lime/django_tools.py. Down at the bottom there is a class called DevServerControl which is my attempt at doing this. As I mentioned, calling start works fine, calling stop does nothing. – Weholt Apr 01 '11 at 07:53
  • I suppose you are running Windows, as it seems to have difficulties when killing subprocesses. Try using the Windows solution to kill processes in this question: http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kill-a-subprocess. If there is a message you can pass to the dev server to stop it that would be an easy way to kill it, too. – Jake Apr 01 '11 at 16:07