diff data/plugin/parser/text_x_arnica.py @ 89:83abc483373a

text_x_arnica: internal _get_files routine added to select only valid image files
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 21 Jun 2008 23:58:43 +0200
parents d60f41c17f42
children 7e0445f8120e
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Thu Jun 19 22:19:15 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Sat Jun 21 23:58:43 2008 +0200
@@ -19,7 +19,7 @@
 
 import os, re
 from random import randint
-from MoinMoin import caching, wikiutil
+from MoinMoin import caching, config, wikiutil
 from MoinMoin.action import AttachFile
 from MoinMoin.filter import EXIF
 from MoinMoin.packages import packLine
@@ -34,6 +34,13 @@
 
 parser_name = __name__.split('.')[-1]
 
+def _get_files(request, pagename):
+    attach_dir = AttachFile.getAttachDir(request, pagename)
+    files = []
+    if os.path.isdir(attach_dir):
+        files = [fn.decode(config.charset) for fn in os.listdir(attach_dir) if wikiutil.isPicture(fn) and not fn.startswith('tmp.')]
+    return files
+
 def macro_arnica(target_page=u'', columns=4, file_regex=u'.',
                  image_for_webnail=False,
                  show_text=True, show_date=True, show_tools=True,
@@ -312,30 +319,24 @@
 
         for attfile in files:
             # only files not thumb or webnails
-            if not attfile.startswith('tmp.'):
-                # only images
-                if wikiutil.isPicture(attfile):
-                    self.description.append(ddict.get(attfile, attfile))
-
-                    self.full.append(attfile)
+            self.description.append(ddict.get(attfile, attfile))
+            self.full.append(attfile)
+            fname, ext = os.path.splitext(attfile)
+            if ext in ('.gif', '.png'):
+                self.imgtype.append('PNG')
+                webnail = 'tmp.webnail_%s.png' % fname
+                thumbfile = 'tmp.thumbnail_%s.png' % fname
+            else:
+                self.imgtype.append("JPEG")
+                webnail = 'tmp.webnail_%s.jpg' % fname
+                thumbfile = 'tmp.thumbnail_%s.jpg' % fname
 
-                    fname, ext = os.path.splitext(attfile)
-                    if ext in ('.gif', '.png'):
-                        self.imgtype.append('PNG')
-                        webnail = 'tmp.webnail_%s.png' % fname
-                        thumbfile = 'tmp.thumbnail_%s.png' % fname
-                    else:
-                        self.imgtype.append("JPEG")
-                        webnail = 'tmp.webnail_%s.jpg' % fname
-                        thumbfile = 'tmp.thumbnail_%s.jpg' % fname
-
-                    att_file = os.path.join(path, attfile)
-                    if os.path.exists(att_file):
-                        self.web.append(webnail)
-                        self.thumb.append(thumbfile)
-
-                        date = get_exif_info(att_file)
-                        self.exif_date.append(wikiutil.escape(date, quote=1))
+            att_file = os.path.join(path, attfile)
+            if os.path.exists(att_file):
+                self.web.append(webnail)
+                self.thumb.append(thumbfile)
+                date = get_exif_info(att_file)
+                self.exif_date.append(wikiutil.escape(date, quote=1))
 
     def to_wikitext(self, text):
         """
@@ -395,7 +396,7 @@
                 all_files = [image_dict[txt] for txt in keys]
 
         else:
-            all_files = AttachFile._get_files(self.request, self.pagename)
+            all_files = _get_files(self.request, self.pagename)
 
         if self.file_regex != u'.':
             all_files = [attfile for attfile in all_files if re.match(self.file_regex, attfile)]