Re: [PATCH] pyfilenamemtime

Mario Fernández <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
Hi,

here is a diff with the file in the svn head (rev 944):




and here is also a fix for the textile parser (which is kind of  
broken), which I sent before but I think got lost in the mailing list.  
Again, the diff with the svn head (rev 883):




Cheers,
Mario

On Jul 3, 2008, at 8:55 PM, Ryan Barrett wrote:

> On Sun, 25 May 2008, Mario Fernández wrote:
>
>> I've written a small enhancement for the pyfilenamemtime plugin.  
>> Before, it
>> recognized timestamps in the filename with the form YYYY-MM- DD-HH- 
>> mm. I
>> found useful to also allow timestamps with the form YYYY- MM-DD (less
>> typing). So now the plugin allows both formats for a timestamp.
>
> cool, thanks! same here, mind merging it into svn head and re-diffing?
>
> http://pyblosxom.sourceforge.net/static/development.html#svn
>
> -Ryan
>
> --
> http://snarfed.org/

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08

_______________________________________________
Pyblosxom-devel mailing list
Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
pyfilenamemtime.py.diff (application/octet-stream, 1.7 KB)
--- old_pyfilenamemtime.py	2008-07-04 18:13:06.000000000 -0700
+++ pyfilenamemtime.py	2008-05-31 17:27:40.000000000 -0700
@@ -4,6 +4,7 @@
 change the mtime to be the timestamp instead of the one kept by the
 filesystem.  For example, a valid filename would be
 foo-2002-04-01-00-00.txt for April fools day on the year 2002.
+It is also possible to use timestamps in the form of YYYY-MM-DD
 
 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
@@ -30,9 +31,9 @@
 import os, re, time
 
 __author__ = 'Tim Roberts http://www.probo.com/timr/blog/'
-__version__ = '$Id$'
+__version__ = '$Id: pyfilenamemtime.py 944 2006-10-27 03:23:18Z willhelm $'
 
-DAYMATCH = re.compile('([0-9]{4})-([0-1][0-9])-([0-3][0-9])-([0-2][0-9])-([0-5][0-9]).[\w]+$')
+DAYMATCH = re.compile('([0-9]{4})-([0-1][0-9])-([0-3][0-9])(-([0-2][0-9])-([0-5][0-9]))?.[\w]+$')
 
 def cb_filestat(args):
     filename = args["filename"]
@@ -42,11 +43,15 @@
     mtch = DAYMATCH.search(os.path.basename(filename))
     if mtch:
         try:
-            year = int(mtch.groups()[0])
-            mo = int(mtch.groups()[1])
-            day = int(mtch.groups()[2])
-            hr = int(mtch.groups()[3])
-            minute = int(mtch.groups()[4]) 
+            year = int(mtch.group(1))
+            mo = int(mtch.group(2))
+            day = int(mtch.group(3))
+            if mtch.group(4) is None:
+                hr = 0
+                minute = 0
+            else:
+                hr = int(mtch.group(5))
+                minute = int(mtch.group(6)) 
             mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1))
         except:
             # TODO: Some sort of debugging code here?
txtl.py.diff (application/octet-stream, 2.9 KB)
--- old_txtl.py	2008-07-04 18:12:14.000000000 -0700
+++ txtl.py	2008-05-31 17:27:39.000000000 -0700
@@ -104,7 +104,7 @@
 
 
 def verify_installation(request):
-    
+
     config = request.getConfiguration()
 
     # First let's see if we can find the textile module.
@@ -199,18 +199,45 @@
 
 
 def cb_entryparser(args):
+    """
+    Entryparser chain callback - This plugins takes in a *.txtl file and treats
+    it like a normal blosxom entry file. Postformat callbacks are also called
+    from this entryparser.
+    
+    @param args: dict containing function references for each extensions
+    @type args: dict
+    @returns: updated dict containing the reference for .txtl entryparser
+    @rtype: dict
+    """
+
     args[FILE_EXT] = readfile
     return args
 
 
 def cb_preformat(args):
+    """
+    Preformat callback chain looks for this.
+    
+    @param args: a dict with 'parser' string and a list 'story'
+    @type args: dict
+    """
     if args['parser'] == PREFORMATTER_ID:
-        return parse(''.join(args['story']))
+        return parse(''.join(args['story']),args['request'])
     else:
         return ''.join(args['story'])
 
 
 def readfile(filename, request):
+    """
+    Reads a file and passes it to L{parse} to format in textile
+   
+    @param filename: the file in question
+    @type filename: string
+    @param request: The request object
+    @type request: L{Pyblosxom.pyblosxom.Request} object
+    @returns: Data of the entry
+    @rtype: dict
+    """
     entryData = {}
     d = open(filename).read()
 
@@ -218,15 +245,9 @@
     title = d.split('\n')[0]
     body  = d[len(title):]
 
-    # Grab textile configuration.
-    config = request.getConfiguration()
-    head_offset = config.get('txtl_head_offset', 0)
-    validate    = config.get('txtl_validate', 0)
-    output      = config.get('txtl_output', 'ascii')
-    encoding    = config.get('txtl_encoding', 'latin-1')
+    # Parse content
+    body = parse(body,request)
     
-    body = textile(body, head_offset=head_offset, validate=validate, output=output, encoding=encoding)
-
     entryData = {'title': title,
                  'body': body}
 
@@ -236,3 +257,24 @@
              'entry_data': entryData})
     
     return entryData
+
+def parse(story,request):
+    """
+    Uses textile to parse the given text
+   
+    @param story: A text for conversion
+    @type story: string
+    @param request: The request object
+    @type request: L{Pyblosxom.pyblosxom.Request} object
+    @returns: formatted string
+    @rtype: string
+    """
+    
+    # Grab textile configuration.
+    config = request.getConfiguration()
+    head_offset = config.get('txtl_head_offset', 0)
+    validate    = config.get('txtl_validate', 0)
+    output      = config.get('txtl_output', 'ascii')
+    encoding    = config.get('txtl_encoding', 'latin-1')
+
+    return textile(story, head_offset=head_offset, validate=validate, output=output, encoding=encoding)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.