python 清除 nginx 反向代理 单 url 缓存代码

#!/usr/bin/env python
'''
Clear nginx a url cache
'''
import os
try:
    from hashlib import md5
except:
    from md5 import md5



url=raw_input('Please enter url : ')
isClr=raw_input("You sure you want to clear  '%s'   cache ? (y/n)   " % url)
if isClr=='y' or isClr=='Y' :
    m=md5()
    m.update("%s" % url)
    md5url=m.hexdigest()
    md5urllen=len(md5url)
    dir1=md5url[md5urllen-1:]
    dir2=md5url[md5urllen-3:md5urllen-1]
    dirPath=("/usr/local/nginx/proxy_cache/%s/%s/%s" % (dir1, dir2, md5url))
    isDel=raw_input("Will be deleted : %s (y/n)   " % dirPath)
    if isDel=='y' or isDel=='Y' :
        if(os.path.exists(dirPath)) :
            os.remove(dirPath)
            print 'delete success'
        else :
            print 'file not find'

posted on 2012-10-10 15:26  多个马甲  阅读(461)  评论(0编辑  收藏  举报