Tuesday, July 30, 2013
Clear cache by python
I'm learning programming python, this is my script python to show list folder and clear file on them. :) #!/usr/sbin/python
import os
import subprocess
class CachedNginx:
def __init__(self):
pass
def clearCached(self, folder):
strDir = "rm -rf /dir/"
strDir += folder
strDir += "/*"
print (strDir)
result = subprocess.Popen(strDir, stdout=subprocess.PIPE, shell=True)
data, error = result.communicate()
if error == None:
print ("Clear success")
def listCached(cachedNginx):
list = subprocess.Popen("ls /dir/",stdout=subprocess.PIPE, shell=True)
data,error = list.communicate()
print ("You choise cache to clear : ")
number = 0
lists = {}
for cache in iter(data.splitlines()):
print ("["+ str(number) +"]" + cache.decode("utf-8"))
lists[str(number)] = cache.decode("utf-8")
number += 1
choise = input("Select number choise : ")
if int(choise) < number:
cachedNginx.clearCached(lists[choise])
def main():
cached = CachedNginx()
listCached(cached)
if __name__ == '__main__':
main()
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment