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-05 11:05:15 -0400
commit09cbf47c9a42a8ce588e9a6bfb5c45b228fcbaca (patch)
tree5ddf479c170045d2f0764454564e3ac21f946fe8
parent4ff124d7c9179c5286cf41256883a94ba2e07f7e (diff)
downloadbcfg2-09cbf47c9a42a8ce588e9a6bfb5c45b228fcbaca.tar.gz
bcfg2-09cbf47c9a42a8ce588e9a6bfb5c45b228fcbaca.tar.bz2
bcfg2-09cbf47c9a42a8ce588e9a6bfb5c45b228fcbaca.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()
+