Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import os
00034 import sys
00035 import shutil
00036 import re
00037
00038 class Enum(set):
00039 def __getattr__(self, name):
00040 if name in self:
00041 return name
00042 raise AttributeError
00043
00044 def get_value(pathname, keyname):
00045 try:
00046 file = open(pathname, 'r')
00047 buff = file.read()
00048 except:
00049 print("File not found.")
00050 return buff
00051
00052 condition = re.compile('^.+', re.M)
00053 lines = condition.findall(buff)
00054 vars = []
00055 AssembleMode = Enum(["None", "Symbol", "Sentence"])
00056
00057 try:
00058 iter_lines = iter(lines)
00059 for i in iter_lines:
00060 line = i.strip()
00061 if line[0] == '#':
00062 continue
00063
00064 tokens = re.split('[()]+', i)
00065 token = tokens[0].lower()
00066 command = token.strip()
00067
00068
00069 if command != 'set':
00070 continue
00071
00072 runner = 0;
00073 token = tokens[1]
00074 length = len(token)
00075
00076
00077
00078
00079
00080 mode = AssembleMode.None
00081 word = ""
00082 words = []
00083
00084 while runner < length:
00085 if token[runner] == ' ':
00086 if mode == AssembleMode.Symbol:
00087 words.append(word)
00088 word = ""
00089 mode = AssembleMode.None
00090 elif mode == AssembleMode.Sentence:
00091 word += token[runner]
00092 elif token[runner] == '"':
00093 if mode == AssembleMode.None:
00094 mode = AssembleMode.Sentence
00095 elif mode == AssembleMode.Symbol:
00096 words.append(word)
00097 word = ""
00098 mode = AssembleMode.Sentence
00099 elif mode == AssembleMode.Sentence:
00100 words.append(word)
00101 word = ""
00102 mode = AssembleMode.None
00103 else:
00104 word += token[runner]
00105 if mode == AssembleMode.None:
00106 mode = AssembleMode.Symbol
00107
00108 runner += 1
00109
00110 if len(words) < 2:
00111 continue
00112
00113
00114
00115
00116
00117 try:
00118 idx = words.index('CACHE')
00119 runner = 0
00120 val = words[1]
00121 while runner < (idx - 2):
00122 val += ' '
00123 val += words[runner + 2]
00124 runner += 1
00125 except:
00126 val = words[1]
00127
00128 dic = {"key":words[0], "val":val}
00129 vars.append(dic)
00130
00131 except:
00132 return ""
00133
00134
00135
00136
00137
00138 for j in vars:
00139 if j["key"] == keyname:
00140 return j["val"]
00141
00142 return ""