[Spread-users] [PATCH] Packaging of CVS source as tarball

Daniel Rall dlr at finemaltcoding.com
Mon Oct 28 01:29:40 EST 2002


Jonathan Stanton <jonathan at cnds.jhu.edu> writes:

> I will admit I don't have a script. Since it only involves a few
> commands for me I wrote a "howto build a spread release" text file but I
> didn't automate the running of those commands. I've attached that file
> to this email as it might help some. 
> 
> Since I don't need to directly turn a CVS checkout into a release (that
> is more work then running cvs export as I have to get rid of all of the
> CVS directories then) I havn't had to do what it sounds like you need to
> do.
> 
> How to make a spread distribution:
> ----------------------------------
> In the ~/spreaddist directory run:
> 
> cvs -d :ext:cvs.spread.org:/storage/cvsroot export -r REL3.XX.X -d spread_src-3.XX.X spread/daemon
> 
> That will create the basic source directory.
> 
> cd spread_src-3.XX.X
> 
> cvs -d :ext:cvs.spread.org:/storage/cvsroot export -r REL3.XX.X -d java spread/javaapps
> cvs -d :ext:cvs.spread.org:/storage/cvsroot export -r REL3.XX.X -d java/spread spread/javalib
> cvs -d :ext:cvs.spread.org:/storage/cvsroot export -r REL3.XX.X -d perl spread/perl
> 
> cd java
> run perl script to fixup build.xml file:
> 
> perl -pi -e 's,(property name="src.java.dir" value=")../javalib",$1spread,' build.xml
> 
> Write release_announcement.txt file for toplevel source directory.

Jonathan, here's a lightly unit tested Python script implementing the
export strategy you outlined for creating a new source tarball.  I'm
not sure what the best spot in the CVS repo is for it -- I have it
living in the daemon/buildtools/ dir in my working copy.  Let me know
if you'd like anything in the script changed, and once you're happy
with it, please add it to CVS so that it's available for general use.

The script is run as follows:

dlr at despot:buildtools ./mkpkg.py --version=3.17.0 --dir=/tmp
[output scrolls by here]

- Dan


--- /dev/null	Thu Apr 11 07:25:15 2002
+++ mkpkg.py	Sun Oct 27 22:21:30 2002
@@ -0,0 +1,147 @@
+#!/usr/bin/env python2.2
+# mkpkg.py: -*- Python -*- script to turn a Spread CVS checkout into a
+# source tarball releas.
+
+__author__ = 'Daniel Rall <dlr at finemaltcoding.com>'
+
+import os
+import sys
+import getopt
+import re
+
+
+_CVS_ROOT = ':ext:cvs.spread.org:/storage/cvsroot'
+_verbose = None
+
+def main():
+    """Script entry point."""
+    if len(sys.argv) <= 2:
+        usage(1)
+
+    opts, args = getopt.getopt(sys.argv[1:], 'v:t:d:h',
+                               ['version=', 'tagprefix=', 'dir=', 'help',
+                                'verbose'])
+    if args:
+        usage(1)
+
+    version = None
+    tagPrefix = None
+    toDir = None
+
+    for opt, value in opts:
+        if (opt in ('-v', '--version')):
+            version = value
+        elif (opt in ('-t', '--tagprefix')):
+            tagPrefix = value
+        elif (opt in ('-d', '--dir')):
+            toDir = value
+        elif (opt in ('-h', '--help')):
+            usage(0)
+        elif (opt == '--verbose'):
+            if not value:
+                value = 1
+            global _verbose
+            _verbose = value
+        else:
+            usage(1 ,'Unknown option: ' + opt)
+
+    if not version:
+        usage(1, "Version must be specified")
+
+    if _verbose:
+        print "Creating package for version '%s'" % version
+        if toDir:
+            print "Using target directory '%s'" % toDir
+
+    assembleSourceLayout(version, tagPrefix, toDir)
+
+    print "You should now write a release_announcement.txt file in the " \
+          "top level source directory"
+
+
+def assembleSourceLayout(version, tagPrefix=None, toDir=None):
+    """Creates a top-level source directory, then populates it with
+    the Java and Perl sources."""
+    if toDir:
+        savedDir = os.getcwd()
+        if not os.path.isdir(toDir):
+            os.makedirs(toDir)
+        os.chdir(toDir)
+    srcDir = 'spread_src-%s' % version
+    exitCode = export(_CVS_ROOT, 'spread/daemon', version, tagPrefix, srcDir)
+    exitOnError(exitCode, 'CVS export failed')
+    os.chdir(srcDir)
+    for exports in (('spread/perl', 'perl'),
+                    ('spread/javaapps', 'java')):
+        exitCode = export(_CVS_ROOT, exports[0], version, tagPrefix,
+                          exports[1])
+        exitOnError(exitCode, 'CVS export failed')
+    os.chdir('java')
+    exitCode = export(_CVS_ROOT, 'spread/javalib', version, tagPrefix,
+                      'spread')
+    exitOnError(exitCode, 'CVS export failed')
+
+    # Fix path in Ant build file for sourceball layout.
+    antFile = open('build.xml')
+    text = antFile.read()
+    antFile.close()
+    text = re.sub('(property name="src.java.dir" value=)"../javalib"',
+                  r'\1"spread"', text)
+    text = re.sub('(property name="version" value=)"[^"]+"',
+                  r'\1"%s"' % version, text)
+    antFile = open('build.xml', 'w')
+    antFile.write(text)
+
+    if savedDir:
+        os.chdir(savedDir)
+
+
+def exitOnError(exitCode, msg):
+    """Prints an error message and exits if exitCode is non-zero."""
+    if exitCode != 0:
+        exitCode = os.WEXITSTATUS(exitCode)
+        print >> sys.stderr, "%s:  Exit code: %d" % (msg, exitCode)
+        sys.exit(exitCode)
+
+
+def export(cvsRoot, cvsRepo, version, tagPrefix=None, toDir=None):
+    """Exports the source code from the CVS repository, returning exit
+    from cvs binary code."""
+    version = formatVersionAsCVSTag(version, tagPrefix)
+    if toDir:
+        exportCmd = 'cvs -d %s export -r %s -d %s %s' % \
+                    (cvsRoot, version, toDir, cvsRepo)
+    else:
+        exportCmd = 'cvs -d %s export -r %s %s' % (cvsRoot, version, cvsRepo)
+    if _verbose:
+        print "Executing CVS command:", exportCmd
+    return os.system(exportCmd)
+
+
+def formatVersionAsCVSTag(version, tagPrefix=None):
+    """Formats the dotted version number as a Spread CVS release tag.
+    If tagPrefix is not specified, assumes that the release type is a
+    final."""
+    if not tagPrefix:
+        tagPrefix = 'REL_'
+    elif tagPrefix[-1:] != '_':
+        tagPrefix += '_'
+    return tagPrefix + re.sub('\.', '_', version)
+
+
+def usage(exitCode, msg=None):
+    """Prints usage information, then exits."""
+    if exitCode == 0:
+        stream = sys.stdout
+    else:
+        stream = sys.stderr
+    fmt = "usage: %s --version=x.y.z [--tagprefix=RC5] [--dir=/to/dir] " \
+          "[--verbose] | --help"
+    print >> stream, fmt % os.path.basename(sys.argv[0])
+    if msg:
+        print >> stream, msg
+    sys.exit(exitCode)
+
+
+if __name__ == '__main__':
+    main()


-- 

Daniel Rall <dlr at finemaltcoding.com>




More information about the Spread-users mailing list