# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
If a filename contains a timestamp in the form of YYYY-MM-DD-hh-mm,
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.
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 2004, 2005 Tim Roberts
"""
## Leo: tab_width=-4 page_width=80
# vim: tabstop=4 shiftwidth=4
import os, re, time
__author__ = 'Tim Roberts http://www.probo.com/timr/blog/'
__version__ = '$Id: pyfilenamemtime.py,v 2872b22e2ace 2011/10/27 07:08:25 zoomquiet+hg $'
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"]
stattuple = args["mtime"]
mtime = 0
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])
mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1))
except:
# TODO: Some sort of debugging code here?
pass
if mtime:
args["mtime"] = tuple(list(stattuple[:8]) + [mtime] + list(stattuple[9:]))
return args
"""
Summary
=======
This plugin is maintained at::
http://www.bluesock.org/~willg/pyblosxom/
Check that URL for new versions, better documentation, and submitting
bug reports and feature requests.
Usage
=====
This plugin goes through all the plugins you have installed on your blog
and extracts information about the plugin.
To kick it off, the url starts with ``/plugin_info`` .
If there are plugins you want to run that you don't want showing up,
list them in the ``plugininfo_hide`` property of your ``config.py`` file::
py["plugininfo_hide"] = ["myplugin", "myotherplugin"]
It takes a list of strings.
----
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 2002-2007 Will Guaraldi
SUBVERSION VERSION: $Id: plugininfo.py,v 2872b22e2ace 2011/10/27 07:08:25 zoomquiet+hg $
Revisions:
2007-07-07 - Converted documentation to restructured text.
2007-05-19 - Brushed up the code, fixed documentation, ...
2005-11-11 - Pulled into another new version control system
1.8 - (26 October, 2005) pulled into new version control system
1.7 - (09 December, 2004) fixed date_head issue and stopped showing
docstrings
1.6 - (04 May 2004) added comment handling
1.5 - (18 February 2004) added the ability to "hide" plugins so that
we don't talk about them
1.4 - (17 February 2004) added alphabetical sorting of plugins and fixed
num_entries issue
1.3 - (14 July 2003) added $plugincount variable
1.2 - (5/27/2003) minor fixes in the build_entry
"""
import Pyblosxom.plugin_utils
import Pyblosxom.entries.base
import time
import os.path
__author__ = "Will Guaraldi - willg at bluesock dot org"
__version__ = "$Date: 2011/10/27 07:08:25 $"
__url__ = "http://www.bluesock.org/~willg/pyblosxom/"
__description__ = "Shows information about plugins that you're running."
TRIGGER = "/plugin_info"
def verify_installation(request):
config = request.getConfiguration()
# check to see if the user has specified the "plugininfo_hide"
# property
if not config.has_key("plugininfo_hide"):
# the user doesn't have the property set, so we let them know
# they can set it and it prevents specified plugins from showing
# up.
print "Note: You can set 'plugininfo_hide' to hide plugins you " + \
"don't want showing up."
else:
# they do have plugininfo_hide set, so we verify that the value
# is valid-ish.
val = config["plugininfo_hide"]
if not type(val) in [ list, tuple ]:
print "'plugininfo_hide' must be a list of strings."
return 0
for mem in val:
if not type(mem) == str:
print "'plugininfo_hide' must be a list of strings."
return 0
return 1
def build_entry(request, mem):
"""build_entry(Request, plugin) -> PyBlosxom.entries.base.BaseEntry
Takes a plugin, extracts information from it, and builds a PyBlosxom
entry from the results. It returns the BaseEntry object.
"""
plugindata = []
plugindata.append("")
# previously we pulled __doc__, but more and more people are storing
# documentation for the plugin as well as license information--which
# isn't really what we want to show. we really want the author, version,
# and url for the plugin. currently these are stored in __author__,
# __version__, and __url__ (though those should be changed to something
# like VERSION, AUTHOR, and URL so as to avoid confusion with Python
# special things.
plugindata.append("AUTHOR: " + str(getattr(mem, "__author__", None)) + "\n")
plugindata.append("VERSION: " + str(getattr(mem, "__version__", None)) + "\n")
if hasattr(mem, "__url__"):
plugindata.append("URL: %s\n" % \
(str(mem.__url__), str(mem.__url__)))
plugindata.append(" ")
# build a dict of the metadata that generate_entry needs
d = { "title": mem.__name__,
"absolute_path": TRIGGER[1:],
"fn": mem.__name__,
"file_path": TRIGGER[1:] + "/" + mem.__name__ }
# build the body of the entry
body = "".join(plugindata)
entry = Pyblosxom.entries.base.generate_entry(request, d, body, None)
return entry
def cb_prepare(args):
request = args["request"]
data = request.getData()
config = request.getConfiguration()
antiplugins = config.get("plugininfo_hide", [])
plugins = Pyblosxom.plugin_utils.plugins
plugins = [m for m in plugins if m.__name__ not in antiplugins]
data["plugincount"] = len(plugins)
INIT_KEY = "plugininfo_initiated"
def cb_date_head(args):
"""
If we're showing plugins, then we don't want the date_head templates
kicking in--so we block that.
"""
request = args["request"]
data = request.getData()
if data.has_key(INIT_KEY):
args["template"] = ""
return args
def cb_staticrender_filelist(args):
"""
This is test code--trying to work additional bits into the static
renderer.
"""
request = args["request"]
filelist = args["filelist"]
flavours = args["flavours"]
config = request.getConfiguration()
antiplugins = config.get("plugininfo_hide", [])
plugins = Pyblosxom.plugin_utils.plugins
plugins = [m for m in plugins if m.__name__ not in antiplugins]
if plugins:
for mem in plugins:
url = os.path.normpath(TRIGGER + "/" + mem.__name__ + ".")
for f in flavours:
filelist.append( (url + f, "") )
for f in flavours:
filelist.append( (os.path.normpath(TRIGGER + "/index." + f), "") )
def cb_filelist(args):
request = args["request"]
pyhttp = request.getHttp()
data = request.getData()
config = request.getConfiguration()
if not pyhttp["PATH_INFO"].startswith(TRIGGER):
return
data[INIT_KEY] = 1
data['root_datadir'] = config['datadir']
config['num_entries'] = 9999
entry_list = []
antiplugins = config.get("plugininfo_hide", [])
plugins = Pyblosxom.plugin_utils.plugins
plugins = [m for m in plugins if m.__name__ not in antiplugins]
pathinfo = pyhttp["PATH_INFO"]
# if the browser requested the TRIGGER or TRiGGER/index, then we
# kick in and show plugin information for all plugins.
if pathinfo == TRIGGER or pathinfo.startswith(TRIGGER + "/index"):
plugins.sort(lambda x,y: cmp(x.__name__, y.__name__))
for mem in plugins:
entry_list.append(build_entry(request, mem))
return entry_list
# the browser requested to see information on a specific plugin.
# we need to pull off the flavour that was requested
# (if there was one). FIXME - this is a good candidate for a tools
# function.
pathinfo = pathinfo[len(TRIGGER):]
if pathinfo.startswith("/"): pathinfo = pathinfo[1:]
if pathinfo.endswith("/"): pathinfo = pathinfo[:-1]
filename, ext = os.path.splitext(pathinfo)
if ext[1:]:
data["flavour"] = ext[1:]
d = {}
for mem in plugins:
d[mem.__name__] = mem
# if the browser requested to look at a specific plugin, then
# we only show that one.
if d.has_key(filename):
return [build_entry(request, d[filename])]
# if the plugin the browser requested isn't in the list of
# plugins, then we return an empty list of entries--PyBlosxom
# will show a "that doesn't exist" message for that.
return []
# vim: tabstop=4 shiftwidth=4
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4
"""
- zoomq 100419 fixed for export month/year with count
Walks through your blog root figuring out all the available monthly archives in
your blogs. It generates html with this information and stores it in the
$archivelinks variable which you can use in your head or foot templates.
You can format the output with the key "archive_template".
A config.py example:
py['archive_template'] = ' %(m)s/%(y)s'
Displays the archives as list items, with a month number slash year number, like 06/78.
The vars available with typical example values are:
b 'Jun'
m '6'
Y '1978'
y '78'
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 2004, 2005 Wari Wahab
"""
__author__ = "Wari Wahab - wari at wari dot per dot sg"
__version__ = "$Id: zqarchives.py,v 2872b22e2ace 2011/10/27 07:08:25 zoomquiet+hg $"
__url__ = "http://blog.zoomquiet.org/pyblosxom/techic/PyBlosxom/plugins/zqarchives.html"
from Pyblosxom import tools
import time, os
def verify_installation(request):
config = request.get_configuration()
if not config.has_key("archive_template"):
print "missing optional config property 'archive_template' which "
print "allows you to specify how the archive links are created. "
print "refer to pyarchive plugin documentation for more details."
return 1
class PyblArchives:
def __init__(self, request):
self._request = request
self._archives = None
def __str__(self):
if self._archives == None:
self.gen_linear_archive()
return self._archives
def gen_linear_archive(self):
config = self._request.get_configuration()
data = self._request.get_data()
root = config["datadir"]
archives = {}
archive_list = tools.walk(self._request, root)
fulldict = {}
fulldict.update(config)
fulldict.update(data)
template = config.get('archive_template',
' %(y)s.%(m)s')
# %(Y)s-%(b)s
#print fulldict["base_url"]
for mem in archive_list:
timetuple = tools.filestat(self._request, mem)
timedict = {}
for x in ["B", "b", "m", "Y", "y"]:
timedict[x] = time.strftime("%" + x, timetuple)
fulldict.update(timedict)
if not archives.has_key(timedict['Y'] + timedict['m']):
archives[timedict['Y'] + timedict['m']] = [template % fulldict,1]
else:
archives[timedict['Y'] + timedict['m']][1] += 1
archives[timedict['Y'] + timedict['m']][0] = template % fulldict
#print archives
#return
arc_keys = archives.keys()
arc_keys.sort()
arc_keys.reverse()
yearmonth = {}
result = []
#base archives walk and count every year's mounth
for key in arc_keys:
yearname = key[:-2]
if yearname in yearmonth.keys():
yearmonth[yearname][0] += archives[key][1]
yearmonth[yearname][1].append(archives[key])
else:
yearmonth[yearname] = [archives[key][1],[]]
yearmonth[yearname][1].append(archives[key])
#print yearmonth["2007"]
mon_keys = yearmonth.keys()
mon_keys.sort()
mon_keys.reverse()
#print mon_keys
for year in mon_keys:
#print "%s %s"%(year,yearmonth[year][0])
monode = yearmonth[year][1]
result.append("%s(%d)"%(fulldict["base_url"],year,year,yearmonth[year][0]))
if 1==len(monode):
#print "%s%s"%(monode[0][0],monode[0][1])
result.append("%s(%d)"%(monode[0][0],monode[0][1]))
else:
for m in monode:
#print m
#print "%s%s"%(m[0],m[1])
result.append("%s(%d)"%(m[0],m[1]))
#result.append("%s%s"%(month[0],month[1]))
#print result
self._archives = '\n'.join(result)
def cb_prepare(args):
request = args["request"]
data = request.get_data()
data["archivelinks"] = PyblArchives(request)
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4
"""
- 仅仅要求可以根据指定顺序输出分类目录
Walks through your blog root figuring out all the categories you have
and how many entries are in each category. It generates html with
this information and stores it in the $categorylinks variable which
you can use in your head or foot templates.
You can format the output by setting "category_begin", "category_item",
"category_end" and properties.
Categories exist in a hierarchy. "category_start" starts the category listing
and is only used at the very beginning. The "category_begin" property begins a
new category group and the "category_end" property ends that category group.
The "category_item" property is the template for each category item. Then
after all the categories are printed, "category_finish" ends the category
listing.
For example, the following properties will use
to close a category and for each item:
py["category_start"] = ""
py["category_begin"] = ""
py["category_item"] = r'- %(category)s
'
py["category_end"] = " "
py["category_finish"] = ""
Another example, the following properties don't have a begin or an end but
instead use indentation for links and displays the number of entries in that
category:
py["category_start"] = ""
py["category_begin"] = ""
py["category_item"] = r'%(indent)s%(category)s (%(count)d) '
py["category_end"] = ""
py["category_finish"] = ""
There are no variables available in the category_begin or category_end
templates.
Available variables in the category_item template:
variable example datatype
======== ======= ========
base_url http://joe.com/blog/ string
fullcategory_urlencoded 'dev/pyblosxom/status/' string
fullcategory 'dev/pyblosxom/status/' string (urlencoded)
category 'status/' string
category_urlencoded 'status/' string (urlencoed)
flavour 'html' string
count 70 int
indent ' ' string
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 2004, 2005, 2006 Will Guaraldi
"""
__author__ = "Will Guaraldi - willg at bluesock dot org"
__version__ = "$Id: zqcategories.py,v 2872b22e2ace 2011/10/27 07:08:25 zoomquiet+hg $"
__url__ = "http://blog.zoomquiet.org/pyblosxom/techic/PyBlosxom/plugins/zqcategories.html"
#__url__ = "http://pyblosxom.sourceforge.net/"
__description__ = "Builds a list of categories."
from Pyblosxom import tools
import re, os
DEFAULT_START = r''
DEFAULT_BEGIN = r''
DEFAULT_ITEM = r'- %(category)s (%(count)d)
'
DEFAULT_END = " "
DEFAULT_FINISH = " "
DEFAULT_ROOT = []
def verify_installation(request):
config = request.getConfiguration()
if not config.has_key("category_template"):
print "missing optional config property 'category_template' which allows "
print "you to specify how the category hierarchy is rendered. see"
print "the documentation at the top of the pycategories plugin code "
print "file for more details."
return 1
class PyblCategories:
def __init__(self, request):
self._request = request
self._categories = None
config = self._request.getConfiguration()
self._baseurl = config.get("base_url", "")
self.genCategories()
def __str__(self):
if self._categories == None:
self.genCategories()
return self._categories
def genCategories(self):
config = self._request.getConfiguration()
root = config["datadir"]
start_t = config.get("category_start", DEFAULT_START)
begin_t = config.get("category_begin", DEFAULT_BEGIN)
item_t = config.get("category_item", DEFAULT_ITEM)
end_t = config.get("category_end", DEFAULT_END)
finish_t = config.get("category_finish", DEFAULT_FINISH)
#zoomq: configed order by mind the catrgorise
root_path_list = config.get("category_root_list", DEFAULT_ROOT)
cfgBaseUrl = config.get("base_url", "")
form = self._request.getForm()
flavour = (form.has_key('flav') and form['flav'].value or
config.get('default_flavour', 'html'))
#print flavour
# build the list of all entries in the datadir
output = ""
#@others
if 0==len(root_path_list): #as default walk and export Categories as word order
elist = tools.Walk(self._request, root)
output += self._subCategories(elist,root,"")
else:
for rootCategory in root_path_list:
subroot = "%s/%s"%(root,rootCategory)
self._baseurl = "%s/%s"%(cfgBaseUrl,rootCategory)
elist = tools.Walk(self._request, subroot)
output += self._subCategories(elist,subroot,rootCategory)
# then we join the list and that's the final string
#self._categories = "\n".join(output)
self._categories = output
def _subCategories(self,elist,root,rootname):
config = self._request.getConfiguration()
form = self._request.getForm()
flavour = (form.has_key('flav') and form['flav'].value or
config.get('default_flavour', 'html'))
start_t = config.get("category_start", DEFAULT_START)
begin_t = config.get("category_begin", DEFAULT_BEGIN)
item_t = config.get("category_item", DEFAULT_ITEM)
end_t = config.get("category_end", DEFAULT_END)
finish_t = config.get("category_finish", DEFAULT_FINISH)
# peel off the root dir from the list of entries
elist = [mem[len(root)+1:] for mem in elist]
# go through the list of entries and build a map that
# maintains a count of how many entries are in each
# category
elistmap = {}
for mem in elist:
mem = os.path.dirname(mem)
elistmap[mem] = 1 + elistmap.get(mem, 0)
self._elistmap = elistmap
#print self._elistmap
# go through the elistmap keys (which is the list of
# categories) and for each piece in the key (i.e. the key
# could be "dev/pyblosxom/releases" and the pieces would
# be "dev", "pyblosxom", and "releases") we build keys
# for the category list map (i.e. "dev", "dev/pyblosxom",
# "dev/pyblosxom/releases")
clistmap = {}
for mem in elistmap.keys():
mem = mem.split(os.sep)
for index in range(len(mem)+1):
p = os.sep.join(mem[0:index])
clistmap[p] = 0
# then we take the category list from the clistmap and
# sort it alphabetically
clist = clistmap.keys()
clist.sort()
output = []
indent = 0
output.append(start_t)
# then we generate each item in the list
for item in clist:
itemlist = item.split(os.sep)
num = 0
for key in self._elistmap.keys():
if item == '' or key == item or key.startswith(item + os.sep):
num = num + self._elistmap[key]
if not item:
tab = ""
else:
tab = len(itemlist) * " "
if indent > len(itemlist):
for i in range(indent - len(itemlist)):
output.append(end_t)
elif indent < len(itemlist):
for i in range(len(itemlist) - indent):
output.append(begin_t)
# now we build the dict with the values for substitution
d = { "base_url": self._baseurl,
"fullcategory": item + "/",
"category": itemlist[-1] + "/",
"flavour": flavour,
"count": num,
"indent": tab }
# this prevents a double / in the root category url
if item == "":
d["fullcategory"] = item
#print d
# this adds urlencoded versions
d["fullcategory_urlencoded"] = tools.urlencode_text(d["fullcategory"])
d["category_urlencoded"] = tools.urlencode_text(d["category"])
# and we toss it in the thing
output.append(item_t % d)
indent = len(itemlist)
output.append(end_t * indent)
output.append(finish_t)
# export define item's name
output[2] = output[2].replace(">/"," class='rootcategory'>%s/"%rootname)
return "\n".join(output)
def cb_prepare(args):
request = args["request"]
data = request.getData()
data["categorylinks"] = PyblCategories(request)
|