fix archive files being created with perms 000

In python 2.5 and earlier, ZipFile.writestr(filename, data) results in
the file being added to the archive with permissions 000.  (See
http://svn.python.org/view?view=rev&revision=65235.)  Work around this
by creating a ZipInfo object and setting the permissions explicitly.
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 686c6ef..033ba22 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -21,6 +21,7 @@
 import subprocess
 import sys
 import tempfile
+import zipfile
 
 # missing in Python 2.4 and before
 if not hasattr(os, "SEEK_SET"):
@@ -70,7 +71,7 @@
   img = BuildBootableImage(sourcedir)
 
   CheckSize(img, targetname)
-  output_zip.writestr(targetname, img)
+  ZipWriteStr(output_zip, targetname, img)
 
 def BuildBootableImage(sourcedir):
   """Take a kernel, cmdline, and ramdisk directory from the input (in
@@ -381,3 +382,12 @@
       if e.errno != errno.ENOENT:
         print "error reading password file: ", str(e)
     return result
+
+
+def ZipWriteStr(zip, filename, data, perms=0644):
+  # use a fixed timestamp so the output is repeatable.
+  zinfo = zipfile.ZipInfo(filename=filename,
+                          date_time=(2009, 1, 1, 0, 0, 0))
+  zinfo.compress_type = zip.compression
+  zinfo.external_attr = perms << 16
+  zip.writestr(zinfo, data)