From bfaf9249b90f35129cfc614b1086d27eb10aa29a Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Sun, 31 May 2009 21:11:43 -0500
Subject: Linhes-config: systemconfig.py and hostype.py

---
 abs/core-testing/LinHES-config/hostype.py      |  6 ++
 abs/core-testing/LinHES-config/systemconfig.py | 88 ++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 abs/core-testing/LinHES-config/hostype.py
 create mode 100755 abs/core-testing/LinHES-config/systemconfig.py

diff --git a/abs/core-testing/LinHES-config/hostype.py b/abs/core-testing/LinHES-config/hostype.py
new file mode 100644
index 0000000..928c038
--- /dev/null
+++ b/abs/core-testing/LinHES-config/hostype.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+import logging
+
+def hostypeprint(systemconfig):
+    print "hostran"
+    print systemconfig["Hostipeth0"]
\ No newline at end of file
diff --git a/abs/core-testing/LinHES-config/systemconfig.py b/abs/core-testing/LinHES-config/systemconfig.py
new file mode 100755
index 0000000..88961f6
--- /dev/null
+++ b/abs/core-testing/LinHES-config/systemconfig.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import sys,  os,  commands,  glob,  time
+import getopt,  re,  MySQLdb
+import logging
+import hostype
+
+#____________________________________________setup the logging______________________________________________________
+LOG_FILENAME = '/tmp/systemconfig.log'
+DEBUGLOG = '/tmp/systemconfig_debug.log'
+logging.basicConfig(level=logging.DEBUG,
+                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
+                    datefmt='%m-%d %H:%M',
+                    filename=DEBUGLOG,
+                    filemode='a')
+# define a Handler which writes INFO messages or higher to the sys.stderr
+console = logging.StreamHandler()
+console.setLevel(logging.DEBUG)
+# set a format which is simpler for console use
+#formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
+formatter = logging.Formatter("%(message)s")
+# tell the handler to use this format
+console.setFormatter(formatter)
+# add the handler to the root logger
+logging.getLogger('').addHandler(console)
+
+#infoformatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+infoformatter = logging.Formatter("%(message)s")
+infofile = logging.FileHandler(LOG_FILENAME, 'w')
+infofile.setFormatter(infoformatter)
+infofile.setLevel(logging.INFO)
+logging.getLogger('').addHandler(infofile)
+
+
+def usage():
+    logging.info("tell people how to use this")
+
+def main(argv):
+    global cmdmodule
+    try:
+        opts,  args = getopt.getopt(argv,  'c:hm:',  ["help","modules" ] )
+    except getopt.GetoptError, why:
+        print why
+        usage()
+        print "exception haappen"
+        sys.exit(2)
+    cmdmodule = {"op": 'null'}
+    for opt,  arg in opts:
+        if opt in ("-h",  "--help"):
+            usage()
+            sys.exit(0)
+        elif opt in ("-m"):
+            for i in arg.split(","):
+                cmdmodule[i]=True
+
+    if cmdmodule["hostype"]:
+        hostype.hostypeprint(systemconfig)
+
+
+if __name__ == "__main__":
+    config_file = "mv_config"
+    data_config = __import__(config_file,  globals(),  locals(),  [])
+    #Read in systemconfig
+    global systemconfig
+    systemconfig = {}
+    file_name = "/etc/systemconfig"
+    try:
+        config_file = open(file_name)
+    except:
+        logging.critical("%s could not be opened", file_name)
+        sys.exit(1)
+
+    for line in config_file:
+        line = line.strip()
+        if line and line[0] is not "#" and line[-1] is not "=":
+            var, val = line.rsplit("=", 1)
+            val = val.strip('"')
+            systemconfig[var.strip()] = val.strip()
+
+    logging.debug("______START OF DEBUG______")
+    main(sys.argv[1:])
+    logging.debug("______cmd line options______")
+    for i in cmdmodule.items():
+        logging.debug (i)
+    logging.debug("______systemconfig______")
+    for i in systemconfig.items():
+        logging.debug(i)
+    pass
-- 
cgit v0.12

