From 5309cdbfe1f929641095511b62ba1c47f99c0bd6 Mon Sep 17 00:00:00 2001
From: zooko <zooko@zooko.com>
Date: Wed, 22 Aug 2007 01:04:37 +0530
Subject: [PATCH] zfec: copy the new version of pyutil's version_class.py into
 zfec/util/ and remove the dependency on the separate pyutil library

darcs-hash:9c09937490f98b3f36a22ad6da9cf5bf2b870fd9
---
 zfec/setup.py                   |   2 +-
 zfec/zfec/cmdline_zfec.py       |   3 +-
 zfec/zfec/cmdline_zunfec.py     |   3 +-
 zfec/zfec/util/version.py       | 139 -------------------------------
 zfec/zfec/util/version_class.py | 141 ++++++++++++++++++++++++++++++++
 5 files changed, 144 insertions(+), 144 deletions(-)
 delete mode 100644 zfec/zfec/util/version.py
 create mode 100644 zfec/zfec/util/version_class.py

diff --git a/zfec/setup.py b/zfec/setup.py
index a8aeb61..fb7e5c4 100755
--- a/zfec/setup.py
+++ b/zfec/setup.py
@@ -93,7 +93,7 @@ else:
         raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))
 
 setup(name='zfec',
-      install_requires=['pyutil>=1.0.0',],
+      # install_requires=['pyutil>=1.0.0',], # It doesn't require pyutil yet.
       version=verstr,
       description='a fast erasure code with command-line, C, and Python interfaces',
       long_description='Fast, portable, programmable erasure coding a.k.a. "forward error correction": the generation of redundant blocks of information such that if some blocks are lost then the original data can be recovered from the remaining blocks.',
diff --git a/zfec/zfec/cmdline_zfec.py b/zfec/zfec/cmdline_zfec.py
index 24d98de..b62d826 100755
--- a/zfec/zfec/cmdline_zfec.py
+++ b/zfec/zfec/cmdline_zfec.py
@@ -9,8 +9,7 @@ from util import argparse
 import filefec
 
 from zfec import __version__ as libversion
-from util.version import Version
-__version__ = Version("1.0.0a1-0-STABLE")
+__version__ = libversion
 
 def main():
 
diff --git a/zfec/zfec/cmdline_zunfec.py b/zfec/zfec/cmdline_zunfec.py
index 4b0037d..06ecd47 100755
--- a/zfec/zfec/cmdline_zunfec.py
+++ b/zfec/zfec/cmdline_zunfec.py
@@ -9,8 +9,7 @@ from util import argparse
 import filefec
 
 from zfec import __version__ as libversion
-from util.version import Version
-__version__ = Version("1.0.0a1-0-STABLE")
+__version__ = libversion
 
 def main():
     if '-V' in sys.argv or '--version' in sys.argv:
diff --git a/zfec/zfec/util/version.py b/zfec/zfec/util/version.py
deleted file mode 100644
index 5b67bda..0000000
--- a/zfec/zfec/util/version.py
+++ /dev/null
@@ -1,139 +0,0 @@
-# Copyright (c) 2004-2007 Bryce "Zooko" Wilcox-O'Hearn
-# mailto:zooko@zooko.com
-# http://zooko.com/repos/pyutil
-# Permission is hereby granted, free of charge, to any person obtaining a copy 
-# of this work to deal in this work without restriction (including the rights 
-# to use, modify, distribute, sublicense, and/or sell copies).
-
-"""
-extended version number class
-"""
-
-from distutils import version
-
-# End users see version strings like this:
-
-# "1.0.0"
-#  ^ ^ ^
-#  | | |
-#  | | '- micro version number
-#  | '- minor version number
-#  '- major version number
-
-# The first number is "major version number".  The second number is the "minor
-# version number" -- it gets bumped whenever we make a new release that adds or
-# changes functionality.  The third version is the "micro version number" -- it
-# gets bumped whenever we make a new release that doesn't add or change
-# functionality, but just fixes bugs (including performance issues).
-
-# Early-adopter end users see version strings like this:
-
-# "1.0.0a1"
-#  ^ ^ ^^^
-#  | | |||
-#  | | ||'- release number
-#  | | |'- alpha or beta (or none)
-#  | | '- micro version number
-#  | '- minor version number
-#  '- major version number
-
-# The optional "a" or "b" stands for "alpha release" or "beta release"
-# respectively.  The number after "a" or "b" gets bumped every time we
-# make a new alpha or beta release. This has the same form and the same
-# meaning as version numbers of releases of Python.
-
-# Developers see "full version strings", like this:
-
-# "1.0.0a1-55-UNSTABLE"
-#  ^ ^ ^^^  ^     ^
-#  | | |||  |     |
-#  | | |||  |     '- tags
-#  | | |||  '- nano version number
-#  | | ||'- release number
-#  | | |'- alpha or beta (or none)
-#  | | '- micro version number
-#  | '- minor version number
-#  '- major version number
-
-# The next number is the "nano version number".  It is meaningful only to
-# developers.  It gets bumped whenever a developer changes anything that another
-# developer might care about.
-
-# The last part is the "tags" separated by "_".  Standard tags are
-# "STABLE" and "UNSTABLE".
-
-class Tag(str):
-    def __cmp__(t1, t2):
-        if t1 == t2:
-            return 0
-        if t1 == "UNSTABLE" and t2 == "STABLE":
-            return 1
-        if t1 == "STABLE" and t2 == "UNSTABLE":
-            return -1
-        return -2 # who knows
-
-class Version:
-    def __init__(self, vstring=None):
-        self.major = None
-        self.minor = None
-        self.micro = None
-        self.prereleasetag = None
-        self.nano = None
-        self.tags = None
-        if vstring:
-            self.parse(vstring)
-
-    def parse(self, vstring):
-        i = vstring.find('-')
-        if i:
-            svstring = vstring[:i]
-            estring = vstring[i+1:]
-        else:
-            svstring = vstring
-            estring = None
-
-        self.strictversion = version.StrictVersion(svstring)
-        self.major = self.strictversion.version[0]
-        self.minor = self.strictversion.version[1]
-        self.micro = self.strictversion.version[2]
-        self.prereleasetag = self.strictversion.prerelease
-
-        if estring:
-            try:
-                (self.nano, tags,) = estring.split('-')
-            except:
-                print estring
-                raise
-            self.tags = map(Tag, tags.split('_'))
-            self.tags.sort()
-
-        self.fullstr = '-'.join([str(self.strictversion), str(self.nano), '_'.join(self.tags)])
-          
-    def tags(self):
-        return self.tags
-
-    def user_str(self):
-        return self.strictversion.__str__()
-
-    def full_str(self):
-        return self.fullstr
-
-    def __str__(self):
-        return self.full_str()
-
-    def __repr__(self):
-        return self.__str__()
-
-    def __cmp__ (self, other):
-        if isinstance(other, basestring):
-            other = Version(other)
-
-        res = cmp(self.strictversion, other.strictversion)
-        if res != 0:
-            return res
-
-        res = cmp(self.nano, other.nano)
-        if res != 0:
-            return res
-
-        return cmp(self.tags, other.tags)
diff --git a/zfec/zfec/util/version_class.py b/zfec/zfec/util/version_class.py
new file mode 100644
index 0000000..1e1e2fc
--- /dev/null
+++ b/zfec/zfec/util/version_class.py
@@ -0,0 +1,141 @@
+# Copyright (c) 2004-2007 Bryce "Zooko" Wilcox-O'Hearn
+# mailto:zooko@zooko.com
+# http://zooko.com/repos/pyutil
+# Permission is hereby granted, free of charge, to any person obtaining a copy 
+# of this work to deal in this work without restriction (including the rights 
+# to use, modify, distribute, sublicense, and/or sell copies).
+
+"""
+extended version number class
+"""
+
+# from setuptools, but intended to be included in future version of Python Standard Library (PEP 365)
+try:
+    import pkg_resources
+except ImportError:
+    import distutils.version
+    def cmp_version(v1, v2):
+        return cmp(distutils.version.LooseVersion(str(v1)), distutils.version.LooseVersion(str(v2)))
+else:
+    def cmp_version(v1, v2):
+        return cmp(pkg_resources.parse_version(str(v1)), pkg_resources.parse_version(str(v2)))
+
+# bindann, by Nathan Wilcox (needed only for debugging)
+try:
+    import bindann
+    bindann.install_exception_handler()
+except ImportError:
+    pass
+
+# Python Standard Library
+import re
+
+# End users see version strings like this:
+
+# "1.0.0"
+#  ^ ^ ^
+#  | | |
+#  | | '- micro version number
+#  | '- minor version number
+#  '- major version number
+
+# The first number is "major version number".  The second number is the "minor
+# version number" -- it gets bumped whenever we make a new release that adds or
+# changes functionality.  The third version is the "micro version number" -- it
+# gets bumped whenever we make a new release that doesn't add or change
+# functionality, but just fixes bugs (including performance issues).
+
+# Early-adopter end users see version strings like this:
+
+# "1.0.0a1"
+#  ^ ^ ^^^
+#  | | |||
+#  | | ||'- release number
+#  | | |'- a=alpha, b=beta, c=release candidate, or none
+#  | | '- micro version number
+#  | '- minor version number
+#  '- major version number
+
+# The optional "a" or "b" stands for "alpha release" or "beta release"
+# respectively.  The number after "a" or "b" gets bumped every time we
+# make a new alpha or beta release. This has the same form and the same
+# meaning as version numbers of releases of Python.
+
+# Developers see "full version strings", like this:
+
+# "1.0.0a1-55"
+#  ^ ^ ^^^  ^
+#  | | |||  |
+#  | | |||  '- nano version number
+#  | | ||'- release number
+#  | | |'- a=alpha, b=beta, c=release candidate or none
+#  | | '- micro version number
+#  | '- minor version number
+#  '- major version number
+
+# The presence of the nano version number means that this is a development
+# version.  There are no guarantees about compatibility, etc.  This version is
+# considered to be more recent than the version without this field
+# (e.g. "1.0.0a1").
+
+# The nano version number is meaningful only to developers.  It gets generated
+# automatically from darcs revision control history by "make-version.py".  It
+# is the count of patches that have been applied since the last version number
+# tag was applied.
+
+VERSION_BASE_RE_STR="(\d+)\.(\d+)(\.(\d+))?((a|b|c)(\d+))?"
+VERSION_RE_STR=VERSION_BASE_RE_STR + "(-(\d+))?"
+VERSION_RE=re.compile("^" + VERSION_RE_STR + "$")
+
+class Version(object):
+    def __init__(self, vstring=None):
+        self.major = None
+        self.minor = None
+        self.micro = None
+        self.prereleasetag = None
+        self.prerelease = None
+        self.nano = None
+        self.leftovers = ''
+        if vstring:
+            try:
+                self.parse(vstring)
+            except ValueError, le:
+                le.args = tuple(le.args + ('vstring:', vstring,))
+                raise
+
+    def parse(self, vstring):
+        mo = VERSION_RE.search(vstring)
+        if not mo:
+            raise ValueError, "Not a valid version string for pyutil.version_class.Version(): %r" % (vstring,)
+
+        self.major = int(mo.group(1))
+        self.minor = int(mo.group(2))
+        self.micro = int(mo.group(4))
+        reltag = mo.group(5)
+        if reltag:
+            reltagnum = int(mo.group(6))
+            self.prereleasetag = reltag
+            self.prerelease = reltagnum
+
+        if mo.group(8):
+            self.nano = int(mo.group(9))
+
+        self.fullstr = "%d.%d.%d%s%s" % (self.major, self.minor, self.micro, self.prereleasetag and "%s%d" % (self.prereleasetag, self.prerelease,) or "", self.nano and "-%d" % (self.nano,) or "",)
+
+    def user_str(self):
+        return self.strictversion.__str__()
+
+    def full_str(self):
+        if hasattr(self, 'fullstr'):
+            return self.fullstr
+        else:
+            return 'None'
+
+    def __str__(self):
+        return self.full_str()
+
+    def __repr__(self):
+        return self.__str__()
+
+    def __cmp__ (self, other):
+        return cmp_version(self, other)
-- 
2.45.2