-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
oscar_import_catalogue_images.py
37 lines (28 loc) · 1.1 KB
/
oscar_import_catalogue_images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from oscar.core.loading import get_class
Importer = get_class('catalogue.utils', 'Importer')
class Command(BaseCommand):
args = '/path/to/folder'
help = 'For importing product images from a folder'
option_list = BaseCommand.option_list + (
make_option('--filename',
dest='filename',
default='upc',
help='Product field to lookup from image filename'),
)
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError('Command requires a path to a single folder')
logger = self._get_logger()
logger.info("Starting image import...")
dirname = args[0]
importer = Importer(logger, field=options.get('filename'))
importer.handle(dirname)
def _get_logger(self):
logger = logging.getLogger('oscar.apps.image')
stream = logging.StreamHandler(self.stdout)
logger.addHandler(stream)
logger.setLevel(logging.DEBUG)
return logger