#!/usr/bin/env python
#coding:utf-8
import sys,os,time,shutil
import urllib
import urllib2
import zipfile
import tarfile
def un_tar(file_name):
tar = tarfile.open(file_name)
names = tar.getnames()
if os.path.isdir(file_name + "_files"):
pass
else:
os.mkdir(file_name + "_files")
#因为解压后是很多文件,预先建立同名目录
for name in names:
tar.extract(name, file_name + "_files/")
tar.close()
if os.path.exists('/Applications/ImageOptim.app') == False:
print '下载'
un_tar('ImageOptim.tar')
shutil.copytree('ImageOptim.tar_files/ImageOptim.app','/Applications/ImageOptim.app')
text = os.popen('find . -name *.png').read()
images = text.split('n')
imagepaths = ''
for x in xrange(1,200):
image = images[x]
if chr(32) in image:
print '该文件不可用,请去除文件名字的空格' + image
continue
imagepaths = imagepaths + ' ' + image
os.system('open -a ImageOptim ' + imagepaths)
近期评论