* handle more than 2 dashes gracefully

* split returns strings. Make release and build also VersionItems.
This commit is contained in:
Faik Uygur
2006-10-14 21:27:57 +00:00
parent 84f4e1d247
commit f39c1e4dcc
+14 -6
View File
@@ -14,9 +14,12 @@
import re import re
import string import string
import exceptions
import pisi
import pisi.util as util import pisi.util as util
maxdashes = 2
# Basic rule is: # Basic rule is:
# p > (no suffix) > m > rc > pre > beta > alpha # p > (no suffix) > m > rc > pre > beta > alpha
@@ -37,6 +40,9 @@ def has_keyword(versionitem):
return False return False
class VersionException(pisi.Exception):
def __init__(self, str):
pisi.Exception.__init__(self, str)
class VersionItem: class VersionItem:
_keyword = "NOKEY" _keyword = "NOKEY"
@@ -129,12 +135,12 @@ class Version:
def __init__(self, verstring): def __init__(self, verstring):
# PiSi version policy does not allow "-" in version strings. # PiSi version policy does not allow "-" in version strings.
# They are special and used for build and release no separation. # They are special and used for build and release no separation.
if verstring.count("-") == 0: if verstring.count("-") > maxdashes:
(version, self.release, self.build) = (verstring, 0, 0) raise VersionException("%s is not a valid PiSi version format" % verstring)
elif verstring.count("-") == 1:
(version, self.release), self.build = (verstring.split("-"), 0) verchunks = verstring.split("-")
else: verchunks.extend("0" * (maxdashes - verstring.count("-")))
(version, self.release, self.build) = verstring.split("-") (version, release, build) = verchunks
self.comps = [] self.comps = []
for i in util.multisplit(version,'._'): for i in util.multisplit(version,'._'):
@@ -151,6 +157,8 @@ class Version:
self.comps.append(VersionItem(i)) self.comps.append(VersionItem(i))
self.verstring = verstring self.verstring = verstring
self.release = VersionItem(release)
self.build = VersionItem(build)
def string(self): def string(self):
return self.verstring return self.verstring