src/iconolab_episteme/management/commands/importimages.py
changeset 30 7b479c7b6861
parent 28 15f63c5dfe3f
--- a/src/iconolab_episteme/management/commands/importimages.py	Wed Aug 01 14:43:44 2018 +0200
+++ b/src/iconolab_episteme/management/commands/importimages.py	Wed Aug 01 18:18:01 2018 +0200
@@ -63,9 +63,9 @@
             '## Converting image and moving it to static dir, creating Image and Item objects')
         print('### Images will be stored in ' + os.path.join(settings.MEDIA_ROOT, 'uploads'))
 
-        for dirname, dirs, files in os.walk(self.source_dir):
+        for dirname, _, files in os.walk(self.source_dir):
             for filename in files:
-                filename_without_extension, extension = os.path.splitext(filename)
+                filename_without_extension, _ = os.path.splitext(filename)
                 if imghdr.what(os.path.join(dirname, filename)) is None:
                     continue
 
@@ -74,27 +74,20 @@
                     continue
 
                 with open(json_path) as json_data:
-                    eso_data = json.load(json_data)
-                    eso_image = eso_data['image']
+                    item_data = json.load(json_data)
+                    item_image = item_data['image']
                 
                     path_images = os.path.join(dirname, filename)
                     image_list = [path_images]
-                    image_dir = filename_without_extension
 
-                    natural_key = ItemMetadata.get_natural_key(collection, eso_image['id'])
+                    natural_key = ItemMetadata.get_natural_key(collection, item_image['id'])
 
                     if ItemMetadata.objects.filter(
                             item__collection=collection, natural_key=natural_key).exists():
                         print('#### An item with ' +
                               natural_key +' for natural key, already exists in database in the import collection')
                     else:
-                        try:
-                            os.mkdir(os.path.join(settings.MEDIA_ROOT, 'uploads', image_dir))
-                            print(image_dir, "directory created")
-                        except FileExistsError:
-                            print(image_dir, "directory already exists")
-
                         self.create_item_and_metadata(
-                            natural_key, collection, eso_data, image_list, options, self.source_dir)
+                            natural_key, collection, item_data, image_list, options)
 
         print('# All done!')
\ No newline at end of file