summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Albert <albertj@us.ibm.com>2015-01-26 17:08:07 -0600
committerJason Albert <albertj@us.ibm.com>2015-01-26 17:08:07 -0600
commit6a72e60513e4694c98f87152cb25a088e757f348 (patch)
tree52048dab402b886136c8efe8616d9e6dffc987a6
downloadvpdtools-6a72e60513e4694c98f87152cb25a088e757f348.tar.gz
vpdtools-6a72e60513e4694c98f87152cb25a088e757f348.zip
Initial add of scripts
-rwxr-xr-xcreateVpd.py44
-rw-r--r--pymod/cmdline.py81
-rw-r--r--pymod/cmdline.pycbin0 -> 1578 bytes
3 files changed, 125 insertions, 0 deletions
diff --git a/createVpd.py b/createVpd.py
new file mode 100755
index 0000000..e7ce711
--- /dev/null
+++ b/createVpd.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# Created 01/26/15 by Jason Albert
+# Program to create VPD images from input template files
+
+############################################################
+# Imports - Imports - Imports - Imports - Imports - Imports
+############################################################
+import sys
+sys.path.insert(0,"pymod");
+import cmdline
+import os
+import xml.etree.ElementTree as ET
+
+############################################################
+# Function - Functions - Functions - Functions - Functions
+############################################################
+def help():
+ print("createVpd.py")
+ print("Required Args")
+ print("Optional Args")
+ print("-h|--help This help text")
+
+############################################################
+# Main - Main - Main - Main - Main - Main - Main - Main
+############################################################
+rc = 0
+# Get the path the script is being called from
+cwd = os.path.dirname(os.path.abspath(__file__))
+
+################################################
+# Command line options
+clError = 0
+
+# Help text
+if (cmdline.parseOption("-h","--help")):
+ help()
+ exit(0)
+
+tree = ET.parse('tvpd/vini.tvpd')
+root = tree.getroot()
+root.tag
+root.attrib
+for child in root:
+ print child.tag, child.attrib
diff --git a/pymod/cmdline.py b/pymod/cmdline.py
new file mode 100644
index 0000000..f464513
--- /dev/null
+++ b/pymod/cmdline.py
@@ -0,0 +1,81 @@
+# Jason Albert - created 08/21/2014
+# Python module to define command cmdline parsing functions
+
+############################################################
+# Imports - Imports - Imports - Imports - Imports - Imports
+############################################################
+import sys
+import re
+
+############################################################
+# Function - Functions - Functions - Functions - Functions
+############################################################
+def parseOption(option1, option2=None, remove=True):
+ """
+ Parses the command line for options without args
+ Setting remove to False means the found option will not be removed from argv
+ """
+
+ # Create a list of options we loop over
+ options = list()
+ options.append(option1)
+ if (option2 != None):
+ options.append(option2)
+
+ for option in options:
+ # We are going to loop through looking for the option passed in
+ # When found, it will be removed from argv
+ # Return will be 1 to indicate it's found
+ # Since we return once we get a match, we don't have to worry about the fact that we are modifying the list in flight
+ for i in range(0, len(sys.argv)):
+ if (sys.argv[i] == option):
+ if remove:
+ sys.argv.pop(i) # Remove from the args
+ return 1
+
+ # Found nothing
+ return 0
+
+def parseOptionWithArg(option1, option2=None, remove=True):
+ """
+ Parses the command line for options with args
+ They can be in the format of --su2, --su 2 or --su=2
+ Setting remove to False means the found option will not be removed from argv
+ """
+
+ # The value to return
+ optValue = None
+
+ # Create a list of options we loop over
+ options = list()
+ options.append(option1)
+ if (option2 != None):
+ options.append(option2)
+
+ for option in options:
+ # We are going to loop through looking for the option passed in
+ # When found, it and it's value will be removed from argv
+ # Return wil be 1 to indicate it's found, along with the value
+ # Since we return once we get a match, we don't have to worry about the fact that we are modifying the list in flight
+ for i in range(0, len(sys.argv)):
+ if (re.match('^' + option, sys.argv[i])):
+ # We need to handle --option xx, --option=xx, --optionxx
+ # An option with a space
+ if (sys.argv[i] == option):
+ optValue = sys.argv[i+1]
+ if remove:
+ sys.argv.pop(i) # Remove the option from the args
+ sys.argv.pop(i) # Remove the value from the args. It's not i+1 because the pop shrunk the list
+ return optValue
+
+ # We'll strip the option off the front, and handle an = if it is there at the front
+ else:
+ optValue = sys.argv[i]
+ optValue = re.sub('^' + option, '', optValue) # The option
+ optValue = re.sub('^=', '', optValue) # An = if it's there
+ if remove:
+ sys.argv.pop(i) # Remove from the args
+ return optValue
+
+ # Found nothing
+ return None
diff --git a/pymod/cmdline.pyc b/pymod/cmdline.pyc
new file mode 100644
index 0000000..7f5c336
--- /dev/null
+++ b/pymod/cmdline.pyc
Binary files differ
OpenPOWER on IntegriCloud