2
# Package SunPinyin for release
4
import sys, os, commands, time, plistlib
7
from jinja2 import Environment, FileSystemLoader
9
print "Install jinja2 first."
12
env = Environment(loader=FileSystemLoader('.'))
13
plist = plistlib.readPlist("../build/SunPinyin.app/Contents/Info.plist")
15
url_base = "http://sunpinyin.googlecode.com/files/"
16
xml_url_base = "http://release.sunpinyin.googlecode.com/hg/"
17
appcast_url = xml_url_base + "SunpinyinAppcast.xml"
19
pack_proj = "SunPinyin/SunPinyin.packproj"
20
pkg = "SunPinyin/build/SunPinyin.pkg"
21
resource_dir = "../build/SunPinyin.app/Contents/Resources"
23
version = plist["CFBundleVersion"]
24
releasenotes_url = xml_url_base + "SunpinyinReleaseNotes.xml"
26
zip = "SunPinyin-MacOS-%s.zip" % version
27
file_url = url_base + zip
29
priv_key = "%s/.ssh/dsa_priv.pem" % os.path.expanduser('~')
30
date = time.strftime("%a, %d %b %Y %H:%M:%S %z")
31
appcast_template = 'appcast.template.xml'
32
appcast = "sunpinyin_appcast.xml"
35
priv_key = sys.argv[1]
37
def remove_if_exists(file):
38
if os.path.isfile(file):
41
print "[PACK] Remove temporary files..."
43
#remove_if_exists("%s/lm_sc.t3g" % resource_dir)
44
#remove_if_exists("%s/pydict_sc.bin" % resource_dir)
46
print "[PACK] Building %s..." % pkg
48
os.system("freeze -v %s" % pack_proj)
50
print "[PACK] Compressing %s..." % zip
51
os.chdir("SunPinyin/build")
52
os.system("zip -y -r ../../%s SunPinyin.pkg" % zip)
55
print "[PACK] Signing %s..." % zip
56
signed = commands.getoutput('openssl dgst -sha1 -binary < "%s" | openssl dgst -dss1 -sign "%s" | openssl enc -base64' % (zip, priv_key))
58
print "[PACK] Generating %s..." % appcast
59
template = env.get_template(appcast_template)
61
output = open(appcast, "w")
63
output.write(template.render(link=appcast_url,
64
releaseNotesLink=releasenotes_url,
68
length=os.path.getsize(zip),
69
signed=signed).encode("utf-8"))
73
print "Done! Please:\n 1. Publish %s to %s\n 2. Publish %s to %s\n 3. Update the release note for version %s at %s." % (appcast, appcast_url, zip, file_url, version, releasenotes_url)