Skip to content

Instantly share code, notes, and snippets.

@AKSarav
Created December 6, 2017 22:22
Show Gist options
  • Save AKSarav/dedccdeb3615d4efb4a7ad674dc15e99 to your computer and use it in GitHub Desktop.
Save AKSarav/dedccdeb3615d4efb4a7ad674dc15e99 to your computer and use it in GitHub Desktop.
Weblogic Application Deployment Parser - With No Excel Report
#!/usr/bin/python
import os
import sys
import subprocess
from sys import argv
from os.path import exists
import re
from collections import deque
from itertools import chain
FLAG = "OFF"
mylist = []
repo = {}
parents = []
servername = ""
row =0
col =0
founddomain = "false"
# Testing the Startup Arguments for the script
if not (len(argv) < 3 ):
print "Argument is must"
sys.exit()
filename = argv[1].rstrip();
if exists(filename):
#with open(filename,"r+") as fo
fo = open(filename,"r+")
os.system("clear")
print "-"* 0
print "..Reading the file..",filename
print "-"*70
print "\t\t WEBLOGIC APP-DEPLOYMENT PARSER \t\t"
print "\t\t DESIGNED BY - WWW.MWINVENTORY.IN \t\t"
print "-"*70
print ""
filecontent = fo.readlines()
for str in filecontent:
#print " Processing Line: \n",str
matchdomainname = re.search(r'(^\<)(name)(\>)(.+)(\<\/)(name)(\>)', str.strip())
matchdomainver = re.search(r'(^\<)(domain-version)(\>)(.+)(\<\/)(domain-version)(\>)', str.strip())
if matchdomainname and founddomain == "false":
print "DOMAIN NAME:",matchdomainname.group(4),"\t\t"
founddomain = "true"
if matchdomainver:
print "DOMAIN VERSION:",matchdomainver.group(4),"\t\t"
print "-"*70
match1 = re.search(r'\<app-deployment\>', str)
if match1:
#print str
FLAG = "ON"
match2 = re.search(r'\<\/app-deployment\>', str)
if match2:
#print str
FLAG = "OFF"
#print str.strip()
mylist.append(str.strip())
if (FLAG == "ON"):
#print str.strip()
mylist.append(str.strip())
fo.close()
else:
print "File is not present"
sys.exit()
elements={}
class parent(object):
def addelement(self,key,value):
self.__dict__[key]=value
servers=[]
class server(object):
def addelement(self,key,value):
self.__dict__[key]=value
'''
Below steps are for creating Dynamic variables and dictionary
element[server]=parent() # New object will be created under the list
element[server].addelement(key,value) would add new element to the dictionary like JSON
'''
mode="parent"
#print "------------------------------------------------------------"
try:
for line in mylist:
if re.search(r'(^\<)(.+)(\>)(.+)(\<\/)(.+)(\>)',line):
mode="child"
match=re.search(r'(^\<)(.+)(\>)(.+)(\<\/)(.+)(\>)',line)
if match:
if not ( "/" in root ):
print root+"_"+match.group(2),":", match.group(4)
elements[root].addelement(match.group(2),match.group(4)) #adding new element to the dict
key=root+"_"+match.group(2)
repo[key]=match.group(4)
else:
print "DID IT EVER COME HERE"
root = root.split("/")[1].strip()
print root+"_"+match.group(2),":", match.group(4)
elements[root].addelement(match.group(2),match.group(4)) #adding new element to the dict
key=root+"_"+match.group(2)
repo[key]=match.group(4)
elif re.search(r'(^\<)(.+)(\>)(\<\/)(.+)(\>)',line):
mode="child"
match=re.search(r'(^\<)(.+)(\>)(\<\/)(.+)(\>)',line)
if match:
if not ( "/" in root ):
print root+"_"+match.group(2),": NO VALUE"
elements[root].addelement(match.group(2),"NO VALUE")
key=root+"_"+match.group(2)
repo[key]="NO VALUE"
else:
root = root.split("/")[1].strip()
print root+"_"+match.group(2),": NO VALUE"
elements[root].addelement(match.group(2),"NO VALUE")
key=root+"_"+match.group(2)
repo[key]="NO VALUE"
elif re.search(r'(^\<|^\<\/)(.+)(\>$)',line):
mode="parent"
match=re.search(r'(^\<)(.+)(\>)',line)
if match:
if not "/" in match.group(2) :
mode = "child"
root=match.group(2)
parents.append(root)
#print "ADDED NEW ELEMENT", parents
else:
root=match.group(2)
mode = "child"
tmpstr=match.group(2).split("/")[1]
#print tmpstr;
if tmpstr in parents:
parents.remove(tmpstr)
#print "REMOVED ELEMENT", parents
#print parents
if len(parents) > 0:
root=parents[len(parents)-1]
if root not in elements.keys():
#print "Adding new element object", root
elements[root] = parent()
if root == "/app-deployment":
print "----------------------------------------------------------"
if "/app-deployment" not in line:
row = row+1
col = 0
print "-"*70
except IndexError:
print "- "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment