itools 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 572fcb73d2ed042ab8d43f2ae359cc22c46f7b1a91c70aa53dcdadf424a65b3d
4
- data.tar.gz: 1fb8249f6f2d8934c7b7d04712b310d1465cbb1c253e8f950fe7be2efab9e628
3
+ metadata.gz: a7dcec9f2f9c1c5f46bed45dcd31d97b87c3b8b7d5e4cfbde50b54a173277b29
4
+ data.tar.gz: 93450e0c03b424cc94910354407c090063e538e8f6c202bce7e153baebabd35e
5
5
  SHA512:
6
- metadata.gz: 7d4bb2508282c6ec1b8ef24e3ac60fa80e648c16ddffb8bbe4a52f641801eb1178105139fcc10b8deee6c63966b4e965073b39f11e5fcdcc73d8e15c8539a30c
7
- data.tar.gz: 5ebe0bced44d8a2c33dee0f949ddc4ed4c86d2544585da1909d7ac1ec68566e385fb3280b408415b41ac4594553dc64e47af658b36da3d18611de7606b2f03a6
6
+ metadata.gz: 242950430add170c20e636ee10363b44117e94286f7e75f4593b9f10b2fbdea15c2189aa2c19c866fb7eb1ef91279dca8e3a946e70cf2e8ce18dff0476833e51
7
+ data.tar.gz: 0e42334a689c790919f9c4cd67a5040cfc3090602c35749fe76af930f3f016a7348f283596c12f4ad2717d0dff921ec809de46891b5d95adf3630446c09aa140
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- itools (0.1.3)
4
+ itools (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -20,7 +20,7 @@ DEPENDENCIES
20
20
  gli (~> 2.17)
21
21
  itools!
22
22
  rake (~> 10.0)
23
- spreadsheet (~> 1.1.8)
23
+ spreadsheet (~> 1.1, >= 1.1.8)
24
24
 
25
25
  BUNDLED WITH
26
26
  1.17.1
data/README.md CHANGED
@@ -1,25 +1,44 @@
1
1
  # itools
2
2
 
3
- a iOSer's tool.
3
+ 一个方便iOS开发的工具类。主要是使用Ruby编写,用于进行一些方便的处理,例如字符串查找,LinkMap解析等。
4
4
 
5
- ## Installation
5
+ ## 安装
6
6
 
7
7
 
8
8
  ```ruby
9
9
  gem install itools
10
10
  ```
11
11
 
12
- ## Usage
13
- ### First Step
14
- Open Xcode Write Link Map File Setting to YES for getting the Link Map File.
15
- ### Second Step
12
+ ## 使用
13
+ 安装之后再终端执行itools,结果如下:
14
+ ```shell
15
+ NAME
16
+ itools - a collection of tools for ios developer
17
+
18
+ SYNOPSIS
19
+ itools [global options] command [command options] [arguments...]
20
+
21
+ VERSION
22
+ 0.1.4
23
+
24
+ GLOBAL OPTIONS
25
+ --help - Show this message
26
+ --version - Display the program version
27
+
28
+ COMMANDS
29
+ help - Shows a list of commands or help for one command
30
+ parse - Analyze the memory footprint of each part or component in Xcode project
31
+ search - search str(or strs) in some file(or folder's file)
32
+ ```
33
+
34
+ ### 功能1:解析LinkMap
35
+ 命令:
16
36
  ```shell
17
- #link map file's name
18
37
  itools parse LinkMapDemo-LinkMap-normal-arm64.txt
19
38
  # or
20
39
  itools parse /user/Desk/LinkMapDemo-LinkMap-normal-arm64.txt
21
40
  ```
22
- The result is:
41
+ 解析结果实例:
23
42
  ```ruby
24
43
  AppDelegate.o 8.50KB
25
44
  ViewController.o 735B
@@ -32,6 +51,33 @@ UIKit.tbd 24B
32
51
  Total Size:10.07KB
33
52
  ```
34
53
  For more information, see:[https://www.cnblogs.com/zhanggui/p/9991455.html](https://www.cnblogs.com/zhanggui/p/9991455.html)
54
+
55
+ ### 功能2:字符串查找
56
+ 命令
57
+ ```ruby
58
+ itools search folder/file str/strs
59
+ ```
60
+ 例如:
61
+ 1.单字符查找:查找number.txt中包含7的行
62
+ ```ruby
63
+ itools search number.txt 7
64
+ ```
65
+ 将会把number.txt中包含7的行输出,内容包括:文件名(这里是number.txt)、包含字符串(这里是7)、文件所在目录、查找内容所在行、查找结果。
66
+ 2.多字符查找:查找number.txt中包含7,8的行
67
+ ```ruby
68
+ itools search number.txt 7,8
69
+ ```
70
+ 将会把number.txt中包含7、8的行记录到excel表中,表内容和上面的展示一样。
71
+ 3.在文件夹所有文件中查找某个字符串:
72
+ ```ruby
73
+ itools search /Users/zhanggui/zhanggui/my-dev MAYGO
74
+ ```
75
+ 将会把/Users/zhanggui/zhanggui/my-dev文件夹中所有的文件进行遍历,然后找到包含MAYGO字符串的类,并生成excel文件。
76
+ 4.在文件夹所有文件文件中查找某些字符串:
77
+ ```ruby
78
+ itools search /Users/zhanggui/zhanggui/Ruby/ 3434,Scott
79
+ ```
80
+ 将会在/Users/zhanggui/zhanggui/Ruby/中查找所有包含3434和Scott的文件,并生成excel。
35
81
  ## Contributing
36
82
 
37
83
  Bug reports and pull requests are welcome on GitHub at https://github.com/ScottZg/itools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
data/bin/itools CHANGED
@@ -22,4 +22,12 @@ command :search do |c|
22
22
  Itools::StringSearcher.search_result(args[0],args[1])
23
23
  end
24
24
  end
25
+ # 查找工程中没有用到的图片
26
+ desc "search unuse image"
27
+ arg 'xxx.txt'
28
+ command :find do |c|
29
+ c.action do |global_options, options, args|
30
+ Itools::ImgFinder.find(args[0])
31
+ end
32
+ end
25
33
  exit run(ARGV)
@@ -1,3 +1,4 @@
1
1
  require "itools/version"
2
2
  require "itools/link_map"
3
3
  require "itools/string_searcher"
4
+ require "itools/find_unuse_img"
@@ -0,0 +1,105 @@
1
+ require 'find'
2
+ require 'spreadsheet'
3
+ module Itools
4
+ class ImgFinder
5
+ attr_accessor :image_count, :image_names, :unuse_images,:find_path
6
+ attr_accessor :search_files
7
+ def initialize
8
+ @image_count = 0
9
+ @image_names = []
10
+ @search_files = []
11
+ end
12
+ # 得到所有图片名称字符
13
+ def get_img_name_strs
14
+ result_arr = []
15
+ @image_names.each {|item|
16
+ item_name = Image.get_image_name(File.basename(item, ".*"))
17
+ result_arr << item_name
18
+ }
19
+ return result_arr
20
+ end
21
+ # 查找
22
+ def self.find(temp_find_dir)
23
+ imgFinder = ImgFinder.new
24
+ imgFinder.find_path = temp_find_dir
25
+ # 第一步:找到该文件夹下所有的图片文件
26
+ Find.find(temp_find_dir) do |filename|
27
+ if File.file?(filename) #如果是文件,则从文件中查找,忽略文件夹
28
+ if Image.is_image_format(File.extname(filename))
29
+ # p File.basename(filename)
30
+ # exit
31
+ imgFinder.image_count = imgFinder.image_count + 1
32
+ imgFinder.image_names << filename
33
+ elsif File.extname(filename).eql?(".m")
34
+ imgFinder.search_files << filename
35
+ end
36
+ end
37
+ end
38
+ if imgFinder.image_names.size == 0
39
+ puts "\033[32m查找成功,未发现图片\033[0m"
40
+ return
41
+ else
42
+ puts "\033[32m查找成功,共发现图片#{imgFinder.image_names.size}张\033[0m"
43
+ end
44
+ # 第二步:找到图片是否使用
45
+ imags = imgFinder.get_img_name_strs.uniq #要查找的图片名称数组
46
+
47
+ puts "\033[32m需要查找的图片有#{imags.size}张\033[0m"
48
+ # imgFinder.search_files #要查找的文件
49
+ imgFinder.search_files.each {|file|
50
+ File.read(file).each_line do |line|
51
+ haveStr = StringHandle.containsStr(line,imags)
52
+ if haveStr != -1
53
+ puts "#{imags[haveStr]}在使用...,剩余查找项#{imags.size-1}个"
54
+ imags.delete_at(haveStr)
55
+ end
56
+ end
57
+ }
58
+ puts "\033[32m无用图片#{imags.size}张,图片名称如下:\033[0m"
59
+ Spreadsheet.client_encoding = 'utf-8'
60
+ book = Spreadsheet::Workbook.new
61
+ sheet1 = book.create_worksheet
62
+ sheet1.row(0)[0] = "文件名"
63
+ imags.each_with_index {|item,idx|
64
+ sheet1.row(idx+1)[0] = item
65
+ puts item
66
+ }
67
+ book.write "#{imgFinder.find_path}/search_result.xls"
68
+ puts "\033[32m文件已经保存到#{imgFinder.find_path}/search_result.xls\033[0m"
69
+ puts "\033[32m内容仅供参考,具体还要自己通过结果查看一下\033[0m"
70
+ end
71
+ end
72
+ # 字符串操作类
73
+ class StringHandle
74
+ # originStr中是否包含targetStrs中的内容
75
+ def self.containsStr(originStr,targetStrs)
76
+ targetStrs.each_with_index {|item,idx|
77
+ if originStr.include?(item)
78
+ return idx
79
+ end
80
+ }
81
+ return -1
82
+ end
83
+ end
84
+ class Image
85
+
86
+ # 是否是图片格式,这里只判断了jpg、png和gif
87
+ def self.is_image_format(temp_ext_name)
88
+ if ['.jpg','.png','.gif'].include?(temp_ext_name)
89
+ return true
90
+ else
91
+ return false
92
+ end
93
+ end
94
+ def self.get_image_name(file)
95
+ return file.gsub(/@2x|@3x/,"")
96
+ end
97
+ end
98
+ # class ObjectiveC
99
+ # def self.is_h_file(temp_ext_name)
100
+ # if ['.h']
101
+
102
+ # end
103
+ # end
104
+ # end
105
+ end
@@ -0,0 +1,129 @@
1
+ require 'find'
2
+ require 'spreadsheet'
3
+ module Itools
4
+ # 字符串操作类
5
+ class StringHandle
6
+ # originStr中是否包含targetStrs中的内容
7
+ def self.containsStr(originStr,targetStrs)
8
+ targetStrs.each_with_index {|item,idx|
9
+ if originStr.include?(item)
10
+ return idx
11
+ end
12
+ }
13
+ return -1
14
+ end
15
+ end
16
+ # 搜索结果类
17
+ class SearchResult
18
+ attr_accessor :file_name, :in_line, :result_str, :key_str
19
+
20
+ def initialize(tempName,tempInLine,tempResultStr,tempKeyStr)
21
+ @file_name = tempName
22
+ @in_line = tempInLine
23
+ @result_str = tempResultStr
24
+ @key_str = tempKeyStr
25
+ end
26
+ end
27
+
28
+ # Main class
29
+ class StringSearcher
30
+ attr_accessor :search_strs, :search_in, :result
31
+ def initialize(temp_SearchStrs,temp_SearchIn)
32
+ @search_strs = temp_SearchStrs
33
+ @search_in = temp_SearchIn
34
+ @result = []
35
+ end
36
+ # 第二步开始搜索
37
+ def search
38
+ if check_exist
39
+ handle_method = ''
40
+ if File.file?(@search_in) #如果是文件
41
+ handle_method = "search_in_file"
42
+ else
43
+ handle_method = "search_in_folder"
44
+ end
45
+ self.send(handle_method,@search_in)
46
+ else
47
+ puts "\033[31m文件不存在,请检查输入是否正确\033[0m"
48
+ exit
49
+ end
50
+ end
51
+ # 从文件查找
52
+ def search_in_file(temp_file)
53
+ line_index = 1
54
+ File.read(temp_file).each_line do |line|
55
+ haveIndex = StringHandle.containsStr(line,@search_strs)
56
+ if haveIndex != -1
57
+ search_result = SearchResult.new(temp_file,line_index,line,@search_strs[haveIndex])
58
+ @result << search_result
59
+ end
60
+ line_index = line_index + 1
61
+ end
62
+ end
63
+
64
+ # 从文件夹查找
65
+ def search_in_folder(unuse)
66
+ puts @search_in_folder
67
+ Find.find(@search_in) do |filename|
68
+ if File.file?(filename) #如果是文件,则从文件中查找,忽略文件夹
69
+ search_in_file(filename)
70
+ end
71
+ end
72
+ end
73
+ # 第一步:检查是否存在
74
+ def check_exist
75
+ if File.file?(@search_in)
76
+ puts "\033[32m从文件中查找\033[0m"
77
+ return true
78
+ elsif File::directory?(@search_in)
79
+ puts "\033[32m从文件夹中查找\033[0m"
80
+ return true
81
+ else
82
+ return false
83
+ end
84
+ end
85
+ # 第一个参数为要搜索的文件或者文件夹名称
86
+ # 第二个参数为要搜索的字符串
87
+ def self.search_result(temp_search_in,temp_search_strs)
88
+ if temp_search_in.nil?
89
+ puts "\033[31m传入的参数有误,第一个参数为要搜索的文件或者文件夹名称,第二个参数为要搜索的字符串(如要查找多个str使用英文,分割),两个参数中间用空格区分\033[0m"
90
+ exit
91
+ end
92
+ if temp_search_strs.nil?
93
+ puts "\033[31m传入的参数有误,第一个参数为要搜索的文件或者文件夹名称,第二个参数为要搜索的字符串(如要查找多个str使用英文,分割),两个参数中间用空格区分\033[0m"
94
+ exit
95
+ end
96
+ # 传入的可能是字符串数组
97
+ searcher = StringSearcher.new(temp_search_strs.split(","),temp_search_in)
98
+ searcher.search
99
+ if searcher.result.size == 0
100
+ puts "\033[32m没有找到相关字段\033[0m"
101
+ exit
102
+ end
103
+ # 输出搜索的内容
104
+ Spreadsheet.client_encoding = 'utf-8'
105
+ book = Spreadsheet::Workbook.new
106
+ sheet1 = book.create_worksheet
107
+ sheet1.row(0)[0] = "文件名"
108
+ sheet1.row(0)[1] = "包含字符串"
109
+ sheet1.row(0)[2] = "文件所在目录"
110
+ sheet1.row(0)[3] = "查找内容所在行"
111
+ sheet1.row(0)[4] = "查找结果Str"
112
+
113
+ searcher.result.each_with_index do |item,i|
114
+ sheet1.row(i+1)[0] = File.basename(item.file_name)
115
+ sheet1.row(i+1)[1] = item.key_str
116
+ sheet1.row(i+1)[2] = File.dirname(item.file_name)
117
+ sheet1.row(i+1)[3] = item.in_line
118
+ sheet1.row(i+1)[4] = item.result_str
119
+ if i < 10
120
+ puts "#{item.key_str} is in file:#{File.basename(item.file_name)} and Inline:#{item.in_line}"
121
+ end
122
+
123
+ end
124
+
125
+ puts "\033[32m查找成功,内容已经保存到#{File.dirname(searcher.search_in)},请点击查看\033[0m"
126
+ book.write "#{File.dirname(searcher.search_in)}/search_result.xls"
127
+ end
128
+ end
129
+ end
@@ -1,3 +1,3 @@
1
1
  module Itools
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhanggui
@@ -92,7 +92,9 @@ files:
92
92
  - bin/itools
93
93
  - itools.gemspec
94
94
  - lib/itools.rb
95
+ - lib/itools/find_unuse_img.rb
95
96
  - lib/itools/link_map.rb
97
+ - lib/itools/string_searcher.rb
96
98
  - lib/itools/version.rb
97
99
  homepage: https://github.com/ScottZg/itools
98
100
  licenses: