summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaul Cuza <raulcuza@gmail.com>2011-07-05 11:05:15 -0400
committerRaul Cuza <raulcuza@gmail.com>2011-07-06 13:37:59 -0400
commit146a7a633bc3a36de21f589af0eec10755b0cae5 (patch)
tree6db1dae63c685db21afdb7333681f11942f76220
parent5aa97a1b01f0a4508d4e5adbe0db5022029bead8 (diff)
downloadbcfg2-146a7a633bc3a36de21f589af0eec10755b0cae5.tar.gz
bcfg2-146a7a633bc3a36de21f589af0eec10755b0cae5.tar.bz2
bcfg2-146a7a633bc3a36de21f589af0eec10755b0cae5.zip
Add Environment.py file for building classes to gather env data.
Includes Pyversion() class which simplifies getting the Python version that Bcfg2 is running under. It is mostly useful for Python 2 and under, since Python 3 has the handy sys.version_info.{major,minor,...} object.
-rw-r--r--src/lib/Environment.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/Environment.py b/src/lib/Environment.py
new file mode 100644
index 000000000..782407ee2
--- /dev/null
+++ b/src/lib/Environment.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+Environment.py
+
+Classes for easy access to python environment information (e.g. python version).
+"""
+
+import sys
+import os
+
+class Pyversion():
+
+ def __init__(self):
+ # This is only helpful for Python 2 and older. Python 3 has sys.version_info.major.
+ [self.major, self.minor, self.micro, self.releaselevel, self.serial] = sys.version_info
+ self.version = sys.version
+ self.hex = sys.hexversion
+
+
+def main():
+ # test class Pyversion
+ pyversion = Pyversion()
+ print "%s : %s" % ("major", pyversion.major)
+ print "%s : %s" % ("minor", pyversion.minor)
+ print "%s : %s" % ("micro", pyversion.micro)
+ print "%s : %s" % ("releaselevel", pyversion.releaselevel)
+ print "%s : %s" % ("serial", pyversion.serial)
+ print "%s : %s" % ("version", pyversion.version)
+ print "%s : %s" % ("hex", pyversion.hex)
+
+ pass
+
+
+if __name__ == '__main__':
+ main()
+