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

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

Configbuilder.py - NerdingOut Paste Tool (Stikked)

This paste brought to you by NerdingOut Paste Tool (Stikked). View Raw

  1. import os
  2. import re
  3. import csv
  4. import string
  5. import subprocess
  6.  
  7. class ConfigBuilder(object):
  8.         def __init__(self, CSV,basetemplatefile,vrftemplatefile):
  9.                 self.CSV = CSV
  10.                 self.CSV_DICT = {}
  11.                 self.basetemplatefile = basetemplatefile
  12.                 self.basetemplatecontents = ''
  13.                 self.vrftemplatefile = vrftemplatefile
  14.                 self.vrftemplatecontents = ''
  15.                
  16.                 # READ IN BASE CONFIG TEMPLATE
  17.                 with open(self.basetemplatefile) as b:
  18.                         self.basetemplatecontents = b.read()
  19.                 self.baseresultstring = self.basetemplatecontents
  20.                
  21.                 # READ IN VRF TEMPLATE
  22.                 with open(self.vrftemplatefile) as v:
  23.                         self.vrftemplatecontents = v.read()
  24.                 self.vrfresultstring = ''
  25.  
  26.                 # READ IN CSV FILE
  27.                 with open(self.CSV, mode='r') as csvfile:
  28.                         Detail_file = csv.reader(csvfile, delimiter=',')
  29.                         # Cycle through Each ITEM-VALUE pair in the DETAIL FILE
  30.                         for row in Detail_file:
  31.                                 # DEREFERENCE row ARRAY FOR CLARITY IN READING CODE
  32.                                 ITEM = row[0]
  33.                                 try:
  34.                                         VALUE = row[1]
  35.                                 except IndexError:
  36.                                         VALUE = ''
  37.                                         print "==== WARNING: ==== " + ITEM + " is missing a comma in the CSV file"
  38.                                 try:
  39.                                         REQUIRED_FIELD = bool(row[2])
  40.                                 except IndexError:
  41.                                         REQUIRED_FIELD = False
  42.                                 if (REQUIRED_FIELD == True and VALUE == ''):
  43.                                         print "\n==== WARNING: ==== " + ITEM + " == IS A REQUIRED FIELD!\n"
  44.                                 # CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK BEFORE STORING IN DICTIONARY
  45.                                 if VALUE.strip()!='':
  46.                                         self.CSV_DICT[ITEM] = VALUE
  47.                                
  48.         def generateBaseConfig(self):
  49.                 # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  50.                 for key in self.CSV_DICT:
  51.                         # DEREFERENCE row ARRAY FOR CLARITY IN READING CODE
  52.                         ITEM = key
  53.                         VALUE = self.CSV_DICT[key]
  54.                         # CHECK TO MAKE SURE THE CONFIG_VALUE ISN"T BLANK
  55.                         self.baseresultstring = self.baseresultstring.replace(ITEM,VALUE)
  56.                 return self.baseresultstring
  57.  
  58.         def generateAgencyVRFs(self):
  59.                 NumVRFs = self.queryitem('@NUMBER_OF_AGENCY_VRFS')
  60.                 for x in range(1, int(NumVRFs)+1):
  61.                         self.vrfresultstring = self.vrfresultstring + self.vrftemplatecontents
  62.                         # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  63.                         for key in self.CSV_DICT:
  64.                                 #print key, self.CSV_DICT[key]
  65.                                 # DEREFERENCE row ARRAY FOR CLARITY IN READING CODE
  66.                                 ITEM = key
  67.                                 VALUE = self.CSV_DICT[key]
  68.                                 # remove VRF1, VRF2, etc in ITEM key and replace with just VRF so I can use one template for all vrfs
  69.                                 basepattern = "VRF"
  70.                                 iterator = str(x)
  71.                                 fullpattern = basepattern+iterator
  72.                                 regex = re.compile(fullpattern)
  73.                                 ITEM = regex.sub('VRF', ITEM)
  74.                                 #print ITEM, VALUE
  75.                                 self.vrfresultstring = self.vrfresultstring.replace(ITEM,VALUE)
  76.                 return self.vrfresultstring
  77.  
  78.         def queryitem(self,querystring):
  79.                 # Cycle through Each ITEM-VALUE pair in the CSV DICTIONARY
  80.                 for key in self.CSV_DICT:
  81.                         # DEREFERENCE row ARRAY FOR CLARITY IN READING CODE
  82.                         ITEM = key
  83.                         VALUE = self.CSV_DICT[key]
  84.                         if ITEM == querystring:
  85.                                 queryresult = VALUE
  86.                                 return queryresult
  87.                                                
  88.         def writeconfig(self,outputfilename,FinalOutput):
  89.                 if os.path.isfile(outputfilename):
  90.                         os.remove(outputfilename)
  91.                 with open(outputfilename + '.txt', 'w') as outputFile:
  92.                         print '\n==== INFO: ==== WRITING FINAL CONFIG FILE: ' + outputfilename + '.txt'
  93.                         outputFile.write(FinalOutput)
  94.                        
  95.         def fullbuild(self):
  96.                 baseconfig = self.generateBaseConfig()
  97.                 vrfconfig = self.generateAgencyVRFs()
  98.                 outputfilename = self.queryitem('@RTR_NAME_OF_ROUTER')
  99.                 FinalOutput = baseconfig + vrfconfig
  100.                 self.writeconfig(outputfilename,FinalOutput)
  101.                
  102. def OpenOutput(object):
  103.         fileName = object.queryitem('@RTR_NAME_OF_ROUTER')+'.txt'
  104.         programName = "notepad.exe"
  105.         subprocess.Popen([programName, fileName])
  106.  
  107. def main():
  108.         MPLSGen = ConfigBuilder('RouterDetails.csv','BaseMPLSRouter.tmpl','AgencyVRF.tmpl')
  109.         MPLSGen.fullbuild()
  110.         OpenOutput(MPLSGen)
  111.        
  112. if __name__ == '__main__':
  113.    main()
  114.