hardcodedates plugin patch

Ryan Barrett <pyblosxom-6sb6M7qyT/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
hi nathan, pyblosxom-devel. i'm attaching a small patch to the hardcodedates
plugin. with this patch, when hardcodedates sees an entry that it doesn't have
in the timestamps file, it keeps track of it. when pyblosxom shuts down,
hardcodedates appends the new files and mtimes to the timestamps file.

this effectively switches pyblosxom from mtime to ctime (roughly) for ordering
blog posts. when an entry is first added, hardcodedates will notice it and
store its mtime. if it's later modified, the mtime in the timestamps file will
remain the same.

with my filestat patch, it also means that hardcodedates acts as a persistent
file stat cache. (woo!)

-Ryan

--
http://snarfed.org/

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

_______________________________________________
Pyblosxom-devel mailing list
Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
hardcodedates_save_mtimes.patch (text/plain, 3.2 KB)
*** /home/ryanb/pyblosxom-etc/hardcodedates.py	Fri Jul 14 20:47:30 2006
--- ./hardcodedates.py	Mon Sep  4 21:16:39 2006
***************
*** 17,34 ****
  __version__ = '1.2'
  
  from Pyblosxom import tools
! import os, re, time, sys
  
  FILETIME = re.compile('^([0-9]{4})-([0-1][0-9])-([0-3][0-9])-([0-2][0-9])-([0-5][0-9]) +(.*)$')
  
  all_timestamps = None
  
  def get_all_timestamps(datadir):
  	f = open(datadir + "/timestamps")
! 	t = []
! 	while True:
! 		str = f.readline()
! 		if str == "": break
  		m = FILETIME.search(str.strip())
  		if m:
  			year = int(m.group(1))
--- 17,34 ----
  __version__ = '1.2'
  
  from Pyblosxom import tools
! import os, os.path, re, time
  
  FILETIME = re.compile('^([0-9]{4})-([0-1][0-9])-([0-3][0-9])-([0-2][0-9])-([0-5][0-9]) +(.*)$')
  
  all_timestamps = None
+ extensions = None
+ timestamps_to_save = {}
  
  def get_all_timestamps(datadir):
  	f = open(datadir + "/timestamps")
! 	t = {}
! 	for str in f.readlines():
  		m = FILETIME.search(str.strip())
  		if m:
  			year = int(m.group(1))
***************
*** 38,44 ****
  			minute = int(m.group(5))
  			mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1))
  			
! 			t.append( (datadir + "/" + m.group(6), mtime) )
  
  	f.close()
  	return t
--- 38,44 ----
  			minute = int(m.group(5))
  			mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1))
  			
! 			t[datadir + "/" + m.group(6)] = mtime
  
  	f.close()
  	return t
***************
*** 47,61 ****
  	global all_timestamps
  
  	filename = args["filename"]
- 	stattuple = args["mtime"]
  
! 	for fname,mtime in all_timestamps:
! 		if fname == filename:
! 			args["mtime"] = tuple(list(stattuple[:8]) + [mtime] + list(stattuple[9:]))
! 			break
! 	
  	return args
  
  def cb_start(args):
! 	global all_timestamps
  	all_timestamps = get_all_timestamps(args["request"].getConfiguration()['datadir'])
--- 47,81 ----
  	global all_timestamps
  
  	filename = args["filename"]
  
! 	if all_timestamps.has_key(filename):
! 		# we know this file's timestamp
! 		args['mtime'][8] = all_timestamps[filename]
! 
! 	elif os.path.splitext(filename)[1] in extensions:
! 		# we don't know it, but we should. ask the os for it, and remember it.
! 		args['mtime'] = os.stat(filename)
! 		all_timestamps[filename] = args['mtime'][8]
! 		timestamps_to_save[filename] = args['mtime'][8]
! 
  	return args
  
  def cb_start(args):
! 	global all_timestamps, extensions
! 	request = args['request']
! 
  	all_timestamps = get_all_timestamps(args["request"].getConfiguration()['datadir'])
+ 
+ 	extensions = request.getData()['extensions'].keys()
+ 	extensions.append(request.getConfiguration().get('comment_ext', ''))
+ 
+ def cb_end(args):
+ 	if timestamps_to_save:
+ 		datadir = args["request"].getConfiguration()['datadir']
+ 		tsfile = file(datadir + "/timestamps", 'a')
+ 		for filename, mtime in timestamps_to_save.items():
+ 			time_str = time.strftime('%Y-%m-%d-%H-%M', time.localtime(mtime))
+ 			tilename = filename[len(datadir) + 1:]
+ 			tsfile.write('%s %s\n' % (time_str, filename))
+ 			tools.getLogger().info('Saved mtime %s for %s' % (time_str, filename))
+ 		tsfile.close()
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.