1 Star 0 Fork 2

17683250315/pabi-robot-stm32f4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
shellTools.py 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/python
# -*- coding:UTF-8 -*-
"""
shellTools
Author
Date
2020-04-14
Copyright
(c) Letter 2020
"""
import os
import sys
import re
FILE_PATTERN = r"^.*?\.(cpp|c|h)$"
SHELL_EXPORT_PATTERN = r"^\s*SHELL_EXPORT_(CMD|CMD_AGENCY|VAR|USER|KEY|KEY_AGENCY|CMD_GROUP|PASSTROUGH)\s*\(\s*\S+\s*,\s*(\S+)\s*,.*$"
def isCodeFile(name):
return re.match(FILE_PATTERN, name) != None
def getCodeFiles(path):
names = os.listdir(path)
files = []
for name in names:
fullName = os.path.join(path, name)
if os.path.isdir(fullName):
files = files + getCodeFiles(fullName)
else:
if re.match(FILE_PATTERN, name) != None:
files.append(fullName)
return files
def getFileEcoding(name):
encoding = ""
try:
with open(name, encoding="utf-8") as f:
f.read()
encoding = "utf-8"
except:
try:
with open(name, encoding="gbk") as f:
f.read()
encoding = "gbk"
except:
encoding = "ascii"
return encoding
if __name__ == "__main__":
path = sys.argv[1]
itemList = []
codeLine = ""
for codeFile in getCodeFiles(path):
try:
with open(codeFile, encoding=getFileEcoding(codeFile)) as f:
lineNum = 0
while True:
line = f.readline()
if line:
line = line.replace("\r", " ").replace("\n", " ")
codeLine = codeLine + line
lineNum = lineNum + 1
if ";" in codeLine or "}" in codeLine:
matcher = re.match(SHELL_EXPORT_PATTERN, codeLine)
if matcher != None:
item = (matcher.group(1), matcher.group(2), codeFile, lineNum)
itemList.append(item)
codeLine = ""
else:
codeLine = ""
break
except Exception as e:
print(e)
pass
for item in sorted(itemList, key=lambda x:(x[1])):
print("shell export %s, %s in file %s:%d"
%(item[0], item[1], item[2], item[3]))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/daoyi2-code/pabi-robot-stm32f4.git
[email protected]:daoyi2-code/pabi-robot-stm32f4.git
daoyi2-code
pabi-robot-stm32f4
pabi-robot-stm32f4
master

搜索帮助