views:

37

answers:

1

I'm building a Django management command which is creating website screenshots using Paul Hammond's webkit2png script (http://www.paulhammond.org/webkit2png/) and stores them into my DB.

For this command I'm using the 'call' command from 'subprocess'. How do I execute this command in specific directory (temp/ under django project in this case)? My current code looks like this but it doesn't find the script to execute which is stored in my virtualenv site-packages folder:

import os

from django.core.management.base import NoArgsCommand
from django.conf import settings
from subprocess import call

# Models
from reviews.models import Shop

class Command(NoArgsCommand):
    def handle_noargs(self, **options):
        # Shops
        shops = Shop.objects.all()

        path = os.path.join(settings.SITE_ROOT, '../env/lib/python2.6/site-packages')

        for shop in shops:
            print shop
            command = "cd temp; python %s/webkit2png.py -F %s" % (path, shop.url)
            call([command])

            # Read the screenshot file and insert to model's ImageField
A: 

This does not answer your question directly but : why do you need to use subprocess to call a python script ? You could just look at the "__main__" code in the webkit2png.py file, import it and use it.

Ghislain Leveque
This is something that I would usually do but the main() code in this case is a bit complex and it saves the results in files.
jorde