A PHP Error was encountered
Severity: 8192
Message: Function create_function() is deprecated
Filename: geshi/geshi.php
Line Number: 4698
Backtrace:
File: /home3/analyti4/public_html/nerdingout/pastetool/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler
File: /home3/analyti4/public_html/nerdingout/pastetool/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string
File: /home3/analyti4/public_html/nerdingout/pastetool/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list
File: /home3/analyti4/public_html/nerdingout/pastetool/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group
File: /home3/analyti4/public_html/nerdingout/pastetool/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache
File: /home3/analyti4/public_html/nerdingout/pastetool/application/libraries/Process.php
Line: 45
Function: parse_code
File: /home3/analyti4/public_html/nerdingout/pastetool/application/models/Pastes.php
Line: 517
Function: syntax
File: /home3/analyti4/public_html/nerdingout/pastetool/application/controllers/Main.php
Line: 624
Function: getPaste
File: /home3/analyti4/public_html/nerdingout/pastetool/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/analyti4/public_html/nerdingout/pastetool/system/core/Exceptions.php:271)
Filename: view/download.php
Line Number: 2
Backtrace:
File: /home3/analyti4/public_html/nerdingout/pastetool/themes/default/views/view/download.php
Line: 2
Function: header
File: /home3/analyti4/public_html/nerdingout/pastetool/application/core/MY_Loader.php
Line: 173
Function: include
File: /home3/analyti4/public_html/nerdingout/pastetool/application/core/MY_Loader.php
Line: 43
Function: _ci_load
File: /home3/analyti4/public_html/nerdingout/pastetool/application/controllers/Main.php
Line: 625
Function: view
File: /home3/analyti4/public_html/nerdingout/pastetool/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/analyti4/public_html/nerdingout/pastetool/system/core/Exceptions.php:271)
Filename: view/download.php
Line Number: 3
Backtrace:
File: /home3/analyti4/public_html/nerdingout/pastetool/themes/default/views/view/download.php
Line: 3
Function: header
File: /home3/analyti4/public_html/nerdingout/pastetool/application/core/MY_Loader.php
Line: 173
Function: include
File: /home3/analyti4/public_html/nerdingout/pastetool/application/core/MY_Loader.php
Line: 43
Function: _ci_load
File: /home3/analyti4/public_html/nerdingout/pastetool/application/controllers/Main.php
Line: 625
Function: view
File: /home3/analyti4/public_html/nerdingout/pastetool/index.php
Line: 315
Function: require_once
import os
import re
import csv
import string
import subprocess
# SITEBUILDER.py
# SCRIPT_VERSION 1.9
# by JASON BLACK
# last revision date 3/15/18
class ConfigBuilder(object):
def __init__(self, CSV,basetemplatefile,vrftemplatefile,sitetemplatefile):
self.CSV = CSV
self.CSV_DICT = {}
self.basetemplatefile = basetemplatefile
self.basetemplatecontents = ''
self.vrftemplatefile = vrftemplatefile
self.vrftemplatecontents = ''
self.sitetemplatefile = sitetemplatefile
self.siteemplatecontents = ''
# READ IN SITE SUMMARY TEMPLATE
with open(self.sitetemplatefile) as s:
self.sitetemplatecontents = s.read()
self.siteresultstring = self.sitetemplatecontents
# READ IN BASE CONFIG TEMPLATE
with open(self.basetemplatefile) as b:
self.basetemplatecontents = b.read()
self.baseresultstring = self.basetemplatecontents
# READ IN VRF TEMPLATE
with open(self.vrftemplatefile) as v:
self.vrftemplatecontents = v.read()
self.vrfresultstring = ''
# READ IN CSV FILE
with open(self.CSV, mode='r') as csvfile:
Detail_file = csv.reader(csvfile, delimiter=',')
# Cycle through Each ITEM-VALUE pair in the DETAIL FILE
for row in Detail_file:
# DEREFERENCE row ARRAY FOR CLARITY IN READING CODE
ITEM = row[0]
try:
VALUE = row[1]
except IndexError:
VALUE = ''
print "==== WARNING: ==== " + ITEM + " is missing a comma in the CSV file"
try:
REQUIRED_FIELD = bool(row[2])
except IndexError:
REQUIRED_FIELD = False
if (REQUIRED_FIELD == True and VALUE == ''):
print "==== WARNING: ==== " + ITEM + " == IS A REQUIRED FIELD!"
# CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK BEFORE STORING IN DICTIONARY
if VALUE.strip()!='':
self.CSV_DICT[ITEM] = VALUE
def generateBaseConfig(self):
# Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
for key in self.CSV_DICT:
ITEM = key
VALUE = self.CSV_DICT[key]
# CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK
self.baseresultstring = self.baseresultstring.replace(ITEM,VALUE)
return self.baseresultstring
def generateSiteSummary(self):
# Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
for key in self.CSV_DICT:
ITEM = key
VALUE = self.CSV_DICT[key]
# CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK
self.siteresultstring = self.siteresultstring.replace(ITEM,VALUE)
return self.siteresultstring
def generateAgencyVRFs(self):
NumVRFs = int(self.queryitem('@NUMBER_OF_AGENCY_VRFS'))
for x in range(1, (NumVRFs+1)):
self.vrfresultstring = self.vrfresultstring + self.vrftemplatecontents
# Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
for key in self.CSV_DICT:
#print key, self.CSV_DICT[key]
ITEM = key
VALUE = self.CSV_DICT[key]
# remove VRF1, VRF2, etc in ITEM key and replace with just VRF so I can use one template for all vrfs
basepattern = "VRF"
iterator = str(x)
fullpattern = basepattern+iterator
regex = re.compile(fullpattern)
ITEM = regex.sub('VRF', ITEM)
print ITEM, VALUE
self.vrfresultstring = self.vrfresultstring.replace(ITEM,VALUE)
return self.vrfresultstring
def queryitem(self,querystring):
# Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
for key in self.CSV_DICT:
ITEM = key
VALUE = self.CSV_DICT[key]
if ITEM == querystring:
queryresult = VALUE
return queryresult
def writeconfig(self,outputfilename,FinalOutput):
if os.path.isfile(outputfilename):
os.remove(outputfilename)
with open(outputfilename + '.txt', 'w') as outputFile:
print '==== INFO: ==== WRITING FINAL CONFIG FILE: ' + outputfilename + '.txt'
outputFile.write(FinalOutput)
def writesitesummary(self,sitesummary):
if os.path.isfile('SiteSummary.txt'):
os.remove('SiteSummary.txt')
with open('SiteSummary.txt', 'w') as outputFile:
print '==== INFO: ==== WRITING SITE SUMMARY FILE: SiteSummary.txt'
outputFile.write(sitesummary)
def fullbuild1(self):
baseconfig = self.generateBaseConfig()
vrfconfig = self.generateAgencyVRFs()
sitesummary = self.generateSiteSummary()
# WRITE ROUTER 1 CONFIG FILE
outputfilename = self.queryitem('@SITE_DDB_R1_NAME_OF_ROUTER')
FinalOutput = baseconfig + vrfconfig
self.writeconfig(outputfilename,FinalOutput)
# WRITE SITE SUMMARY FILE
self.writesitesummary(sitesummary)
# this was moved to a separate script/CSV file.
def fullbuild2(self):
baseconfig = self.generateBaseConfig()
vrfconfig = self.generateAgencyVRFs()
sitesummary = self.generateSiteSummary()
# WRITE ROUTER 1 CONFIG FILE
outputfilename = self.queryitem('@SITE_DDB_R2_NAME_OF_ROUTER')
FinalOutput = baseconfig + vrfconfig
self.writeconfig(outputfilename,FinalOutput)
# WRITE SITE SUMMARY FILE
# self.writesitesummary(sitesummary)
# this was moved to a separate script/CSV file.
def OpenOutput1(object):
fileName = object.queryitem('@SITE_DDB_R1_NAME_OF_ROUTER')+'.txt'
programName = "notepad.exe"
subprocess.Popen([programName, fileName])
def OpenOutput2(object):
fileName = object.queryitem('@SITE_DDB_R2_NAME_OF_ROUTER')+'.txt'
programName = "notepad.exe"
subprocess.Popen([programName, fileName])
def OpenOutput3():
fileName = 'sitesummary.txt'
programName = "notepad.exe"
subprocess.Popen([programName, fileName])
def main():
MPLSGen1 = ConfigBuilder('migrationDetails.csv','BaseMPLSRouter1.tmpl','R1AgencyVRF.tmpl','SiteSummary.tmpl')
MPLSGen1.fullbuild1()
MPLSGen2 = ConfigBuilder('migrationDetails.csv','BaseMPLSRouter2.tmpl','R2AgencyVRF.tmpl','SiteSummary.tmpl')
MPLSGen2.fullbuild2()
OpenOutput1(MPLSGen1)
OpenOutput2(MPLSGen2)
OpenOutput3()
if __name__ == '__main__':
main()