Re: Script to call loaddata on multiple fixtures

2012-02-20 Thread Tom Evans
On Sat, Feb 18, 2012 at 4:46 PM, LJ  wrote:
> I have quite a number of fixtures that I call loaddata to insert
> fixtures into my sqlite database using the following syntax:
>
> python ./manage.py loaddata ./apps/addresses/fixtures/cities.json
> python ./manage.py loaddata ./apps/addresses/fixtures/addresses.json
> ...
>
> I would like to create a script to call all of these, so I can insert
> them all at once.
> I do not want to combine all of the json files.
> To do this, would I create a py script similar to my bootstrap.py
> script?
> My bootstrap.py script executes subprocess.call() on all packages
> listed in my requirements txt file.
> Am I going down the right path with this, or is there an easier way?
>
> L J
>

Management commands. You can write custom management commands, and you
can programatically invoke other management commands:


from django.core.management.base import NoArgsCommand
from django.core import management

class Command(NoArgsCommand):
  help = 'Meta command which calls other commands'

  def handle_noargs(self, **options):
management.call_command('loaddata', './apps/addresses/fixtures/cities.json')


https://docs.djangoproject.com/en/1.3/howto/custom-management-commands/

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Script to call loaddata on multiple fixtures

2012-02-18 Thread LJ
Thanks, Dennis.
Some of the fixtures are order dependent.
I will have to do some more research on how to use glob.glob() and
spawn.
For now, just adding the list of python loaddata commands to a shell
script seem to work great.
Thanks again for the info!
L J

On Feb 18, 4:33 pm, Dennis Lee Bieber  wrote:
> On Sat, 18 Feb 2012 08:46:25 -0800 (PST), LJ 
> wrote:
>
> >I would like to create a script to call all of these, so I can insert
> >them all at once.
> >I do not want to combine all of the json files.
>
>         Are they order dependent? That is, do any of the loads require
> certain data to have already been loaded? Foreign key constraints,
> perhaps?
>
>         If so, you may want to just create a shell script of the commands
> rather than running a Python process which just spawns separate
> processes to do the load call.
>
>         If they are NOT order dependent (OR you are willing to rename them
> into some scheme that can be sorted) AND if all the .json files in the
> directory are to be loaded (they are not used for any other use), THEN
> you might consider a Python script that reads the directory contents
> (glob.glob() ?) into a list of all the .json files and spawns the load
> command for each (possibly after sorting per the ordering scheme). Of
> course, you could probably develop a shell script to do the same thing.
> The Python version would be more portable if you change OS.
>
> >>> import glob
> >>> for fid in glob.glob("*"):
>
> ...     print "pretend to spawn using %s" % fid
> ...
> pretend to spawn using license.txt
> pretend to spawn using mfc90.dll
> pretend to spawn using mfc90u.dll
> pretend to spawn using mfcm90.dll
> pretend to spawn using mfcm90u.dll
> pretend to spawn using Microsoft.VC90.MFC.manifest
> pretend to spawn using Pythonwin.exe
> pretend to spawn using pywin
> pretend to spawn using scintilla.dll
> pretend to spawn using win32ui.pyd
> pretend to spawn using win32uiole.pyd
>
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Script to call loaddata on multiple fixtures

2012-02-18 Thread LJ
That worked great.  I haven't done much shell scripting, but it was
easier than I thought.
Thanks, Shawn!

L J

On Feb 18, 9:46 am, LJ  wrote:
> I have quite a number of fixtures that I call loaddata to insert
> fixtures into my sqlite database using the following syntax:
>
> python ./manage.py loaddata ./apps/addresses/fixtures/cities.json
> python ./manage.py loaddata ./apps/addresses/fixtures/addresses.json
> ...
>
> I would like to create a script to call all of these, so I can insert
> them all at once.
> I do not want to combine all of the json files.
> To do this, would I create a py script similar to my bootstrap.py
> script?
> My bootstrap.py script executes subprocess.call() on all packages
> listed in my requirements txt file.
> Am I going down the right path with this, or is there an easier way?
>
> L J

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Script to call loaddata on multiple fixtures

2012-02-18 Thread Shawn Milochik
Why not just put all those manage.py commands in a shell script and run 
that?


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.