-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utils.py
35 lines (33 loc) · 1.07 KB
/
Utils.py
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
# -*- coding: utf-8 -*-
"""
工具函数
"""
import os
import shutil
import json
import re
from collections import OrderedDict
# 从节点标签中获取函数实体
def getEntity(nodeLabel):
entity = ""
pattern = re.compile("{<(.*?): (.*?) (.*?)\((.*?)\)>(.*)}")
matcher = pattern.match(nodeLabel)
if matcher:
packageName = matcher.group(1)
methodName = matcher.group(3)
entity = packageName + ": " + methodName
return entity
# 从json文件中恢复有序字典
def getOrderedDictFromJsonFile(jsonFilePath):
with open(jsonFilePath, "r") as jsonFile:
OrderedDictFromJsonFile = json.load(jsonFile, object_pairs_hook=OrderedDict)
return OrderedDictFromJsonFile
# 清理文件夹,只保留列表中的内容
def cleanDir(dirPath, remainList=[]):
for fileName in os.listdir(dirPath):
if fileName not in remainList:
filePath = os.path.join(dirPath, fileName)
if os.path.isfile(filePath):
os.unlink(filePath)
if os.path.isdir(filePath):
shutil.rmtree(filePath)