import script
authorMarcin Koziej <marcinkoziej@nowoczesnapolska.org.pl>
Mon, 9 Sep 2013 16:15:25 +0000 (18:15 +0200)
committerMarcin Koziej <marcinkoziej@nowoczesnapolska.org.pl>
Mon, 9 Sep 2013 16:15:25 +0000 (18:15 +0200)
scripts/image.xml [new file with mode: 0644]
scripts/import_image.py [new file with mode: 0755]

diff --git a/scripts/image.xml b/scripts/image.xml
new file mode 100644 (file)
index 0000000..7276015
--- /dev/null
@@ -0,0 +1,28 @@
+<picture>
+  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+    <rdf:Description rdf:about="http://wiki.wolnepodreczniki.pl/Lektury:Andersen/Brzydkie_kaczątko">
+      <dc:creator xml:lang="pl"></dc:creator>
+      <dc:title xml:lang="la"></dc:title>
+      <dc:publisher xml:lang="pl">Fundacja Nowoczesna Polska</dc:publisher>
+      <dc:contributor.editor xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">Sekuła, Aleksandra</dc:contributor.editor>
+      <dc:contributor.editor xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">Sławiec, Urszula</dc:contributor.editor>
+      <dc:contributor.editor xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">Kucharska-Hornung, Katarzyna</dc:contributor.editor>
+      <dc:subject.period xml:lang="pl"></dc:subject.period>
+      <dc:subject.type xml:lang="pl">Obraz</dc:subject.type>
+      <dc:description xml:lang="pl">Publikacja zrealizowana w ramach projektu Wolne Lektury (http://wolnelektury.pl). Reprodukcja cyfrowa wykonana przez Bibliotekę Narodową z egzemplarza pochodzącego ze zbiorów BN.</dc:description>
+      <dc:description.dimensions xml:lang="pl"></dc:description.dimensions>
+      <dc:description.medium xml:lang="pl"></dc:description.medium>
+      <dc:identifier.url xml:lang="pl"></dc:identifier.url>
+      <dc:source.URL xml:lang="pl"></dc:source.URL>
+      <dc:source xml:lang="pl"></dc:source>
+      <dc:rights xml:lang="pl">Domena publiczna</dc:rights>
+      <dc:date.pd xml:lang="pl"></dc:date.pd>
+      <dc:type>Image</dc:type>
+      <dc:format xml:lang="pl">image/png</dc:format>
+      <dc:format.dimensions xml:lang="pl"></dc:format.dimensions>
+      <dc:format.checksum.sha1 xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:format.checksum.sha1>
+      <dc:date xml:lang="pl"></dc:date>
+      <dc:language xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">pol</dc:language>
+    </rdf:Description>
+  </rdf:RDF>
+</picture>
diff --git a/scripts/import_image.py b/scripts/import_image.py
new file mode 100755 (executable)
index 0000000..30ca8c0
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+import sys
+sys.path.append('.')
+sys.path.append('./apps')
+sys.path.append('./lib')
+
+from django.core.management import setup_environ
+from redakcja import settings
+from redakcja import localsettings
+
+setup_environ(settings)
+settings.CATALOGUE_REPO_PATH = localsettings.CATALOGUE_REPO_PATH
+settings.CATALOGUE_IMAGE_REPO_PATH = localsettings.CATALOGUE_IMAGE_REPO_PATH
+settings.MEDIA_ROOT = localsettings.MEDIA_ROOT
+settings.STATIC_ROOT = localsettings.STATIC_ROOT
+
+
+from catalogue.models import  Image
+from django.core.files import File
+import re
+from os import path
+from django.contrib.auth.models import User
+from django.conf import settings
+
+
+
+user = {
+    'obj': User.objects.get(username='marcinkoziej'),
+    'name': 'Marcin Koziej',
+    'email': 'marcinkoziej@nowoczesnapolska.org.pl'
+    }
+
+files = sys.argv[1:]
+
+xml = open(path.dirname(__file__)+"/image.xml").read().decode('utf-8')
+
+for filename in files:
+    dfile = File(open(filename))
+    img = Image()
+    name = path.splitext(path.basename(filename))[0]
+    print filename, name
+    try:
+        old = Image.objects.get(slug=name)
+        print "deleting old %s" % name
+        old.delete()
+    except:
+        pass
+    
+
+    img.slug = name
+    img.title = name
+    img.image.save(filename, dfile)
+
+    img.save()
+    img.commit(xml, author=user['obj'], author_name=user['name'], author_email=user['email'])
+
+
+