summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@aziz>2010-08-22 17:51:47 +0100
committerRichard Wall <richard@aziz>2010-08-22 17:51:47 +0100
commit1cc9ef400b8ebe09ec15a4acf1b0c51ddab18f15 (patch)
treee9b8f8a3e496cc27b789e9ee3917974896f8f675
parent88b0b1e7143178af532d7983b4e9e8875c591b2e (diff)
Add a command hierarchy and complete the release command
-rwxr-xr-xbin/build (renamed from bin/build-apidocs)4
-rw-r--r--jarmonbuild/commands.py84
2 files changed, 78 insertions, 10 deletions
diff --git a/bin/build-apidocs b/bin/build
index 37a6bd2..54a4b62 100755
--- a/bin/build-apidocs
+++ b/bin/build
@@ -5,6 +5,6 @@ import sys
# Add the current branch to the python path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
-from jarmonbuild.commands import BuildApidocsCommand
+from jarmonbuild.commands import main
-raise SystemExit(BuildApidocsCommand().main())
+raise SystemExit(main())
diff --git a/jarmonbuild/commands.py b/jarmonbuild/commands.py
index addfcd5..7c655ae 100644
--- a/jarmonbuild/commands.py
+++ b/jarmonbuild/commands.py
@@ -9,13 +9,13 @@ import os
import shutil
import sys
+from optparse import OptionParser
from subprocess import check_call
from tempfile import gettempdir
from urllib2 import urlopen
-from zipfile import ZipFile
+from zipfile import ZipFile, ZIP_DEFLATED
-JARMON_VERSION='10.8'
JARMON_PROJECT_TITLE='Jarmon'
JARMON_PROJECT_URL='http://www.launchpad.net/jarmon'
@@ -31,7 +31,8 @@ class BuildError(Exception):
class BuildCommand(object):
- def __init__(self, log=None):
+ def __init__(self, buildversion, log=None):
+ self.buildversion = buildversion
if log is not None:
self.log = log
else:
@@ -43,7 +44,7 @@ class BuildApidocsCommand(BuildCommand):
Download YUI Doc and use it to generate apidocs for jarmon
"""
- def main(self, argv=sys.argv):
+ def main(self, argv):
"""
The main entry point for the build-apidocs command
@@ -115,7 +116,7 @@ class BuildApidocsCommand(BuildCommand):
'--template=%s' % (
os.path.join(
workingbranch_dir, 'jarmonbuild', 'yuidoc_template'),),
- '--version=%s' % (JARMON_VERSION,),
+ '--version=%s' % (self.buildversion,),
'--project=%s' % (JARMON_PROJECT_TITLE,),
'--projecturl=%s' % (JARMON_PROJECT_URL,)
))
@@ -123,9 +124,15 @@ class BuildApidocsCommand(BuildCommand):
shutil.rmtree(yuidoc_dir)
-class BuildSourceArchiveCommand(object):
- def main(self, argv=sys.argv):
- workingbranch_dir = os.path.join(os.path.dirname(__file__), '..')
+class BuildReleaseCommand(BuildCommand):
+ """
+ Export all source files, generate apidocs and create a zip archive for
+ upload to Launchpad.
+ """
+
+ def main(self, argv):
+ workingbranch_dir = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), '..'))
# setup working dir
build_dir = os.path.join(workingbranch_dir, 'build')
@@ -136,4 +143,65 @@ class BuildSourceArchiveCommand(object):
if status != 0:
raise BuildError('bzr export failure. Status: %r' % (status,))
+ # Record the branch version
+ from bzrlib.branch import Branch
+ from bzrlib.version_info_formats.format_python import PythonVersionInfoBuilder
+ v = PythonVersionInfoBuilder(Branch.open(workingbranch_dir))
+ versionfile_path = os.path.join(build_dir, 'jarmonbuild', '_version.py')
+ with open(versionfile_path, 'w') as f:
+ v.generate(f)
+
# Generate apidocs
+ BuildApidocsCommand(buildversion=self.buildversion).main(argv)
+
+ # Generate archive
+ archive_root = 'jarmon-%s' % (self.buildversion,)
+ prefix_len = len(build_dir) + 1
+ z = ZipFile('%s.zip' % (archive_root,), 'w', ZIP_DEFLATED)
+ try:
+ for root, dirs, files in os.walk(build_dir):
+ for file in files:
+ z.write(
+ os.path.join(root, file),
+ os.path.join(archive_root, root[prefix_len:], file)
+ )
+ finally:
+ z.close()
+
+
+# The available sub commands
+build_commands = {
+ 'apidocs': BuildApidocsCommand,
+ 'release': BuildReleaseCommand,
+}
+
+
+def main(argv=sys.argv[1:]):
+ """
+ The root build command which dispatches to various subcommands for eg
+ building apidocs and release zip files.
+ """
+
+ parser = OptionParser(usage='%prog [options] SUBCOMMAND [options]')
+ parser.add_option(
+ '-V', '--build-version', dest='buildversion', default='0',
+ metavar='BUILDVERSION', help='Specify the build version')
+ parser.add_option(
+ '-d', '--debug', action='store_true', default=False, dest='debug',
+ help='Print verbose debug log to stderr')
+
+ parser.disable_interspersed_args()
+
+ options, args = parser.parse_args(argv)
+
+ if len(args) < 1:
+ parser.error('Please specify a sub command. '
+ 'Available commands: %r' % (build_commands.keys()))
+
+ # First argument is the name of a subcommand
+ command_name = args.pop(0)
+ command_factory = build_commands.get(command_name)
+ if not command_factory:
+ parser.error('Unrecognised subcommand: %r' % (command_name,))
+
+ command_factory(buildversion=options.buildversion).main(argv=args)