Control characters don't work in django shell doit shortcut

18 views
Skip to first unread message

Max K.

unread,
Aug 3, 2011, 6:52:35 AM8/3/11
to python-doit
Hi,

I've created django manage shortcut as doit task:

def django_command():
"""
Exedcute django management command
"""

# delayed imports
from django.core.management import execute_manager
from djangoproject import settings as django_settings

# hack command line arguments for django execution manager
cmd_args = command.split(' ')
cmd_args.insert(0, '')
sys.argv = cmd_args
sys.argc = len(cmd_args)

execute_manager(django_settings)

def task_manage():
"""Execute Management command. `doit manage -c "help". """

return {
'actions': [django_command],
'params': [{
'name':'command',
'short':'c',
'long': 'cmd',
'default':'help',
}],
'verbosity': 2,
}

The issue is that when I try to start django shell like

$ doit manage -c shell

All typical shell combinations don't work (Ctrl + A for example). How
I can achieve same behavior as for python djangoproject/manage.py
shell ?

Eduardo Schettino

unread,
Aug 9, 2011, 4:06:46 AM8/9/11
to pytho...@googlegroups.com
On Wed, Aug 3, 2011 at 6:52 PM, Max K. <klym...@gmail.com> wrote:
> All typical shell combinations don't work (Ctrl + A for example). How
> I can achieve same behavior as for python djangoproject/manage.py
> shell ?
>

sorry for the late reply. i am travelling and i have no access to a
development machine.

I am not familiar with this django shell handling. so i can not really
tell you whats going on without trying it out. I can tell that doit
python-actions(as you are using in your example) or command-actions
were not designed to handle interaction with users... so you are doing
something that I never and probably no one tried before.

I guess this is a valid use-case to be handled by doit.

I guess the best way to do this would be to create a new kind of
action instead of changing the existing ones to handle interaction.
the existing ones mess up with the output depending on its verbosity
and they need to save the output.

it is not documented but the actions parameter from a task can take
instances of sub-classes from BaseAction. So you can just add this
code to the top of your dodo.py file, and you wont need to modify doit
source-cede.

Please note that i am not sure this approach will work! try at your
own risk... It would be something like this:


from doit.actions import BaseAction

class InteractiveAction(BaseAction):
# check: http://bazaar.launchpad.net/~schettino72/doit/trunk/view/head:/doit/action.py
# in short you just need to implement the execute method. and include
instance attributes out,err, result, values. you can leave the
attributes with default values. i guess for interactive action this
wont matter.

def __init__(self, action, task=None):
self.action = action
self.task = task
self.out = None
self.err = None
self.result = None
self.values = {}

def execute(self, out=None, err=None):
# this I will leave to you implement :)


---------------------

and on your task you would change this:
- 'actions': [django_command],
+ 'actions': [InteractiveAction(django_command)],


if it works ok. we can add this InteractiveAction in the next doit release.


cheers,
Eduardo

schettino72

unread,
Aug 15, 2011, 9:49:10 AM8/15/11
to pytho...@googlegroups.com

Hi Max,

Please see my dodo.py with an example of a InteractiveAction  http://pastebin.com/zFMmmECA . it is very basic but i guess it solves your problem.

Unfortunately it was required a patch on doit code to make it works...  please apply this patch http://bazaar.launchpad.net/~schettino72/doit/trunk/revision/432

cheers,
  Eduardo

Max K.

unread,
Aug 15, 2011, 12:14:08 PM8/15/11
to pytho...@googlegroups.com
Hi Eduardo,

Thank you, I will try it this week and let you know.

I was going to create my hacks this week :-)

Thank you very much for the support,

Max

Reply all
Reply to author
Forward
0 new messages