[PATCH] pyfilenamemtime

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

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.

Here is the diff:

--- old_pyfilenamemtime.py	2008-05-25 22:07:25.000000000 -0700
+++ pyfilenamemtime.py	2008-05-24 18:06:57.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?

Cheers,
Mario


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
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.