#!/usr/bin/env python import sys # sys.argv[1] import os # os.walk(home) import gzip # gzip.open(filename) import commands # commands.getoutput home = "./FFCache/" if sys.argv[1:]: home = sys.argv[1] cachedata = "../../Documents/cachedata/" #commands.getoutput('chmod -R ../../Documents') #if sys.argv[2:]: cachedata = sys.argv[2] #commands.getoutput('rm -R cachedata') #commands.getoutput('rmdir cachedata') #os.mkdir(cachedata) #print "Making directory ", cachedata, "for copying cached files.\n" for root, dirs, files in os.walk(home): for filename in files: if "_CACHE_" in filename: continue content = None try: f = gzip.open(root + filename,"rb") data = f.read() if 'PNG' in data[:10]: content = "png" elif 'GIF89a' in data[:10]: content = "gif" elif 'JFIF' in data[:10]: content = "jpeg" elif 'HTML' in data[:20]: content = "html" elif 'html' in data[:20]: content = "html" else: continue #print "Copying ",filename," -> ", cachedata + filename +"."+ content #print data[:20] f_out = open(cachedata + filename +"."+ content, "wb") f_out.write(data) #os.chmod(f_out, 0777) except IOError: f = open(root + filename,"rb") data = f.read() if 'PNG' in data[:10]: content = "png" elif 'GIF89a' in data[:10]: content = "gif" elif 'JFIF' in data[:10]: content = "jpeg" elif 'HTML' in data[:20]: content = "html" elif 'html' in data[:20]: content = "html" else: continue #print "Copying ",filename," -> ", cachedata + filename +"."+ content #print data[:50] f_out = open(cachedata + filename +"." + content, "wb") f_out.write(data) #os.chmod(f_out, 0777) commands.getoutput('chmod -R 777 cachedata')