From a19359d95b4138e9cee70dbe69406fbea24efa9a Mon Sep 17 00:00:00 2001 From: iyue Date: Thu, 14 Mar 2024 19:12:03 +0800 Subject: [PATCH] perf(py): :children_crossing: Code Optimization --- .gitignore | 1 + .idea/.gitignore | 8 -------- .idea/inspectionProfiles/Project_Default.xml | 7 ------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/sosearch.iml | 8 -------- .idea/vcs.xml | 6 ------ README.md | 5 ++++- build.sh | 5 +++-- main.py | 14 +++++++++----- 11 files changed, 17 insertions(+), 55 deletions(-) create mode 100644 .gitignore delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/sosearch.iml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index cce1d86..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index dc9ea49..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index d8f1278..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/sosearch.iml b/.idea/sosearch.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/sosearch.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index c415822..1582e1f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,10 @@ options: 参数 保存到文件 ``` # 编译命令 +- `~/.bin` 为PATH路径 可自行修改 +```shell rm -rf out build *.log searchso.spec pyinstaller -F -w ./main.py --distpath=out -n sosearch cp ./sosearch ~/.bin -sudo chmod a+x ~/.bin/sosearch \ No newline at end of file +sudo chmod a+x ~/.bin/sosearch +``` \ No newline at end of file diff --git a/build.sh b/build.sh index 81a8ad4..bfcf1e4 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ -rm -rf out build *.log searchso.spec -pyinstaller -F -w ./main.py --distpath=out -n sosearch +mkdir build || cd build +rm -rf out searchso.spec +pyinstaller -F -w ./../main.py --distpath=out -n sosearch cp ./out/sosearch ~/.bin sudo chmod a+x ~/.bin/sosearch \ No newline at end of file diff --git a/main.py b/main.py index f444a1b..d5ca5ab 100644 --- a/main.py +++ b/main.py @@ -19,8 +19,8 @@ def searchso(sopath, s): arrayStr = [] result = None if out is not None: - print("> {}:开始分析!".format(os.path.split(sopath)[1])) - print("> commad: strings -a {} | grep {}".format(sopath, s)) + # print("> {}:开始分析!".format(os.path.split(sopath)[1])) + # print("> commad: strings -a {} | grep {}".format(sopath, s)) result = out.decode('utf-8') if args.saveall is not None and result is not None: with open(args.saveall, 'a') as f: @@ -30,19 +30,23 @@ def searchso(sopath, s): f.close() try: if args.ignorecase == 1: - print("> -i 1 默认忽略大小写") + # print("> -i 1 默认忽略大小写") items = re.finditer(s, result, re.IGNORECASE) else: items = re.finditer(s, result) - print("> -i 0 区分大小写") + # print("> -i 0 区分大小写") + isfind = False for i in items: + isfind = True arg = result[i.start():-1] print(arg[:arg.find('\n')]) if args.output: arrayStr.append(arg[:arg.find('\n')]) + if isfind == True: + print('search {} found'.format(os.path.split(sopath)[1])) except Exception as e: print(e) - print("> {}:分析完成!".format(os.path.split(sopath)[1])) + # print("> {}:分析完成!".format(os.path.split(sopath)[1])) if args.output is not None and len(arrayStr): with open(args.output, 'a') as f: f.write('<====' + os.path.split(sopath)[1] + "====\n")