-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage_sdk.py
49 lines (46 loc) · 1.7 KB
/
package_sdk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import zipfile
import sys
import os
def zip_folder(zip_file, folder_path):
"""Zip the contents of an entire folder (with that folder included
in the archive). Empty subfolders will be included in the archive
as well.
"""
parent_folder = os.path.dirname(folder_path)
# Retrieve the paths of the folder contents.
contents = os.walk(folder_path)
try:
for root, folders, files in contents:
# Include all subfolders, including empty ones.
for folder_name in folders:
absolute_path = os.path.join(root, folder_name)
relative_path = absolute_path.replace(parent_folder + '\\',
'')
print "Adding '%s' to archive." % absolute_path
zip_file.write(absolute_path, relative_path)
for file_name in files:
absolute_path = os.path.join(root, file_name)
relative_path = absolute_path.replace(parent_folder + '\\',
'')
print "Adding '%s' to archive." % absolute_path
zip_file.write(absolute_path, relative_path)
except IOError, message:
print message
sys.exit(1)
except OSError, message:
print message
sys.exit(1)
except zipfile.BadZipfile, message:
print message
sys.exit(1)
print 'creating archive'
filename = 'Gameeso-iOS-SDK.zip'
zf = zipfile.ZipFile(filename, mode='w')
try:
for f in ['README.md', 'LICENSE.txt']:
print "Adding '%s' to archive." % f
zf.write(f)
zip_folder(zf, 'OpenKitSDK/')
finally:
zf.close()
print 'SDK has been built!'