]> git.parisson.com Git - timeside.git/commitdiff
cleanup staging modules, add a script for importing items
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 16 Mar 2015 10:03:49 +0000 (11:03 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 16 Mar 2015 10:03:49 +0000 (11:03 +0100)
examples/deploy/celery_app.sh
examples/deploy/start_app.sh
timeside/server/management/commands/timeside-import-items.py [new file with mode: 0644]

index 44a896e0415bf35e1f58797c273658b9f955e5e0..1c9b687cc34d1257431ed28894f5b7bca1f726b5 100644 (file)
@@ -5,8 +5,6 @@ app_dir='/opt/TimeSide/'
 sandbox_dir='/home/timeside/'
 manage=$sandbox_dir'manage.py'
 
-pip install django-celery
-
 python $manage migrate --noinput
 
 $manage celery worker -A celery_app
index 0a01c219905ffbdf5556bd3a63937a9671277d56..0f7fe78a4c2a58bf5a4d3d3c7797bb20e101ec22 100644 (file)
@@ -11,9 +11,6 @@ app_static_dir=$app_dir'timeside/player/static/'
 #  this is not needed for TimeSide but for Timeside-diadems
 cp -uR /opt/TimeSide/examples/sandbox/* /home/timeside/
 
-# add some staging modules
-pip install watchdog django-celery
-
 # django init
 python $manage syncdb --noinput
 python $manage migrate --noinput
diff --git a/timeside/server/management/commands/timeside-import-items.py b/timeside/server/management/commands/timeside-import-items.py
new file mode 100644 (file)
index 0000000..d725270
--- /dev/null
@@ -0,0 +1,47 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.core.files.base import ContentFile
+from timeside.server.models import *
+import os, sys
+
+try:
+    from django.utils.text import slugify
+except ImportError:
+    def slugify(string):
+        killed_chars = re.sub('[\(\),]', '', string)
+        return re.sub(' ', '_', killed_chars)
+
+def beautify(string):
+    return os.path.splitext(string)[0].replace('_',' ')
+
+
+class Command(BaseCommand):
+    help = """import media files from the media directory into some items
+            and create a selection (no file copy)"""
+    args = "selection_title media_dir"
+
+    def handle(self, *args, **options):
+        selection_title = args[-2]
+        import_dir = os.path.abspath(args[-1])
+        media_dir = os.path.normpath(settings.MEDIA_ROOT)
+
+        if not media_dir in import_dir:
+            sys.exit('This directory is not in the MEDIA_ROOT directory')
+
+        selection, c = Selection.objects.get_or_create(title=selection_title)
+        if c:
+            print 'Selection "' + selection_title + '" created'
+
+        for root, dirs, files in os.walk(import_dir):
+            for filename in files:
+                path = root + os.sep + filename
+                path = path[len(media_dir)+1:]
+                name, ext = os.path.splitext(filename)
+                title = unicode(selection_title + '_' + filename)
+                item, c = Item.objects.get_or_create(title=title, file=path)
+                if c:
+                    print 'Item "' + title + '" created'
+                if not item in selection.items.all():
+                    selection.items.add(item)
+                    print 'Item "' + title + '" added to selection "' + selection_title +'"'
\ No newline at end of file