Re: metadate improvements

"Hiếu Hoàng" <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
On Dec 19, 2007 1:10 AM, will <[email protected]> wrote:
> If it's throwing a 500 error, then the error messages will likely be in
> your web-server's error log file.
>

 Thanks, that's what I need

 And I forgot to attach the metadate file, oops.

  Hiếu

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Pyblosxom-devel mailing list
Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
metadate.py (text/x-python, 3.7 KB)
# coding: utf-8
"""
Purpose:

  If an entry contains a #postdate metatag, metadate.py makes
  pyblosxom use that as the entry's date instead of the file's mtime.

To use:

  Place this file in your pyblosxom plugins directory.

  If you have previously assigned a value to py['load_plugins'] in
  your config.py file, add this module to that list.

  Tag an entry with a metadata line like so (T is the literal character):
    #postdate YYYY-MM-DDTHH:MM:SS

  You can use a custom time format by defining the ``postdate_formats``
  variable as a list of strings in the format of Python's `time.strftime`_

  .. _time.strftime: http://docs.python.org/lib/module-time.html#l2h-2816

  I recommend you to include some second info in order to avoid $w3cdate
  showing 00 second, telling people that the post date is likely forged

Developer Info:

  There really isn't a clean way to implement this (as far as I can
  tell).  The cb_filestat callback isn't passed the entry, and none of
  the other callbacks are passed the mtime, and we really need them
  both to do this properly.

  The ugly--but functional--solution to this problem is to go into the
  file and dig the metadata out directly.  That is what I have done
  here.

  Since the entries are now being opened twice each, this could result
  in decently-sized (relatively speaking) performance hit.  Consider
  yourself warned.

License:

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.

Copyright 2005 Cameron Desautels
"""

import time

__author__ = 'Cameron Desautels <[email protected]>; Hiếu Đức Hoàng <[email protected]>'
__version__ = 'metadate.py, v 0.2'
__description__ = 'Implements overriding of mtime with #postdate metadata.'

TIME_STR_FORMAT = '%Y-%m-%dT%H:%M:%S'

def cb_filestat(args):
    stattuple = args['mtime']
    new_mtime = old_mtime = stattuple[8] # fallback to original mtime if none matches
    time_formats = args['request'].getConfiguration().get('postdate_formats',
                                                          [TIME_STR_FORMAT])
    story = open(args['filename']).readlines()

    for line in story:
        if line.startswith('#postdate'):
            string = line.replace('#postdate','').strip()
        else: continue # doesn't match? try next line
        for format in time_formats:
            try:
                new_mtime = time.mktime((time.strptime(string, format)))
            except ValueError: # more details if necessary
                #ValueError: time data did not match format:  data=  fmt=
                pass
        if new_mtime == old_mtime:
            print "Warning: none of %s matches %s" % (time_formats, string)
        args['mtime'] = tuple(list(stattuple[:8]) +
                                  [new_mtime] + list(stattuple[9:]))
        break

    return args
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.