easy_install -mxN Genshi
然后下面类似的提示:
install_dir /usr/local/lib/python2.6/dist-packages/ Processing Genshi-0.6-py2.6.egg Removing Genshi 0.6 from easy-install.pth file Installed /usr/local/lib/python2.6/dist-packages/Genshi-0.6-py2.6.egg Because this distribution was installed --multi-version, before you can import modules from this package in an application, you will need to 'import pkg_resources' and then use a 'require()' call similar to one of these examples, in order to select the desired version: pkg_resources.require("Genshi") # latest installed version pkg_resources.require("Genshi==0.6") # this exact version pkg_resources.require("Genshi>=0.6") # this version or higher
然后删除目录:
rm -rf /usr/local/lib/python2.6/dist-packages/Genshi-0.6-py2.6.egg
Python 2.6.x
python 2.6.5 windows installer i386
python 2.6.5 windows installer amd64
python 2.6.5 source code bzipped
Python 3.x
python 3.1.2 windows installer i386
python 3.1.2 windows installer amd64
python 3.1.2 source code bzipped tarball
Docs
]]>Thinkpad屏幕顶部的键盘灯是个很有创意的设计,这个和小红点一起构成了Thinkpad的重要特色功能。
比如收到邮件后,thinklight闪烁;pidgin收到消息后,thinklight闪烁提醒。
pidgin通过pidgin-blinklight插件即可实现。
debian/ubuntu用户需要安装:
#apt-get install pidgin-blinklight
然后在pidgin的”工具” -> “插件”内启用,这样在pidgin收到消息时thinklight能闪烁三下。
同时在收到Email的时候也可以让thinklight来进行提醒,如果是evolution的,使用thinklight-notification 就可以实现,详细见:http://ubuntuforums.org/showthread.php?t=1017263
下面详细说一下thunderbird收到邮件时的thinklight闪烁。
安装thunderbird插件yamb,http://www.globs.org/download.php?lng=en。
进入thunderbird,在“工具” -> “附加软件”,进入“Yet Another Mail Biff”的配置,在”External notifier executable”内加入如下代码的执行路径:
=============================================
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import time
import sys
import signal
TL_PROC_FILE = “/proc/acpi/ibm/light”
PID_FILE = “/tmp/thinklightblink.pid”
def blink(second, filepath = TL_PROC_FILE):
try:
# open light
fp = open(filepath, “w”)
fp.seek(0)
fp.write(“on”)
fp.flush()
time.sleep(second)
fp.seek(0)
fp.write(“off”)
fp.close()
return
except Exception, inst:
print inst
return
def writepid(filepath = PID_FILE):
try:
pid = os.getpid()
fp = open(filepath, “w”)
fp.write(str(pid))
fp.close()
return
except Exception, inst:
print inst
return
def delpid(filepath = PID_FILE):
try:
if os.path.isfile(filepath):
os.remove(filepath)
return
except Exception, inst:
print inst
return
def getpid(filepath = PID_FILE):
try:
if os.path.isfile(filepath):
return int(open(filepath).read())
else:
return None
except Exception, inst:
print inst
return None
if __name__ == “__main__”:
try:
os.kill(getpid(), signal.SIGTERM)
except:
pass
writepid()
blink(1)
delpid()
=============================================
完成。测试一下thunderbird收到邮件时thinklight是否会闪动一下 😀
手动操作thinklight的方法:
echo ‘on’ > /proc/acpi/ibm/light
echo ‘off’ > /proc/acpi/ibm/light
echo 255 > /sys/class/leds/tpacpi::thinklight/brightness
echo 0 > /sys/class/leds/tpacpi::thinklight/brightness
参考文档:
http://www.thinkwiki.org/wiki/ThinkLight
http://blog.wahlig.eu/2008/04/thinklight-mail-notification.html
遂想到django统一的models抽象应该很方便对db的cache进行统一处理,所以就有以下的想法:
目前设计的cache存储的数据结构是按db的行进行cache,cache采用memcached作为存储方式,其数据结构是:
{pointer_key -> model_key}, {model_key -> model}。
point_key:以get方法查询的表名和查询参数为基础构建,例如:’user-{‘username’:’qingran}’或者 ‘user-{‘id’:1}’;
model_key:以数据库的表名和表的primary key为基础构建,例如:’user-1’,’user-2’;
model:就是models class的内容了,在db中就是符合primary key的数据行。
这样的结构能使不同的get参数只要是查询同一个表的同一个行,那么就对应同一个model数据。
cache的命中和过期:
在get的方法,现查{point_key -> model_key},然后查询{model_key -> model}最终得到数据。如果有一步命中失败,就从db取,然后回写cache。
在models进行save和delete方法的时候把{model_key -> model}的对应删除。
但是这样的存储结构目前只能缓存models.Model.objects的get方法请求。而无法对filter方法进行cache。filter cache的难点在于这个查询的结果是一个集合,而集合中的任何一个元素的修改或者新添加一个符合filter查询的数据,都会导致cache失效。
所以说解决filter查询的cache需要解决以下问题:
0,save()和delete()方法中发生时能够快速获知filter的cache是否需要立即更新。
可能”需要手动维护所有filter相关缓存的一个key清单,当你有相关数据发生变动时手动清理相关key。”
另外新增加的符合filter查询要求的元素也会引起cache的失效。
1,因为一个filter查询集合内一个元素的失效就清理整个filter集合可能会cache的更新过于频繁。
啰嗦了一堆,上代码:
===========================================
from django.core.cache import cache
from django.db import models
from django.conf import settings
DOMAIN_CACHE_PREFIX = settings.CACHE_MIDDLEWARE_KEY_PREFIX
CACHE_EXPIRE = settings.CACHE_MIDDLEWARE_SECONDS
def cache_key(model, id):
return (“%s-%s-%s” % (DOMAIN_CACHE_PREFIX, model._meta.db_table,
id)).replace(” “, “”)
class GetCacheManager(models.Manager):
# to reload the get method. cache -> db -> cache
def get(self, *args, **kwargs):
id = repr(kwargs)
# in mc, data are stored in {pointer_key -> model_key},{model_key -> model}
# pointer_key is object.get’s method parameters.
# pointer_key = ‘www-user-{‘username’:’qingran}’ or ‘www-user-{‘id’:1}’
pointer_key = cache_key(self.model, id)
# model_key is “<prefix>-<db tablename>-pk”
# model_key = ‘www-user-1’
model_key = cache.get(pointer_key)
if model_key != None:
model = cache.get(model_key)
if model != None:
return model
# cache MISS, get from db.
model = super(GetCacheManager, self).get(*args, **kwargs)
# write data back to cache from db.
if not model_key:
model_key = cache_key(model, model.pk)
cache.set(pointer_key, model_key, CACHE_EXPIRE)
cache.set(model_key, model, CACHE_EXPIRE)
return model
class ModelWithGetCache(models.Model):
# to reload the save method
def save(self, *args, **kwargs):
# first, delete cache {model_key -> model}
model_key = cache_key(self, self.pk)
cache.delete(model_key)
super(ModelWithGetCache, self).save()
# to reload the delete method
def delete(self, *args, **kwargs):
# first, delete cache {model_key -> model}
model_key = cache_key(self, self.pk)
cache.delete(model_key)
super(ModelWithGetCache, self).delete()
===============================================
在使用的时候定义models需要改从ModelWithGetCache继承,并且指定objects = GetCacheManager()
Sample:
class User(ModelWithGetCache):
objects = GetCacheManager()
…