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