Home | History | Annotate | Download | only in packaging
      1 #!/usr/bin/env python
      2 # Package SunPinyin for release
      3 
      4 import sys, os, commands, time, plistlib
      5 
      6 try:
      7     from jinja2 import Environment, FileSystemLoader
      8 except:
      9     print "Install jinja2 first."
     10     sys.exit(1)
     11 
     12 env = Environment(loader=FileSystemLoader('.'))
     13 plist = plistlib.readPlist("../build/SunPinyin.app/Contents/Info.plist")
     14 
     15 url_base = "http://opensolaris.org/os/project/input-method/files/"
     16 appcast_url = url_base + "sunpinyin_appcast.xml"
     17 
     18 pack_proj = "SunPinyin/SunPinyin.packproj"
     19 pkg = "SunPinyin/build/SunPinyin.pkg"
     20 resource_dir = "../build/SunPinyin.app/Contents/Resources"
     21 
     22 version = plist["CFBundleVersion"]
     23 releasenotes_url = url_base + "sunpinyin_rn.xml"
     24 
     25 zip = "SunPinyin-%s.zip" % version
     26 file_url = url_base + zip
     27 
     28 priv_key = "%s/.ssh/dsa_priv.pem" % os.path.expanduser('~')
     29 date = time.strftime("%a, %d %b %Y %H:%M:%S %z")
     30 appcast_template = 'appcast.template.xml'
     31 appcast = "sunpinyin_appcast.xml"
     32 
     33 if len(sys.argv) > 1:
     34     priv_key = sys.argv[1]
     35 
     36 def remove_if_exists(file):
     37     if os.path.isfile(file):
     38         os.remove(file)
     39 
     40 print "[PACK] Remove temporary files..."
     41 
     42 remove_if_exists("%s/lm_sc.t3g" % resource_dir)
     43 remove_if_exists("%s/pydict_sc.bin" % resource_dir)
     44 
     45 print "[PACK] Building %s..." % pkg
     46 
     47 os.system("freeze -v %s" % pack_proj)
     48 
     49 print "[PACK] Compressing %s..." % zip
     50 os.chdir("SunPinyin/build")
     51 os.system("zip -r ../../%s SunPinyin.pkg" % zip)
     52 os.chdir("../..")
     53 
     54 print "[PACK] Signing %s..." % zip
     55 signed = commands.getoutput('openssl dgst -sha1 -binary < "%s" | openssl dgst -dss1 -sign "%s" | openssl enc -base64' % (zip, priv_key))
     56 
     57 print "[PACK] Generating %s..." % appcast
     58 template = env.get_template(appcast_template)
     59 
     60 output = open(appcast, "w")
     61 
     62 output.write(template.render(link=appcast_url,
     63         releaseNotesLink=releasenotes_url,
     64         url=file_url,
     65         date=date,
     66         version=version,
     67         length=os.path.getsize(zip),
     68         signed=signed).encode("utf-8"))
     69 
     70 output.close()
     71 
     72 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)
     73 
     74