'''
Created on 2013-6-6
@author: DengWei
'''
import zipfile
import os
import shutil
import sys
class Zip(object):
@staticmethod
def zip_dir(dirname, zipfilename):
# def writeFile(pathname, basename=""):
# for filepath in os.listdir(pathname):
# if os.path.isfile(dirname):
# if basename:
# zf.write(dirname, basename)
# else:
# zf.write(dirname)
# else:
# dir, name = os.path.split(filepath)
# if basename:
# basename = "%s/%s" % (basename, name)
# else:
# basename = name
# writeFile(dir, basename)
#
# zf = zipfile.ZipFile(zipfilename, 'w', zipfile.zlib.DEFLATED)
#
# writeFile(dirname)
os.system("compress.bat %s %s;"%(dirname, zipfilename))
@staticmethod
def unzip_file(zipfilename, unziptodir):
if os.path.exists(unziptodir):
shutil.rmtree(unziptodir)
os.mkdir(unziptodir)
zipobj = zipfile.ZipFile(zipfilename)
zipobj.extractall(apkNameWithoutExt)
if __name__ == "__main__":
# APK_FOLDER ="c:\sinaNews3.2.1_52_release_wm_5062_0001_0520.apk"
APK_FOLDER = sys.argv[-1]
apkName = os.path.basename(APK_FOLDER)
apkNameWithoutExt = apkName[0:-4]
Zip.unzip_file(APK_FOLDER, apkNameWithoutExt)
shutil.rmtree(os.path.join(os.getcwd(), apkNameWithoutExt, "META-INF"))
Zip.zip_dir(apkNameWithoutExt, os.path.join(os.getcwd(), apkNameWithoutExt+"_sign.zip"))
shutil.move(apkNameWithoutExt+"_sign.zip", apkNameWithoutExt+"_sign.apk")
shutil.rmtree(os.path.join(os.getcwd(), apkNameWithoutExt))
@echo off
title 批量压缩rar文件
if EXIST tmp_t del tmp_t
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe" /v path>>tmp_t
for /f "tokens=1,2,* skip=4 delims= " %%j in ('more tmp_t') do set WinRAR=%%l
if EXIST tmp_t del tmp_t
set dst = %1
cd %1
"%WinRAR%\rar" a -r %2
EndLocal