]> git.parisson.com Git - telemeta.git/commitdiff
add all item file paths command
authorGuillaume Pellerin <guillaume.pellerin@free.fr>
Wed, 20 Mar 2024 09:24:00 +0000 (10:24 +0100)
committerGuillaume Pellerin <guillaume.pellerin@free.fr>
Wed, 20 Mar 2024 09:24:00 +0000 (10:24 +0100)
telemeta/management/commands/telemeta-check-items-paths.py [new file with mode: 0644]

diff --git a/telemeta/management/commands/telemeta-check-items-paths.py b/telemeta/management/commands/telemeta-check-items-paths.py
new file mode 100644 (file)
index 0000000..829a02b
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 Guillaume Pellerin
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://svn.parisson.org/telemeta/TelemetaLicense.
+#
+# Author: Guillaume Pellerin <yomguy@parisson.com>
+#
+
+import logging
+import codecs
+import os
+import sys
+import csv
+import logging
+import datetime
+from optparse import make_option
+
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.core.files.base import ContentFile
+from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
+from django.template.defaultfilters import slugify
+
+from telemeta.models import *
+from telemeta.util.unaccent import unaccent
+
+
+class Logger:
+
+    def __init__(self, file):
+        self.logger = logging.getLogger('myapp')
+        self.hdlr = logging.FileHandler(file)
+        self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+        self.hdlr.setFormatter(self.formatter)
+        self.logger.addHandler(self.hdlr)
+        self.logger.setLevel(logging.INFO)
+
+    def info(self, prefix, message):
+        self.logger.info(' ' + prefix + ' : ' + message.decode('utf8'))
+
+    def error(self, prefix, message):
+        self.logger.error(prefix + ' : ' + message.decode('utf8'))
+
+
+class Command(BaseCommand):
+
+    """Import CREM collections from collection directories containing media files
+    and eventually a XLS files representing the relation between old codes and new codes
+    """
+
+    help = "check all item file paths"
+    admin_email = 'webmaster@parisson.com'
+    media_root = settings.MEDIA_ROOT
+
+    option_list = BaseCommand.option_list + (
+          make_option('-l', '--log',
+            dest='log',
+            help='define log file'),
+    )
+
+    def handle(self, *args, **kwargs):
+        self.logger = Logger(kwargs.get('log'))
+
+        for item in MediaItem.objects.all():
+            if not os.path.exists(self.media_root + os.sep + item.file.path):
+                msg = ' : item file does not exists'
+                self.logger.info(item.public_id, msg)
+