45 lines
732 B
Python
45 lines
732 B
Python
|
from logging import getLogger
|
||
|
import re
|
||
|
|
||
|
# noinspection PyUnreachableCode
|
||
|
if False:
|
||
|
from typing import Dict
|
||
|
|
||
|
_log = getLogger(__name__)
|
||
|
|
||
|
|
||
|
def make2way(dic):
|
||
|
# type: (Dict) -> Dict
|
||
|
for k, v in dic.items():
|
||
|
dic[v] = k
|
||
|
|
||
|
return dic
|
||
|
|
||
|
|
||
|
def invert_dict(src_dic):
|
||
|
# type: (Dict) -> Dict
|
||
|
dic = dict()
|
||
|
|
||
|
for k, v in src_dic.items():
|
||
|
dic[v] = k
|
||
|
|
||
|
return dic
|
||
|
|
||
|
|
||
|
def enum_file_name_of(path):
|
||
|
# type: (str) -> Dict[int,str]
|
||
|
|
||
|
"""
|
||
|
This is kinda hacky, but it works :)
|
||
|
The enum file must contain a single enum however!
|
||
|
"""
|
||
|
|
||
|
path = path[0:-1] if path.endswith('.pyc') else path
|
||
|
pattern = re.compile(r"^\s*(\w+)\s*=\s*(\d+)", re.M)
|
||
|
with open(path, "r") as f:
|
||
|
return {
|
||
|
int(m[1]): m[0]
|
||
|
for m
|
||
|
in pattern.findall(f.read())
|
||
|
}
|