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: 693
Function: getPaste

File: /home3/analyti4/public_html/nerdingout/pastetool/index.php
Line: 315
Function: require_once

SiteBuilder - NerdingOut Paste Tool (Stikked)

SiteBuilder

From Black, 6 Years ago, written in Python, viewed 66 times.
URL http://nerdingout.net/pastetool/view/13a987fc Embed
Download Paste or View Raw
  1. import os
  2. import re
  3. import csv
  4. import string
  5. import subprocess
  6.  
  7. # SITEBUILDER.py
  8. # SCRIPT_VERSION 1.9
  9. # by JASON BLACK
  10. # last revision date 3/15/18
  11.  
  12. class ConfigBuilder(object):
  13.         def __init__(self, CSV,basetemplatefile,vrftemplatefile,sitetemplatefile):
  14.                 self.CSV = CSV
  15.                 self.CSV_DICT = {}
  16.                 self.basetemplatefile = basetemplatefile
  17.                 self.basetemplatecontents = ''
  18.                 self.vrftemplatefile = vrftemplatefile
  19.                 self.vrftemplatecontents = ''
  20.                 self.sitetemplatefile = sitetemplatefile
  21.                 self.siteemplatecontents = ''
  22.                
  23.                 # READ IN SITE SUMMARY TEMPLATE
  24.                 with open(self.sitetemplatefile) as s:
  25.                         self.sitetemplatecontents = s.read()
  26.                 self.siteresultstring = self.sitetemplatecontents
  27.                
  28.                 # READ IN BASE CONFIG TEMPLATE
  29.                 with open(self.basetemplatefile) as b:
  30.                         self.basetemplatecontents = b.read()
  31.                 self.baseresultstring = self.basetemplatecontents
  32.                
  33.                 # READ IN VRF TEMPLATE
  34.                 with open(self.vrftemplatefile) as v:
  35.                         self.vrftemplatecontents = v.read()
  36.                 self.vrfresultstring = ''
  37.  
  38.                 # READ IN CSV FILE
  39.                 with open(self.CSV, mode='r') as csvfile:
  40.                         Detail_file = csv.reader(csvfile, delimiter=',')
  41.                         # Cycle through Each ITEM-VALUE pair in the DETAIL FILE
  42.                         for row in Detail_file:
  43.                                 # DEREFERENCE row ARRAY FOR CLARITY IN READING CODE
  44.                                 ITEM = row[0]
  45.                                 try:
  46.                                         VALUE = row[1]
  47.                                 except IndexError:
  48.                                         VALUE = ''
  49.                                         print "==== WARNING: ==== " + ITEM + " is missing a comma in the CSV file"
  50.                                 try:
  51.                                         REQUIRED_FIELD = bool(row[2])
  52.                                 except IndexError:
  53.                                         REQUIRED_FIELD = False
  54.                                 if (REQUIRED_FIELD == True and VALUE == ''):
  55.                                         print "==== WARNING: ==== " + ITEM + " == IS A REQUIRED FIELD!"
  56.                                 # CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK BEFORE STORING IN DICTIONARY
  57.                                 if VALUE.strip()!='':
  58.                                         self.CSV_DICT[ITEM] = VALUE
  59.                                
  60.         def generateBaseConfig(self):
  61.                 # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  62.                 for key in self.CSV_DICT:
  63.                         ITEM = key
  64.                         VALUE = self.CSV_DICT[key]
  65.                         # CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK
  66.                         self.baseresultstring = self.baseresultstring.replace(ITEM,VALUE)
  67.                 return self.baseresultstring
  68.  
  69.         def generateSiteSummary(self):
  70.                 # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  71.                 for key in self.CSV_DICT:
  72.                         ITEM = key
  73.                         VALUE = self.CSV_DICT[key]
  74.                         # CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK
  75.                         self.siteresultstring = self.siteresultstring.replace(ITEM,VALUE)
  76.                 return self.siteresultstring           
  77.                
  78.         def generateAgencyVRFs(self):
  79.                 NumVRFs = int(self.queryitem('@NUMBER_OF_AGENCY_VRFS'))
  80.                 for x in range(1, (NumVRFs+1)):
  81.                         self.vrfresultstring = self.vrfresultstring + self.vrftemplatecontents
  82.                         # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  83.                         for key in self.CSV_DICT:
  84.                                 #print key, self.CSV_DICT[key]
  85.                                 ITEM = key
  86.                                 VALUE = self.CSV_DICT[key]
  87.                                 # remove VRF1, VRF2, etc in ITEM key and replace with just VRF so I can use one template for all vrfs
  88.                                 basepattern = "VRF"
  89.                                 iterator = str(x)
  90.                                 fullpattern = basepattern+iterator
  91.                                 regex = re.compile(fullpattern)
  92.                                 ITEM = regex.sub('VRF', ITEM)
  93.                                 print ITEM, VALUE
  94.                                 self.vrfresultstring = self.vrfresultstring.replace(ITEM,VALUE)
  95.                 return self.vrfresultstring
  96.  
  97.         def queryitem(self,querystring):
  98.                 # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  99.                 for key in self.CSV_DICT:
  100.                         ITEM = key
  101.                         VALUE = self.CSV_DICT[key]
  102.                         if ITEM == querystring:
  103.                                 queryresult = VALUE
  104.                                 return queryresult
  105.                                                
  106.         def writeconfig(self,outputfilename,FinalOutput):
  107.                 if os.path.isfile(outputfilename):
  108.                         os.remove(outputfilename)
  109.                 with open(outputfilename + '.txt', 'w') as outputFile:
  110.                         print '====   INFO:  ==== WRITING FINAL CONFIG FILE: ' + outputfilename + '.txt'
  111.                         outputFile.write(FinalOutput)
  112.  
  113.         def writesitesummary(self,sitesummary):
  114.                 if os.path.isfile('SiteSummary.txt'):
  115.                         os.remove('SiteSummary.txt')
  116.                 with open('SiteSummary.txt', 'w') as outputFile:
  117.                         print '====   INFO:  ==== WRITING SITE SUMMARY FILE: SiteSummary.txt'
  118.                         outputFile.write(sitesummary)
  119.                        
  120.         def fullbuild1(self):
  121.                 baseconfig = self.generateBaseConfig()
  122.                 vrfconfig = self.generateAgencyVRFs()
  123.                 sitesummary = self.generateSiteSummary()
  124.                
  125.                 # WRITE ROUTER 1 CONFIG FILE
  126.                 outputfilename = self.queryitem('@SITE_DDB_R1_NAME_OF_ROUTER')
  127.                 FinalOutput = baseconfig + vrfconfig
  128.                 self.writeconfig(outputfilename,FinalOutput)
  129.                
  130.                 # WRITE SITE SUMMARY FILE
  131.                 self.writesitesummary(sitesummary)
  132.                 # this was moved to a separate script/CSV file.
  133.                
  134.         def fullbuild2(self):
  135.                 baseconfig = self.generateBaseConfig()
  136.                 vrfconfig = self.generateAgencyVRFs()
  137.                 sitesummary = self.generateSiteSummary()
  138.                
  139.                 # WRITE ROUTER 1 CONFIG FILE
  140.                 outputfilename = self.queryitem('@SITE_DDB_R2_NAME_OF_ROUTER')
  141.                 FinalOutput = baseconfig + vrfconfig
  142.                 self.writeconfig(outputfilename,FinalOutput)
  143.                
  144.                 # WRITE SITE SUMMARY FILE
  145.                 # self.writesitesummary(sitesummary)
  146.                 # this was moved to a separate script/CSV file.
  147.                
  148. def OpenOutput1(object):
  149.         fileName = object.queryitem('@SITE_DDB_R1_NAME_OF_ROUTER')+'.txt'
  150.         programName = "notepad.exe"
  151.         subprocess.Popen([programName, fileName])
  152.  
  153. def OpenOutput2(object):
  154.         fileName = object.queryitem('@SITE_DDB_R2_NAME_OF_ROUTER')+'.txt'
  155.         programName = "notepad.exe"
  156.         subprocess.Popen([programName, fileName])
  157.        
  158. def OpenOutput3():
  159.         fileName = 'sitesummary.txt'
  160.         programName = "notepad.exe"
  161.         subprocess.Popen([programName, fileName])
  162.        
  163. def main():
  164.         MPLSGen1 = ConfigBuilder('migrationDetails.csv','BaseMPLSRouter1.tmpl','R1AgencyVRF.tmpl','SiteSummary.tmpl')
  165.         MPLSGen1.fullbuild1()
  166.         MPLSGen2 = ConfigBuilder('migrationDetails.csv','BaseMPLSRouter2.tmpl','R2AgencyVRF.tmpl','SiteSummary.tmpl')
  167.         MPLSGen2.fullbuild2()
  168.        
  169.         OpenOutput1(MPLSGen1)
  170.         OpenOutput2(MPLSGen2)
  171.         OpenOutput3()
  172.        
  173. if __name__ == '__main__':
  174.    main()
  175.  

Reply to "SiteBuilder"

Here you can reply to the paste above

captcha