|
@@ -191,26 +191,28 @@ SET_TAIL_ENTERPRISE_HUGE_FILE = "SET_TAIL_ENTERPRISE_HUGE.pk"
|
|
def getDict_enterprise():
|
|
def getDict_enterprise():
|
|
global DICT_ENTERPRISE_DONE,SET_ENTERPRISE,SET_PREFIX_ENTERPRISE,SET_TAIL_ENTERPRISE
|
|
global DICT_ENTERPRISE_DONE,SET_ENTERPRISE,SET_PREFIX_ENTERPRISE,SET_TAIL_ENTERPRISE
|
|
real_path,is_huge = getEnterprisePath()
|
|
real_path,is_huge = getEnterprisePath()
|
|
|
|
+ _ok = False
|
|
if is_huge:
|
|
if is_huge:
|
|
if os.path.exists(SET_PREFIX_ENTERPRISE_HUGE_FILE) and os.path.exists(SET_TAIL_ENTERPRISE_HUGE_FILE):
|
|
if os.path.exists(SET_PREFIX_ENTERPRISE_HUGE_FILE) and os.path.exists(SET_TAIL_ENTERPRISE_HUGE_FILE):
|
|
SET_PREFIX_ENTERPRISE = load(SET_PREFIX_ENTERPRISE_HUGE_FILE)
|
|
SET_PREFIX_ENTERPRISE = load(SET_PREFIX_ENTERPRISE_HUGE_FILE)
|
|
SET_TAIL_ENTERPRISE = load(SET_TAIL_ENTERPRISE_HUGE_FILE)
|
|
SET_TAIL_ENTERPRISE = load(SET_TAIL_ENTERPRISE_HUGE_FILE)
|
|
- else:
|
|
|
|
- with open(real_path,"r",encoding="UTF8") as f:
|
|
|
|
- for _e in f:
|
|
|
|
- if not _e:
|
|
|
|
- continue
|
|
|
|
- _e = _e.strip()
|
|
|
|
- if len(_e)>=4:
|
|
|
|
- key_enter = _e[:ENTERPRISE_KEY_LEN]
|
|
|
|
- SET_PREFIX_ENTERPRISE.add(key_enter)
|
|
|
|
- SET_TAIL_ENTERPRISE.add(_e[-ENTERPRISE_TAIL_LEN:])
|
|
|
|
- if not is_huge:
|
|
|
|
- SET_ENTERPRISE.add(_e)
|
|
|
|
- #仅在大文件情况下才使用缓存加载
|
|
|
|
- if is_huge:
|
|
|
|
- save(SET_PREFIX_ENTERPRISE,SET_PREFIX_ENTERPRISE_HUGE_FILE)
|
|
|
|
- save(SET_TAIL_ENTERPRISE,SET_TAIL_ENTERPRISE_HUGE_FILE)
|
|
|
|
|
|
+ _ok = True
|
|
|
|
+ if not _ok:
|
|
|
|
+ with open(real_path,"r",encoding="UTF8") as f:
|
|
|
|
+ for _e in f:
|
|
|
|
+ if not _e:
|
|
|
|
+ continue
|
|
|
|
+ _e = _e.strip()
|
|
|
|
+ if len(_e)>=4:
|
|
|
|
+ key_enter = _e[:ENTERPRISE_KEY_LEN]
|
|
|
|
+ SET_PREFIX_ENTERPRISE.add(key_enter)
|
|
|
|
+ SET_TAIL_ENTERPRISE.add(_e[-ENTERPRISE_TAIL_LEN:])
|
|
|
|
+ if not is_huge:
|
|
|
|
+ SET_ENTERPRISE.add(_e)
|
|
|
|
+ #仅在大文件情况下才使用缓存加载
|
|
|
|
+ if is_huge:
|
|
|
|
+ save(SET_PREFIX_ENTERPRISE,SET_PREFIX_ENTERPRISE_HUGE_FILE)
|
|
|
|
+ save(SET_TAIL_ENTERPRISE,SET_TAIL_ENTERPRISE_HUGE_FILE)
|
|
|
|
|
|
|
|
|
|
log("SET_PREFIX_ENTERPRISE takes memory:%.2fM size:%d"%(sys.getsizeof(SET_PREFIX_ENTERPRISE)/1024/1024,len(SET_PREFIX_ENTERPRISE)))
|
|
log("SET_PREFIX_ENTERPRISE takes memory:%.2fM size:%d"%(sys.getsizeof(SET_PREFIX_ENTERPRISE)/1024/1024,len(SET_PREFIX_ENTERPRISE)))
|