changeset 7:a067ae7020f6

text_x_arnica: fixed many pylint warnings, factored out get_exif_info from get_files
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 09 Mar 2008 17:53:43 +0100
parents 756cb845ddad
children b9eb24a6213a
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 63 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Sat Mar 08 21:46:11 2008 +0100
+++ b/data/plugin/parser/text_x_arnica.py	Sun Mar 09 17:53:43 2008 +0100
@@ -89,6 +89,7 @@
     """ arnica parser """
     extensions = '*.jpg'
     def __init__(self, raw, request, **kw):
+        # list of optional arguments for the parser starts here 
         self.target_page = ''
         self.sort_by_date = '0'
         self.sort_by_name = '1'
@@ -112,28 +113,35 @@
         self.thumbnail_width = '128'
         self.webnail_width = '640'
         self.text_width = '140'
+        # list of optional arguments for the parser ends here
         
-
+        # get the paraemters
         test = kw.get('format_args', '')
         if test:
             for arg in kw.get('format_args', '').split(','):
                 if arg.find('=') > -1:
                     key, value = arg.split('=')
                     setattr(self, key, wikiutil.escape(value.strip(), quote=1))
-
+        # calc
         self.width = str(int(self.thumbnail_width) + int(self.text_width))
-
+        
+        self.pagename = request.page.page_name
         self.raw = raw
         self.request = request
-        self.form = request.form
+        self.form = None
         self._ = request.getText
 
         self.outer_table_style = ' border="%s"' % self.border_thick
         self.inner_table_style = ' style="border-style:none; margin:10px;"'
         self.td_style = ' align="center" style="padding:0; margin:2px 2px; border-style:none"'
         
-        self.form = None
-        self.pagename = request.page.page_name
+        self.web = [] # array for webnails
+        self.full = [] # array for  images
+        self.thumb = [] # array for thumbnails
+        self.exif_date = [] # array of exif date description
+        self.imgtype = [] # array of imagetype of full image 
+        self.description = [] # array of description
+        self.webimg = [] # array of images for forms
         
     def show_tools_restricted(self, this_target):
         """ show only tools to users with enough rights 
@@ -170,7 +178,7 @@
             'baseurl': self.request.getBaseURL(),
             'style': self.td_style,
             'htdocs': self.request.cfg.url_prefix_static,
-            "pagename": self.quoted_pagename,
+            "pagename": wikiutil.quoteWikinameURL(self.pagename),
             "this_target": this_target}
 
     def tools_html(self, idx):
@@ -204,7 +212,7 @@
                 </tr>
             </table>'''   % {
             "baseurl": self.request.getScriptname(),
-            "pagename": self.quoted_pagename,
+            "pagename": wikiutil.quoteWikinameURL(self.pagename),
             "htdocs": self.request.cfg.url_prefix_static,
             "tablestyle": self.inner_table_style,
             "style": self.td_style,
@@ -213,7 +221,7 @@
             "exif_date": self.exif_date[idx] + ',' + ','.join(self.exif_date),
             "target": self.webimg[idx] + ',' + ','.join(self.webimg),
             "this_target": self.full[idx],
-            "thumbnail": "%s%s" % (self.static_url, self.thumb[idx]),
+            "thumbnail": "%s%s" % (AttachFile.getAttachUrl(self.pagename, '', self.request), self.thumb[idx]),
             "show_tools_restricted":self.show_tools_restricted(this_image)
             }
 
@@ -270,12 +278,12 @@
     <tr>%(tools_html)s%(date_html)s</tr>''' % {
      "tdstyle": self.td_style,
      "baseurl": self.request.getScriptname(),
-     "pagename": self.quoted_pagename,
+     "pagename": wikiutil.quoteWikinameURL(self.pagename),
      "thumbnail_width": self.thumbnail_width,
      "description": self.description[idx] + '!,!' + '!,!'.join(self.description),
      "exif_date": self.exif_date[idx] + ',' + ','.join(self.exif_date),
      "target": self.webimg[idx] + ',' + ','.join(self.webimg),
-     "thumbnail": "%s%s" % (self.static_url, self.thumb[idx]),
+     "thumbnail": "%s%s" % (AttachFile.getAttachUrl(self.pagename, '', self.request), self.thumb[idx]),
      "tools_html": self.show_tools_mode2(idx),
      "date_html": self.show_date_mode2(idx),
      "alias_html": self.show_alias_mode2(idx)
@@ -320,6 +328,7 @@
 
     def mode1_html(self, idx):
         """ html code of mode 1 (default)"""
+        print AttachFile.attachUrl(self.request, self.pagename, self.thumb[idx], target=self.thumb[idx])
         text = '''
     <table width="%(thumbnail_width)s" align="center" valign="center"%(style)s>
     <TR align="center" valign="center">
@@ -342,11 +351,11 @@
      "tdstyle": self.td_style,
      "style": self.inner_table_style,
      "baseurl": self.request.getScriptname(),
-     "pagename": self.quoted_pagename,
+     "pagename": wikiutil.quoteWikinameURL(self.pagename),
      "description": self.description[idx] + '!,!' + '!,!'.join(self.description),
      "exif_date": self.exif_date[idx] + ',' + ','.join(self.exif_date),
      "target": self.webimg[idx] + ',' + ','.join(self.webimg),
-     "thumbnail": "%s%s" % (self.static_url, self.thumb[idx]),
+     "thumbnail":"%s%s" % (AttachFile.getAttachUrl(self.pagename, '', self.request), self.thumb[idx]),
      "thumbnail_width": self.thumbnail_width,
      "tools_html": self.show_tools_mode1(idx),
      "date_html": self.show_date_mode1(idx),
@@ -354,6 +363,21 @@
      }
 
         return text
+    
+    def get_exif_info(self, file_name):
+        """ gets exif info from image file 
+        @param: image file name 
+        """
+        id_file = open(file_name, 'rb')
+        tags = EXIF.process_file(id_file, 'DateTimeOriginal')
+        id_file.close()
+        if tags.has_key('EXIF DateTimeOriginal'):
+            date = str(tags['EXIF DateTimeOriginal'])
+            date = date.replace(':', '-', 2)
+        else:
+            date = '--'
+
+        return date
 
     def get_files(self, path, files, quotes):
         """ get files creates lists for thumbnails and webnails 
