Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#19115 closed Cleanup/optimization (fixed)

dumpdata should take option to output to named file

Reported by: murftone@… Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords: dumpdata management command
Cc: d1fffuz0r@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If the dumpdata management command could output to a named file, it would make it a lot easier to invoke dumpdata from other management commands via call_command.

Attachments (4)

19115.patch (3.8 KB ) - added by Roman Gladkov 11 years ago.
19115.2.patch (684 bytes ) - added by Roman Gladkov 11 years ago.
19115.3.patch (1.0 KB ) - added by Roman Gladkov 11 years ago.
19115.4.patch (680 bytes ) - added by Claude Paroz 11 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 by Simon Charette, 11 years ago

We could document you can achieve this by passing a file like object as the stdout kwarg of call_command.

with open('/tmp/call_command_output') as f:
    call_command('dumpdata', stdout=f)

This looks quite easy to me.

comment:2 by Claude Paroz, 11 years ago

Component: Core (Management commands)Documentation
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

by Roman Gladkov, 11 years ago

Attachment: 19115.patch added

comment:3 by Roman Gladkov, 11 years ago

Cc: d1fffuz0r@… added
Has patch: set
Version: 1.4master

added new optional parameter to dumpdata command, for save data to file

comment:4 by Claude Paroz, 11 years ago

Patch needs improvement: set

This ticket was accepted on the base that we should document the stdout usage of call_command, which is also useful for all other commands. Not to add another option to dumpdata.

by Roman Gladkov, 11 years ago

Attachment: 19115.2.patch added

comment:5 by Roman Gladkov, 11 years ago

Ok. I'm sorry, I fixed this patch and added only documentation.

comment:6 by Claude Paroz, 11 years ago

Thanks for your efforts. As the stdout option is valid for all commands, I'd rather add a paragraph (Output redirection) in the section https://docs.djangoproject.com/en/dev/ref/django-admin/#running-management-commands-from-your-code

Then you can just add a reference to it from the dumpdata section.

comment:7 by Roman Gladkov, 11 years ago

I agree. That looks better.

by Roman Gladkov, 11 years ago

Attachment: 19115.3.patch added

by Claude Paroz, 11 years ago

Attachment: 19115.4.patch added

comment:8 by Claude Paroz, 11 years ago

After some thoughts, here's how I'd like to document it. I don't think it's worth adding the note to the dumpdata command section, as we should then specify it also for all other commands which output data. We can count on people trying to output data with a management command to look after the call_command section.

comment:9 by Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: newclosed

In b1ac329ba9bbcba90d8ced7e16909ed169b1d16e:

Fixed #19115 -- Documented stdout/stderr options for call_command

Thanks d1ffuz0r for helping with the patch.

comment:10 by Claude Paroz <claude@…>, 11 years ago

In b8726179249ede88c988c13fd4b1077e49e8b151:

[1.5.x] Fixed #19115 -- Documented stdout/stderr options for call_command

Thanks d1ffuz0r for helping with the patch.
Backport of b1ac329ba from master.

comment:11 by maa@…, 10 years ago

how do we use this ?
./manage dumpdata --stdout=file.json ?

in reply to:  11 comment:12 by Baptiste Mispelon, 10 years ago

Replying to maa@…:

how do we use this ?
./manage dumpdata --stdout=file.json ?

This ticket tracker is not the best place to ask questions like this. You should use our support channels instead [1].

As for your question, since the command outputs its result, you can use your shell's output redirection feature:

./manage dumpdata > the_name_of_the_file.json

[1] https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels

Note: See TracTickets for help on using tickets.
Back to Top