|
| 1 | +#!/usr/bin/python |
| 2 | +# -*- coding: iso-8859-15 -*- |
| 3 | + |
| 4 | +# This script generates the version header to be used in REST installation |
| 5 | + |
| 6 | +# 23 - Dec - 2019 |
| 7 | + |
| 8 | +#from __future__ import print_function |
| 9 | +import os |
| 10 | +import sys |
| 11 | +import re |
| 12 | +import filecmp |
| 13 | +import subprocess |
| 14 | + |
| 15 | + |
| 16 | +def validateClass(className): |
| 17 | + print "" |
| 18 | + print "++++ Validating class : " + className |
| 19 | + with open(className, 'r') as file: |
| 20 | + data = file.read() |
| 21 | + |
| 22 | + data = data[data.find("::Initialize"):] |
| 23 | + data = getMethodDefinition(data) |
| 24 | + data = removeCppComment(data) |
| 25 | + |
| 26 | + #print (data) |
| 27 | + #print data.find("SETLIBRARYVERSION(LIBRARY_VERSION);") |
| 28 | + if data.find("SETLIBRARYVERSION(LIBRARY_VERSION);") >= 0: |
| 29 | + print "OK" |
| 30 | + return |
| 31 | + else: |
| 32 | + print( "Problem found at class : " + className ) |
| 33 | + print( "SetLibraryVersion was NOT found at Initialization!" ) |
| 34 | + sys.exit(1) |
| 35 | + return |
| 36 | + |
| 37 | +def getObservablePositions(data): |
| 38 | + obsposes = {} |
| 39 | + pos = 0 |
| 40 | + str = "SETOBSERVABLEVALUE(\"" |
| 41 | + while(pos < len(data)): |
| 42 | + pos1 = data.find(str,pos) |
| 43 | + if(pos1 == -1): |
| 44 | + break |
| 45 | + pos1 += len(str) |
| 46 | + pos2 = data.find("\"",pos1) |
| 47 | + if(pos2 == -1): |
| 48 | + break |
| 49 | + |
| 50 | + name = data[pos1:pos2] |
| 51 | + if(not obsposes.has_key(name)): |
| 52 | + obsposes[name] = pos1 |
| 53 | + |
| 54 | + pos = pos2 + 1 |
| 55 | + return obsposes |
| 56 | + |
| 57 | + |
| 58 | +def getMethodDefinition(text): |
| 59 | + initPos = text.find("{") |
| 60 | + |
| 61 | + counter = 1 |
| 62 | + start = initPos + 1 |
| 63 | + while(counter > 0): |
| 64 | + pos1 = text.find("{",start) |
| 65 | + pos2 = text.find("}",start) |
| 66 | + |
| 67 | + endPosition = pos2 + 1 |
| 68 | + |
| 69 | + if(pos1 != -1 and pos2 != -1): |
| 70 | + if(pos1 < pos2): |
| 71 | + counter = counter + 1 |
| 72 | + start = pos1 + 1 |
| 73 | + if(pos2 < pos1): |
| 74 | + counter = counter - 1 |
| 75 | + start = pos2 + 1 |
| 76 | + elif pos1 != -1: |
| 77 | + print "Big error!!" |
| 78 | + else: |
| 79 | + counter = counter - 1 |
| 80 | + start = pos2 + 1 |
| 81 | + |
| 82 | + return text[initPos:endPosition].upper() |
| 83 | + |
| 84 | + |
| 85 | +def removeCppComment(strInput) : |
| 86 | + state = 0; |
| 87 | + strOutput = '' |
| 88 | + strRemoved = '' |
| 89 | + |
| 90 | + for c in strInput : |
| 91 | + if state == 0 and c == '/' : # ex. [/] |
| 92 | + state = 1 |
| 93 | + elif state == 1 and c == '*' : # ex. [/*] |
| 94 | + state = 2 |
| 95 | + elif state == 1 and c == '/' : # ex. [#] |
| 96 | + state = 4 |
| 97 | + elif state == 1 : # ex. [<secure/_stdio.h> or 5/3] |
| 98 | + state = 0 |
| 99 | + |
| 100 | + elif state == 3 and c == '*': # ex. [/*he**] |
| 101 | + state = 3 |
| 102 | + elif state == 2 and c == '*': # ex. [/*he*] |
| 103 | + state = 3 |
| 104 | + elif state == 2: # ex. [/*heh] |
| 105 | + state = 2 |
| 106 | + |
| 107 | + elif state == 3 and c == '/': # ex. [/*heh*/] |
| 108 | + state = 0 |
| 109 | + elif state == 3: # ex. [/*heh*e] |
| 110 | + state = 2 |
| 111 | + |
| 112 | + elif state == 4 and c == '\\': # ex. [//hehe\] |
| 113 | + state = 9 |
| 114 | + elif state == 9 and c == '\\': # ex. [//hehe\\\\\] |
| 115 | + state = 9 |
| 116 | + elif state == 9: # ex. [//hehe\<enter> or //hehe\a] |
| 117 | + state = 4 |
| 118 | + elif state == 4 and c == '\n': # ex. [//hehe<enter>] |
| 119 | + state = 0 |
| 120 | + |
| 121 | + elif state == 0 and c == '\'': # ex. ['] |
| 122 | + state = 5 |
| 123 | + elif state == 5 and c == '\\': # ex. ['\] |
| 124 | + state = 6 |
| 125 | + elif state == 6: # ex. ['\n or '\' or '\t etc.] |
| 126 | + state = 5 |
| 127 | + elif state == 5 and c == '\'': # ex. ['\n' or '\'' or '\t' ect.] |
| 128 | + state = 0 |
| 129 | + |
| 130 | + elif state == 0 and c == '\"': # ex. ["] |
| 131 | + state = 7 |
| 132 | + elif state == 7 and c == '\\': # ex. ["\] |
| 133 | + state = 8 |
| 134 | + elif state == 8: # ex. ["\n or "\" or "\t ect.] |
| 135 | + state = 7 |
| 136 | + elif state == 7 and c == '\"': # ex. ["\n" or "\"" or "\t" ect.] |
| 137 | + state = 0 |
| 138 | + |
| 139 | + if (state == 0 and c != '/') or state == 5 or\ |
| 140 | + state == 6 or state == 7 or state == 8 : |
| 141 | + strOutput += c |
| 142 | + else: |
| 143 | + # removed chareters |
| 144 | + strRemoved += c |
| 145 | + |
| 146 | + return strOutput |
| 147 | + |
| 148 | + |
| 149 | +files = [] |
| 150 | + |
| 151 | +# r=root, d=directories, f = files |
| 152 | +for r, d, f in os.walk(sys.argv[1]): |
| 153 | + for file in f: |
| 154 | + validate = 0 |
| 155 | + if '.cxx' in file: |
| 156 | +# print ( file ) |
| 157 | + with open(os.path.join(r, file)) as fin: |
| 158 | + if '::InitFromConfigFile' in fin.read(): |
| 159 | + validate = 1 |
| 160 | + with open(os.path.join(r, file)) as fin: |
| 161 | + if '::LoadDefaultConfig' in fin.read(): |
| 162 | + validate = 1 |
| 163 | + with open(os.path.join(r, file)) as fin: |
| 164 | + if '::Initialize' in fin.read(): |
| 165 | + validate = validate + 1 |
| 166 | + if validate == 2: |
| 167 | + files.append(os.path.join(r, file)) |
| 168 | + validateClass(os.path.join(r, file)) |
| 169 | + |
| 170 | +#for f in files: |
| 171 | +# print(f) |
| 172 | + |
| 173 | +#validateProcess(sys.argv[1]); |
| 174 | +sys.exit(0) |
0 commit comments