@@ -361,28 +385,20 @@
         @param files: file names of images
         @param quotes: text alias for image file
         """
-        self.web = []
-        self.full = []
-        self.thumb = []
-        self.exif_date = []
-        self.imgtype = []
-        self.description = []
-
         ddict = {}
-        n = len(quotes['image'])
-        if n > 0:
+        if len(quotes['image']) > 0:
             i = 0
             for txt in quotes['image']:
-                ddict[txt] = quotes['alias'][i]
-                i += 1
-
-        self.source_type = ''
+                ddict[txt] = quotes['alias'][i]               
+                i += 1            
+            
         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)
 
                     fname, ext = os.path.splitext(attfile)
@@ -395,21 +411,13 @@
                         webnail = 'tmp.webnail_%s.jpg' % fname
                         thumbfile = 'tmp.thumbnail_%s.jpg' % fname
 
-                    infile = os.path.join(path, attfile)
-                    if os.path.exists(infile):
+                    att_file = os.path.join(path, attfile)
+                    if os.path.exists(att_file):
                         self.web.append(webnail)
                         self.thumb.append(thumbfile)
-
-                    f = open(infile, 'rb')
-                    tags = EXIF.process_file(f, 'DateTimeOriginal')
-                    f.close()
-                    if tags.has_key('EXIF DateTimeOriginal'):
-                        date = str(tags['EXIF DateTimeOriginal'])
-                        date = date.replace(':', '-', 2)
-                    else:
-                        date = '--'
-
-                    self.exif_date.append(wikiutil.escape(date, quote=1))
+                        
+                        date = self.get_exif_info(att_file)
+                        self.exif_date.append(wikiutil.escape(date, quote=1))
 
     def to_wikitext(self, text):
         """
@@ -468,44 +476,29 @@
         if self.target_page:
             self.pagename = self.target_page
         path = AttachFile.getAttachDir(self.request, self.pagename, create=1)
-        self.quoted_pagename = wikiutil.quoteWikinameURL(self.pagename)
 
-        self.static_url = AttachFile.getAttachUrl(self.pagename, '', self.request)
-        Image_Dict = {}
+        image_dict = {}
         quotes = self.get_quotes()
 
         if self.only_items == '1':
-            all_files = quotes['image']
-            result = []
-            for attfile in all_files:
-                if os.path.exists(os.path.join(path, attfile)):
-                    result.append(attfile)
-            all_files = result
+            files = quotes['image']
+            all_files = [attfile for attfile in files if os.path.exists(os.path.join(path, attfile))]
 
             if self.sort_by_alias == '1':
-                result = []
                 alias_text = quotes['alias']
-
                 i = 0
                 for attfile in all_files:
-                    infile = os.path.join(path, attfile)
-                    Image_Dict[alias_text[i]] = attfile
+                    image_dict[alias_text[i]] = attfile
                     i += 1
-
-                keys = Image_Dict.keys()
+                keys = image_dict.keys()
                 keys.sort()
-                for txt in keys:
-                    result.append(Image_Dict[txt])
-                all_files = result
+                all_files = [image_dict[txt] for txt in keys]
+                
         else:
             all_files = os.listdir(path)
         
         if self.filter != '.':
-            result = []
-            for test in all_files:
-                if re.match(self.filter, test):
-                    result.append(test)
-            all_files = result
+            all_files = [attfile for attfile in all_files if re.match(self.filter, attfile)]
             
         if self.sort_by_name == '1' and self.only_items == '0':
             all_files.sort()
@@ -514,15 +507,12 @@
             for attfile in all_files:
                 infile = os.path.join(path, attfile)
                 ft_file = "%s%s" % (str(os.path.getmtime(infile)), str(randint(0, 65535)))
-                Image_Dict[ft_file] = attfile   
-            keys = Image_Dict.keys()
+                image_dict[ft_file] = attfile   
+            keys = image_dict.keys()
             keys.sort()
-            result = []
-            for txt in keys:
-                result.append(Image_Dict[txt])
-            all_files = result
+            all_files = [image_dict[txt] for txt in keys]
             
-        Image_Dict.clear()
+        image_dict.clear()
         
         if self.reverse_sort == '1':
             all_files.reverse()
@@ -618,9 +608,11 @@
 
             if self.mode == '2':
                 text = self.mode2_html(i)
-                if cols > 1: self.request.write('<table valign="bottom">')
+                if cols > 1: 
+                    self.request.write('<table valign="bottom">')
                 self.request.write(''.join(text))
-                if cols > 1: self.request.write('</table>')
+                if cols > 1: 
+                    self.request.write('</table>')
 
             if self.mode == '1' or cols > 1:
                 if self.album == '0':