2011-03-21 16:42:21 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2011-03-27 05:23:14 +00:00
|
|
|
# <pep8 compliant>
|
|
|
|
|
2011-03-21 16:42:21 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# todo:
|
|
|
|
# strip executables
|
|
|
|
|
|
|
|
# get parameters
|
|
|
|
if len(sys.argv) < 5:
|
2011-03-21 23:30:56 +00:00
|
|
|
sys.stderr.write('Excepted arguments: ./build_archive.py name extension install_dir output_dir')
|
|
|
|
sys.exit(1)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
|
|
|
package_name = sys.argv[1]
|
|
|
|
extension = sys.argv[2]
|
|
|
|
install_dir = sys.argv[3]
|
|
|
|
output_dir = sys.argv[4]
|
|
|
|
|
|
|
|
package_archive = os.path.join(output_dir, package_name + '.' + extension)
|
|
|
|
package_dir = package_name
|
|
|
|
|
|
|
|
# remove existing package with the same name
|
|
|
|
try:
|
2011-03-21 23:30:56 +00:00
|
|
|
if os.path.exists(package_archive):
|
|
|
|
os.remove(package_archive)
|
|
|
|
if os.path.exists(package_dir):
|
|
|
|
shutil.rmtree(package_dir)
|
2011-03-22 08:58:49 +00:00
|
|
|
except Exception, ex:
|
|
|
|
sys.stderr.write('Failed to clean up old package files: ' + str(ex) + '\n')
|
2011-03-21 23:30:56 +00:00
|
|
|
sys.exit(1)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
|
|
|
# create temporary package dir
|
|
|
|
try:
|
2011-03-21 23:30:56 +00:00
|
|
|
shutil.copytree(install_dir, package_dir)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
2011-03-21 23:30:56 +00:00
|
|
|
for f in os.listdir(package_dir):
|
|
|
|
if f.startswith('makes'):
|
|
|
|
os.remove(os.path.join(package_dir, f))
|
2011-03-22 08:58:49 +00:00
|
|
|
except Exception, ex:
|
|
|
|
sys.stderr.write('Failed to copy install directory: ' + str(ex) + '\n')
|
2011-03-21 23:30:56 +00:00
|
|
|
sys.exit(1)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
|
|
|
# create archive
|
|
|
|
try:
|
2011-03-21 23:30:56 +00:00
|
|
|
if not os.path.exists(output_dir):
|
|
|
|
os.mkdir(output_dir)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
2011-03-21 23:30:56 +00:00
|
|
|
if extension == 'zip':
|
|
|
|
archive_cmd = ['zip', '-9', '-r', package_archive, package_dir]
|
|
|
|
elif extension == 'tar.bz2':
|
|
|
|
archive_cmd = ['tar', 'cjf', package_archive, package_dir]
|
|
|
|
else:
|
|
|
|
sys.stderr.write('Unknown archive extension: ' + extension)
|
|
|
|
sys.exit(-1)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
2011-03-21 23:30:56 +00:00
|
|
|
subprocess.call(archive_cmd)
|
2011-03-22 08:58:49 +00:00
|
|
|
except Exception, ex:
|
|
|
|
sys.stderr.write('Failed to create package archive: ' + str(ex) + '\n')
|
2011-03-21 23:30:56 +00:00
|
|
|
sys.exit(1)
|
2011-03-21 16:42:21 +00:00
|
|
|
|
|
|
|
# empty temporary package dir
|
|
|
|
try:
|
2011-03-21 23:30:56 +00:00
|
|
|
shutil.rmtree(package_dir)
|
2011-03-22 08:58:49 +00:00
|
|
|
except Exception, ex:
|
|
|
|
sys.stderr.write('Failed to clean up package directory: ' + str(ex) + '\n')
|
2011-03-21 23:30:56 +00:00
|
|
|
sys.exit(1)
|