#!/usr/bin/python
#
# Copyright Glyn Matthews 2008.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
"""
Creates a set of archives for the given release.
"""
__author__ = 'Glyn Matthews'
import os
import pysvn
# constants
root_url = "https://cpp-netlib.svn.sourceforge.net/svnroot/cpp-netlib"
def checkout_release(client, version, path):
""" Checkout from the tagged release. """
tag_url = "%s/tags/release/%s" % (root_url, version)
client.checkout(url=tag_url, path=path)
def create_tarball(path, filename, mode):
""" Create tarball. """
import tarfile
tar = tarfile.open(filename, mode)
cwd = os.getcwd()
os.chdir(path)
try:
for root, dirs, files in os.walk('.'):
if '.svn' in dirs:
dirs.remove('.svn')
if 'bin' in dirs:
dirs.remove('bin')
if 'bin.v2' in dirs:
dirs.remove('bin.v2')
for fil in files:
tar.add(os.path.join(root, fil))
except Exception, err:
print err
tar.close()
os.chdir(cwd)
def create_zip(path, filename, mode):
""" Create zip archive. """
import zipfile
zip = zipfile.ZipFile(filename, mode)
cwd = os.getcwd()
os.chdir(path)
try:
for root, dirs, files in os.walk('.'):
if '.svn' in dirs:
dirs.remove('.svn')
if 'bin' in dirs:
dirs.remove('bin')
if 'bin.v2' in dirs:
dirs.remove('bin.v2')
for fil in files:
zip.write(os.path.join(root, fil))
except Exception, err:
print err
zip.close()
os.chdir(cwd)
def usage():
""" """
print "Usage: python create_packages_from_release.py --major=<major> --minor<minor>"
if __name__ == '__main__':
import sys
import getopt
try:
opts, args = getopt.getopt(sys.argv[1:], "", ["major=", "minor="])
for name, value in opts:
if name == '--major':
major = int(value)
elif name == '--minor':
minor = int(value)
if major is None or minor is None:
usage()
sys.exit(-1)
version = "%d.%d" % (major, minor)
client = pysvn.Client()
path = os.path.join("/", "tmp", "cpp-netlib")
checkout_release(client, version, path)
create_tarball(path, "cpp-netlib.tar.gz", "w:gz")
create_tarball(path, "cpp-netlib.tar.bz2", "w:bz2")
create_zip(path, "cpp-netlib.zip", "w")
except Exception, err:
print err
sys.exit(-1)