Home >Backend Development >Python Tutorial >使用python删除nginx缓存文件示例(python文件操作)

使用python删除nginx缓存文件示例(python文件操作)

WBOY
WBOYOriginal
2016-06-06 11:29:311271browse

调用时输入参数如:  www.bitsCN.com/表示删除www.bitsCN.com首页的缓存, www.bitsCN.com/test.php就表示删除/test.php的缓存

代码如下:


#coding=utf8
import sys,os
import hashlib
if len(sys.argv)    print("你没有输入地址。")
    sys.exit()
path="/home/cache"#缓存目录
md5v = hashlib.md5(sys.argv[1].encode(encoding='gb2312')).hexdigest()#得到文件的hash值
onep=md5v[31:32]
twop=md5v[29:31]
filename=path+"/"+onep+"/"+twop+"/"+md5v
if os.path.isfile(filename):
    if os.remove(filename)==None:
       print(filename+" ==>清除成功")
    else:
       print("清除失败")
else:
    print("没有这个缓存文件")

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn