Skip to content

Instantly share code, notes, and snippets.

@zqqf16
Created March 16, 2014 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zqqf16/9583574 to your computer and use it in GitHub Desktop.
Save zqqf16/9583574 to your computer and use it in GitHub Desktop.
根据ipa包来生成Manifest的工具
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
import shutil
import zipfile
import biplist
PLIST_STR = '''<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>{ipa_url}</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>http://display.png</string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>http://full.png</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>{identifier}</string>
<key>bundle-version</key>
<string>{version}</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>{name}</string>
<key>title</key>
<string>{title}</string>
</dict>
</dict>
</array>
</dict>
</plist>
'''
class IPA(object):
info_plist_re = re.compile(r'Payload/.*\.app/Info.plist')
def __init__(self, file_name, **settings):
self.file_name = file_name
info = None
zip_file = zipfile.ZipFile(file_name)
all_files = zip_file.namelist()
for f in all_files:
if self.info_plist_re.match(f):
info = f
break
if not info:
print('Info.plist not found')
return
plist = biplist.readPlistFromString(zip_file.read(info))
self.version = plist.get('CFBundleShortVersionString')
self.build = plist.get('CFBundleVersion')
self.identifier = plist.get('CFBundleIdentifier')
self.name = plist.get('CFBundleDisplayName').encode('utf-8')
if not self.version:
raise KeyError('Version not found')
if not self.identifier:
raise KeyError('Identifier not found')
if not self.name:
raise KeyError('Name not found')
def manifest(self, base_url, name_format='{name}_{version}_{build}.ipa'):
'''Get manifest string
@param base_url: base url of the ipa file
@param name_format: name format of the ipa file, available keys: name, version, build
'''
attributes = {
'name': self.name,
'version': self.version.replace('.', '_'),
'build': self.build
}
url = (base_url + name_format).format(**attributes)
return PLIST_STR.format(ipa_url=url,
version=self.version,
identifier=ipa.identifier,
name=ipa.name,
title=ipa.name)
if __name__ == '__main__':
ipa = IPA(sys.argv[1])
print ipa.manifest('http://10.10.10.10/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment