MCPcopy Create free account
hub / github.com/EasyIME/PIME / Debug

Class Debug

python/cinbase/debug.py:7–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5from cinbase.tools import cpuinfo
6
7class Debug:
8 def __init__(self, imeDirName):
9 self.info = cpuinfo.get_cpu_info()
10 self.debugLog = {}
11 self.startTime = {}
12 self.endTime = {}
13 self.imeDirName = imeDirName
14 self.jsonNameDict = ({"checj.json": "酷倉", "mscj3.json": "倉頡", "mscj3-ext.json": "倉頡(大字集)", "cj-ext.json": "雅虎倉頡", "cnscj.json": "中標倉頡",
15 "thcj.json": "泰瑞倉頡", "newcj3.json": "亂倉打鳥", "cj5.json": "倉頡五代", "newcj.json": "自由大新倉頡", "scj6.json": "快倉六代",
16 "thphonetic.json": "泰瑞注音", "CnsPhonetic.json": "中標注音", "bpmf.json": "傳統注音", "tharray.json": "泰瑞行列30", "array30.json": "行列30",
17 "ar30-big.json": "行列30大字集", "array40.json": "行列40", "thdayi.json": "泰瑞大易四碼", "dayi4.json": "大易四碼", "dayi3.json": "大易三碼",
18 "ez.json": "輕鬆", "ezsmall.json": "輕鬆小詞庫", "ezmid.json": "輕鬆中詞庫", "ezbig.json": "輕鬆大詞庫", "thpinyin.json": "泰瑞拼音",
19 "pinyin.json": "正體拼音", "roman.json": "羅馬拼音", "simplecj.json": "正體簡易", "simplex.json": "速成", "simplex5.json": "簡易五代",
20 "liu.json": "嘸蝦米"})
21
22 def getConfigDir(self):
23 config_dir = os.path.join(os.path.expandvars("%APPDATA%"), "PIME", self.imeDirName)
24 os.makedirs(config_dir, mode=0o700, exist_ok=True)
25 return config_dir
26
27 def getConfigFile(self, name="debug.json"):
28 return os.path.join(self.getConfigDir(), name)
29
30 def loadDebugLog(self):
31 jsondata = {}
32 filename = self.getConfigFile()
33 if os.path.isfile(filename):
34 try:
35 with open(filename, 'r', encoding='utf8') as f:
36 jsondata = json.load(f)
37 except Exception:
38 pass # FIXME: handle I/O errors?
39 self.debugLog = copy.deepcopy(jsondata)
40 return jsondata
41
42 def setStartTimer(self, timerName):
43 self.startTime[timerName] = time.time()
44
45 def setEndTimer(self, timerName):
46 self.endTime[timerName] = time.time()
47
48 def getDurationTime(self, timerName):
49 durationTime = round(self.endTime[timerName] - self.startTime[timerName], 2)
50 return str(durationTime)
51
52 def saveDebugLog(self, debugLog):
53 filename = self.getConfigFile()
54 try:
55 with open(filename, 'w', encoding='utf8') as f:
56 js = json.dump(debugLog, f, ensure_ascii=False, sort_keys=True, indent=4)
57 self.debugLog = copy.deepcopy(debugLog)
58 except Exception:
59 pass # FIXME: handle I/O errors?
60
61__all__ = ["Debug"]

Callers 1

initTextServiceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected