summaryrefslogtreecommitdiffstats
path: root/gluster/swift/common/middleware/gswauth/swauth/swift_version.py
diff options
context:
space:
mode:
authorLuis Pabon <lpabon@redhat.com>2013-10-10 16:53:28 -0400
committerLuis Pabon <lpabon@redhat.com>2013-10-13 19:36:20 -0700
commitac1ac5bd2171e61ba4332dcae33d8a433cef7a4f (patch)
tree9d836201435c83cf59a659124f004a03f488c1f5 /gluster/swift/common/middleware/gswauth/swauth/swift_version.py
parent46cd43fdf401b16f9e1b588e5fc8d2c5dd599b37 (diff)
GSWauth authentication to be based on SWauth
We are planning on creating a GlusterFS aware authentication system for gluster-swift based on SWauth. We forked from SWauth commit 41d36ebe160aa3346f6f45197fff0c80f38fde58 Change-Id: Ia28730d21e04fc8d9ce0cb317fc04d0d97583fca Signed-off-by: Luis Pabon <lpabon@redhat.com> Reviewed-on: http://review.gluster.org/6069
Diffstat (limited to 'gluster/swift/common/middleware/gswauth/swauth/swift_version.py')
-rw-r--r--gluster/swift/common/middleware/gswauth/swauth/swift_version.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/gluster/swift/common/middleware/gswauth/swauth/swift_version.py b/gluster/swift/common/middleware/gswauth/swauth/swift_version.py
new file mode 100644
index 0000000..cabe284
--- /dev/null
+++ b/gluster/swift/common/middleware/gswauth/swauth/swift_version.py
@@ -0,0 +1,71 @@
+import swift
+
+
+MAJOR = None
+MINOR = None
+REVISION = None
+FINAL = None
+
+
+def parse(value):
+ parts = value.split('.')
+ if parts[-1].endswith('-dev'):
+ final = False
+ parts[-1] = parts[-1][:-4]
+ else:
+ final = True
+ major = int(parts.pop(0))
+ minor = int(parts.pop(0))
+ if parts:
+ revision = int(parts.pop(0))
+ else:
+ revision = 0
+ return major, minor, revision, final
+
+
+def newer_than(value):
+ global MAJOR, MINOR, REVISION, FINAL
+ major, minor, revision, final = parse(value)
+ if MAJOR is None:
+ MAJOR, MINOR, REVISION, FINAL = parse(swift.__version__)
+ if MAJOR < major:
+ return False
+ elif MAJOR == major:
+ if MINOR < minor:
+ return False
+ elif MINOR == minor:
+ if REVISION < revision:
+ return False
+ elif REVISION == revision:
+ if not FINAL or final:
+ return False
+ return True
+
+
+def run_tests():
+ global MAJOR, MINOR, REVISION, FINAL
+ MAJOR, MINOR, REVISION, FINAL = parse('1.3')
+ assert(newer_than('1.2'))
+ assert(newer_than('1.2.9'))
+ assert(newer_than('1.3-dev'))
+ assert(newer_than('1.3.0-dev'))
+ assert(not newer_than('1.3'))
+ assert(not newer_than('1.3.0'))
+ assert(not newer_than('1.3.1-dev'))
+ assert(not newer_than('1.3.1'))
+ assert(not newer_than('1.4'))
+ assert(not newer_than('2.0'))
+ MAJOR, MINOR, REVISION, FINAL = parse('1.7.7-dev')
+ assert(newer_than('1.6'))
+ assert(newer_than('1.7'))
+ assert(newer_than('1.7.6-dev'))
+ assert(newer_than('1.7.6'))
+ assert(not newer_than('1.7.7'))
+ assert(not newer_than('1.7.8-dev'))
+ assert(not newer_than('1.7.8'))
+ assert(not newer_than('1.8.0'))
+ assert(not newer_than('2.0'))
+
+
+if __name__ == '__main__':
+ run_tests()