-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESconfig.py
More file actions
89 lines (86 loc) · 2.71 KB
/
Copy pathESconfig.py
File metadata and controls
89 lines (86 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#-*-coding:utf8 -*-
'''
缓存配置,缓存服务挂掉时,程序里的数据,以及elasticsearch的搜索点
'''
import ConfigParser
import os
import pdb
import json
from Clogdata import Clogdata
from EShelplog import getlogInst
import os
g_loginst=getlogInst()
cf = ConfigParser.ConfigParser()
cf.read('config/ess.conf')
class ESconfig:
def __init__(self):
global cf
secs = cf.sections()
self.Scalesize=0
def setsize(self,size):
self.Scalesize=size
ret=cf.set("elasticsearchpara","scalsize",size)
with open("config/ess.conf", "w+") as f:
cf.write(f)
def getsize(self):
temp = cf.get("elasticsearchpara", "scalsize")
self.Scalesize = int(cf.get("elasticsearchpara", "scalsize"))
return self.Scalesize
class Dictcache:
def __init__(self):
self.dict={}
def Getdict(self):
global cf
secs = cf.sections()
str = cf.get("dictdata", "g_dict")
self.dict = self.deserialize(str)
return self.dict
def Setdict(self,tempdict):
self.dict = tempdict
ret = cf.set("dictdata", "g_dict", self.serialize())
with open("config/ess.conf", "w+") as f:
cf.write(f)
def serialize(self):
strdict=""
for (key,value) in self.dict.items():
strdict+=key
strdict+="@@@"
valuedata=json.dumps(value.Data2Json())
strdict+=str(valuedata)
strdict+="&&"
strdict=strdict[:-2] #去掉最后一个”&&“
return strdict
def deserialize(self,strdata):
tempdict={}
strdata=strdata.encode('utf-8')
filedlist = strdata.split('&&')
for item in filedlist:
keyvalue=item.split("@@@",1)
strobj=keyvalue[1]
jsonobj=json.loads(strobj.encode('utf-8'))
logobj=Clogdata()
logobj.copyAttr(jsonobj)
tempdict[keyvalue[0]]=logobj
self.dict=tempdict
return self.dict
pass
def Createconf(self):# 不存在就创建一个
global g_loginst
flag=os.path.exists('config/ess.conf')
if flag==True:
pass
g_loginst.logger.info("配置文件存在,不需要创建")
else:
g_loginst.logger.info("配置文件不存在,创建文件")
cf.add_section('elasticsearchpara')
cf.set('elasticsearchpara','scalsize',0)
cf.add_section('dictdata')
cf.set('dictdata','g_dict',{})
pdb.set_trace()
with open('config/ess.conf', 'w') as configfile:
cf.write(configfile)
if __name__ =='__main__':
pass
t=Dictcache()
pdb.set_trace()
t.Createconf()