]> git.parisson.com Git - telemeta.git/commitdiff
fix more epub errors against epubcheck (mostly filenames)
authorGuillaume Pellerin <yomguy@parisson.com>
Thu, 16 Apr 2015 16:52:47 +0000 (18:52 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Thu, 16 Apr 2015 16:53:07 +0000 (18:53 +0200)
telemeta/management/commands/telemeta-import-corpus-epub.py
telemeta/templates/telemeta/collection_epub.html
telemeta/views/resource.py

index 909b8b5af752f18d156102ab0977c3f0976939ab..8fbb21d49f6c98684ba7544f9cf261ad31825bb3 100644 (file)
@@ -16,6 +16,15 @@ except ImportError:
 def beautify(string):
     return os.path.splitext(string)[0].replace('_',' ')
 
+def remove_dir_spaces(root_dir):
+    for resource in os.listdir(root_dir):
+        path = os.path.join(root_dir, resource)
+        if os.path.isdir(path):
+            new_path = path.replace(' ', '_')
+            if new_path != path:
+                os.rename(path, new_path)
+            remove_dir_spaces(new_path)
+
 def trim_list(list):
     new = []
     for item in list:
@@ -32,17 +41,26 @@ class Command(BaseCommand):
 
     def handle(self, *args, **options):
         root_dir = args[-1]
+        remove_dir_spaces(root_dir)
 
         for root, dirs, files in os.walk(root_dir):
             for media_file in files:
+                path = os.path.join(root, media_file)
+
+                if ' ' in media_file:
+                    new_media_file = media_file.replace(' ', '_')
+                    new_media_path = os.path.join(root, new_media_file)
+                    os.rename(path, new_media_path)
+                    media_file = new_media_file
+                    print media_file
+
                 media_name = os.path.splitext(media_file)[0]
                 media_ext = os.path.splitext(media_file)[1][1:]
 
                 if media_ext and media_ext in self.media_formats and media_name[0] != '.':
                     root_list = root.split(os.sep)
-
                     media_path = os.sep.join(root_list[-4:])  + os.sep + media_file
-                    print media_path
+
                     item_name = root_list[-1]
                     collection_name = root_list[-2]
                     corpus_name = root_list[-3]
@@ -74,7 +92,7 @@ class Command(BaseCommand):
 
                         if lines:
                              item.track = lines[2]
-                             item.title = lines[3]
+                             item.title = lines[3][:255]
                              item.save()
 
                         for related_file in os.listdir(root):
@@ -84,7 +102,7 @@ class Command(BaseCommand):
 
                             print related_path
                             if related_ext in self.image_formats:
-                                related, c = MediaItemRelated.objects.get_or_create(item=item, file=unicode(related_path))
+                                related, c = MediaItemRelated.objects.get_or_create(item=item, file=related_path)
                                 if c:
                                     if lines:
                                         related.title = lines[4]
index 1bc24e1282b989697aad80bc9da9b877732e2a96..c01b113a4249880ac1cfcef33da521bdf2420a7a 100644 (file)
@@ -1,28 +1,24 @@
 
 {% for item in items %}
 
-<table>
- <tr>
-  <td>
+<p>
+  <span style="font-size:0.8em;">
+  <b>{{ item.old_code }}</b> : {{ item.title }} (p. {{ item.track }})
+  </span>
+  <br>
     {% for image in item.related.all %}
       {% if 'image' in image.mime_type %}
          <div class="item-image">
-          <img width="100" src="{{ image.file }}"/>
+          <img src="{{ image.file }}"/>
          </div>
       {% endif %}
      {% endfor %}
 
-  </td>
-  <td width="75">
-  <span style="font-size:0.8em;">
-  <b>{{ item.old_code }}</b> : {{ item.title }} (p. {{ item.track }})
-  </span>
-  </td>
- </tr>
-</table>
-
+<br>
 <div class="item-audio">
  <audio src="{{ item.file }}" controls="controls"></audio>
 </div>
 
+</p>
+
 {% endfor %}
index 2db4725466490e6e41965703d06dfb9a21f9c88c..d3251f162f36181c4cfd0e4fcc4d56962c77f99b 100644 (file)
@@ -395,7 +395,7 @@ class CorpusEpubView(View):
         for collection in corpus.children.all():
             items = {}
             for item in collection.items.all():
-                 id = item.old_code.split(' ')
+                 id = item.old_code.split('_')
                  if len(id) > 1:
                      id = id[1]
                  items[item] = int(id.split('.')[1])
@@ -405,12 +405,12 @@ class CorpusEpubView(View):
                 if item.file:
                     audio = open(item.file.path, 'r')
                     filename = str(item.file)
-                    epub_item = epub.EpubItem(file_name=cleanup_path(str(item.file)), content=audio.read())
+                    epub_item = epub.EpubItem(file_name=str(item.file), content=audio.read())
                     book.add_item(epub_item)
                 for related in item.related.all():
                     if 'image' in related.mime_type:
                         image = open(related.file.path, 'r')
-                        epub_item = epub.EpubItem(file_name=cleanup_path((str(related.file)), content=image.read())
+                        epub_item = epub.EpubItem(file_name=str(related.file), content=image.read())
                         book.add_item(epub_item)
             context = {'collection': collection, 'site': site, 'items': items}
             c = epub.EpubHtml(title=collection.title, file_name=collection.code + '.xhtml', lang='fr')