OK, Gerry, I have addressed your concerns.

1) Note that the release number is still squelched in the case of RPMs 
compiled from SVN checkouts of distutils packages.  This is so that alpha, 
beta or release candidate packages can upgrade SVN checkouts without extra 
intervention from the packager.  Alpha, beta and rc packages do obey the 
release variable just fine.  The whole intention here is to put a sensible 
release variable and a sensible version variable when no release variable was 
specified.
2) I have used a relsep variable that you can tweak to use a dot or an 
elephant if your package policy wants that (note that the Mandrake policy says 
nothing about that).
3) If anything non-numeric is specified in the release, then you as a packager 
are indicating that you do not want this automatic behavior and the 
modifications are automatically skipped.  Note that the whole point of the 
patch is to AVOID this extra work of specifying the release for prerelease 
packages.
4) The cases you spoke about are addressed.

Attached is the patch.  Here is a map table with the default release (which 
happens to be "1":

-----------------------
[rud...@tobey ~]$ for a in `cat versions` ; do python bdist_rpm.py rewrite $a 
1 ; done
1.0-1           1.0-1
1.1-1           1.1-1
1.1a-1          1.1-0.1.a
1.1a2-1         1.1-0.1.a2
1.1b1-1         1.1-0.1.b1
1.1dev-1                1.1-0.0.dev
1.1svn-1                1.1-0.0.svn
1.1dev-r56554-1         1.1-0.0.56554dev
1.1svn-r400-1           1.1-0.0.400svn
1.1svn-r401-1           1.1-0.0.401svn
1.2svn-r34-1            1.2-0.0.34svn
5.5rc2-1                5.5-0.1.rc2
0.9-1           0.9-1
0.9.8-1         0.9.8-1
20080706-1              20080706-1
A2005-1         A2005-1
ABCDEF15-1              ABCDEF15-1
abc45-1         abc45-1
0.9alpha23-1            0.9-0.1.alpha23
A2-1            A2-1
--------------------

Now here is a map table with a release with a non-integer release:

----------------
[rud...@tobey ~]$ for a in `cat versions` ; do python bdist_rpm.py rewrite $a 
0_1 ; done
1.0-0_1         1.0-0_1
1.1-0_1         1.1-0_1
1.1a-0_1                1.1a-0_1
1.1a2-0_1               1.1a2-0_1
1.1b1-0_1               1.1b1-0_1
1.1dev-0_1              1.1dev-0_1
1.1svn-0_1              1.1svn-0_1
1.1dev-r56554-0_1               1.1dev_r56554-0_1
1.1svn-r400-0_1         1.1svn_r400-0_1
1.1svn-r401-0_1         1.1svn_r401-0_1
1.2svn-r34-0_1          1.2svn_r34-0_1
5.5rc2-0_1              5.5rc2-0_1
0.9-0_1         0.9-0_1
0.9.8-0_1               0.9.8-0_1
20080706-0_1            20080706-0_1
A2005-0_1               A2005-0_1
ABCDEF15-0_1            ABCDEF15-0_1
abc45-0_1               abc45-0_1
0.9alpha23-0_1          0.9alpha23-0_1
A2-0_1          A2-0_1
------------------

I hope the next note you have about this patch is as constructive as the last 
one.  The intention here is to solve a problem, not to bikeshed.
-- 

        Manuel Amador (Rudd-O) <rud...@rudd-o.com>
        Rudd-O.com - http://rudd-o.com/
        GPG key ID 0xC8D28B92 at http://wwwkeys.pgp.net/

If puns were deli meat, this would be the wurst.

--- bdist_rpm.py.orig	2009-03-12 23:30:29.000000000 -0500
+++ bdist_rpm.py	2009-03-13 00:40:52.000000000 -0500
@@ -16,6 +16,44 @@
 from distutils.file_util import write_file
 from distutils.errors import *
 from distutils import log
+import re
+
+
+# helper function to rewrite the version number into correct RPM lexicographical order
+def rewrite_lexicographically(version, release):
+
+        version = version.replace('-','_')
+        release = release.replace('-','_')
+        relsep = "."
+
+        try: int(release)
+        except ValueError: return (version, release)
+
+        expressions = [
+           '^([0-9\.]+)(dev|svn)_r(.*)$',
+           '^([0-9\.]+)(dev|svn)($)',
+           '^([0-9\.]+)(alpha|beta|gamma)(.*)$',
+           '^([0-9\.]+)([abc])(.*)$',
+           '^([0-9\.]+)(rc)(.*)$',
+       ]
+
+        matches = [ re.match(m,version) for m in expressions ]
+        matches = [ m for m in matches if m ]
+        if matches:
+            v,d,p = matches[0].groups()
+            if d == "dev" or d == "svn":
+                d,p = p,d
+                release = "0"
+            version = "%s" % v
+            release = "0%s%s%s%s%s" %(relsep, release, relsep, d, p)
+
+        return (version , release)
+
+# this is so you can test me by running python bdist_rpm.py rewrite <version> <release>
+if __name__ == "__main__" and "rewrite" in sys.argv:
+        v,r=rewrite_lexicographically(*sys.argv[2:4])
+        print "%s-%s		%s-%s"%(sys.argv[2],sys.argv[3],v,r)
+
 
 class bdist_rpm (Command):
 
@@ -391,6 +429,13 @@
             'Summary: ' + self.distribution.get_description(),
             ]
 
+        version = self.distribution.get_version()
+        release = self.release
+
+        version, release = rewrite_lexicographically(version,release)
+        spec_file.insert(3,version)
+        spec_file.insert(4,release)
+
         # put locale summaries into spec file
         # XXX not supported for now (hard to put a dictionary
         # in a config file -- arg!)
@@ -411,8 +456,10 @@
         else:
             spec_file.append('Source0: %{name}-%{version}.tar.gz')
 
+        license = self.distribution.get_license()
+        if len(license.splitlines()) > 1: license = "Other"
         spec_file.extend([
-            'License: ' + self.distribution.get_license(),
+            'License: ' + license,
             'Group: ' + self.group,
             'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
             'Prefix: %{_prefix}', ])

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to