Skip to content

Instantly share code, notes, and snippets.

@jackyzonewen
Forked from jk2K/appcrush.py
Created April 9, 2016 14:32
Show Gist options
  • Save jackyzonewen/c2ff76511f82515c4f5a4827a3b687b4 to your computer and use it in GitHub Desktop.
Save jackyzonewen/c2ff76511f82515c4f5a4827a3b687b4 to your computer and use it in GitHub Desktop.
appcrush.rb的python版本
# coding=utf-8
import os
import sys
import glob
pngcrush = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush"
destination = os.path.join(os.environ['HOME'], 'Desktop')
for ipa in sys.argv:
if os.path.splitext(ipa)[1] == '.ipa':
# Get the app name by stripping out the extension from the file name
# 获取剔除了扩展名的app名称
app_name = os.path.splitext(ipa)[0]
# Get the expanded dir by stripping out the extension from the file path
# 获取剔除了扩展名的文件路径
expanded_dir = os.path.join(os.getcwd(), app_name)
# In case the dir is already there, try and remove it
# 以防ipa已经解压缩, 尝试删除解压缩后的文件
os.system("rm -drf '{0}'".format(expanded_dir))
# Extract .ipa zip file
# 解压缩ipa
os.system("unzip -q '{0}' -d '{1}'".format(ipa, expanded_dir))
images_dir_path = os.path.join(destination, "{0} Images".format(app_name))
# In case the destination directory is already there, try and remove it
# 以防目的文件夹已存在, 尝试删除这个文件夹
os.system("rm -drf '{0}'".format(images_dir_path))
# Create the destination directory
# 创建目的文件夹
os.mkdir(images_dir_path)
# Iterate through all png images
# 处理所有的png图片
for png_file in glob.glob(os.path.join(expanded_dir, 'Payload', "*.app", '*.png')):
# and revert the iphone optimizations
# 取消xcode对png图片的压缩
png_crush_command = "{0} -q -revert-iphone-optimizations -d '{1}' '{2}'".format(pngcrush, images_dir_path, png_file)
# puts "#{png_crush_command}"
# 执行pngcrush命令
os.system(png_crush_command)
# Iterate through all jpg images
# 处理所有的jpg图片
for jpg_file in glob.glob(os.path.join(expanded_dir, 'Payload', "*.app", '*.jpg')):
# and move each to the destination directory
# 移动jpg图片至目的文件夹
os.system("mv '{0}' '{1}'".format(jpg_file, images_dir_path))
# Cleanup. Delete the expanded dir
# 清理, 删除解压缩目录
os.system("rm -drf '{0}'".format(expanded_dir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment