itools 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b172c6cbab9604e72a36f7303bf8eec0353afb84abf887b8f65e38610885bc5
4
- data.tar.gz: d40afd6ca2603f7a2434ebf73aa84ca9b23212e4bdcd4e2e2a09b9703818e1b7
3
+ metadata.gz: 76d7b8118a74915adfe2228663db77773c494dc647144b956062fd36efa3cf2a
4
+ data.tar.gz: 51179c6ca8adb383f1c1dad65ebf2188a25a8b493d1b2ec93e027d19b342974d
5
5
  SHA512:
6
- metadata.gz: 8286419537fc6bb35c6704bc011e49cf623e98a0db362b45b5c0ef3c7d61bcf0057f358e023c731a99d1870f7b806f9361515d5f2b17ce43af6b9a7fa3c29a89
7
- data.tar.gz: 70e1d369dd7c8c600b29ab52ddafd0649d002979fc82f717ed5b8574feaac6f65d67892b516557104be86cf3f70a0705363e9b3eb101b910d938697f2be7e8db
6
+ metadata.gz: 30572c05c6ee47d62400a11d042ecaaef4dc691f718ec6c117fa66cd1bfd3e49a22867f9645569726f6fe1c5fd03676b9a6c2126241f8d3c54f1376ae73d2bc4
7
+ data.tar.gz: d28beada88df4e847278dcf6e5b53c5ab04f79796483f48e9912f05f2adc652bbcdedd36d88a511f7006e8c0ab4d0ec55db104af7e9af8bfb3c7825b80b77699
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- itools (0.2.5)
4
+ itools (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -19,17 +19,19 @@ SYNOPSIS
19
19
  itools [global options] command [command options] [arguments...]
20
20
 
21
21
  VERSION
22
- 0.1.5
22
+ 0.2.5
23
23
 
24
24
  GLOBAL OPTIONS
25
25
  --help - Show this message
26
26
  --version - Display the program version
27
27
 
28
28
  COMMANDS
29
- find - search unuse image
30
- help - Shows a list of commands or help for one command
31
- parse - Analyze the memory footprint of each part or component in Xcode project
32
- search - search str(or strs) in some file(or folder's file)
29
+ find - search unuse image
30
+ help - Shows a list of commands or help for one command
31
+ parse - Analyze the memory footprint of each part or component in Xcode project
32
+ search - search str(or strs) in some file(or folder's file)
33
+ searchFile - search File in folder
34
+ sizeFor - calculate the memory footprint of file or folder(contain file)
33
35
  ```
34
36
 
35
37
  ### 功能1:解析LinkMap
@@ -98,6 +100,14 @@ or
98
100
  ```
99
101
  计算sizeFor后面跟的参数内容所占内存大小,如果参数为文件路径,则计算文件大小,如果是文件夹,会遍历所有文件,然后计算大小。第二个参数为计算系数(这个系数为1MB = 1024KB中的1024;windows为1024,mac为1000,不传默认为1024)。
100
102
  在中途会提示你输入要查找的文件后缀,不输入任何则表示查找文件夹下的所有文件,输入后缀则会计算特定文件类型包含的大小,例如:png,jpg,gif,这样会计算出文件夹中三种类型格式的图片所占有内存的大小。
103
+
104
+ ### 功能5:查找文件
105
+ 命令
106
+ ```
107
+ itools searchFile /Users/zhanggui/zhanggui/my-dev/search_vc ViewController.m #第二个参数现在只支持单字符串查找
108
+ ```
109
+ 查找/Users/zhanggui/zhanggui/my-dev/search_vc文件夹下所有的文件名包含ViewController.m的文件,并且输出到excel表格
110
+
101
111
  ## Contributing
102
112
 
103
113
  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
@@ -30,6 +30,15 @@ command :find do |c|
30
30
  Itools::ImgFinder.find(args[0])
31
31
  end
32
32
  end
33
+ # 查找Xcode工程中没有用到的类
34
+ desc "search unuse class"
35
+ arg 'xxx.txt'
36
+ command :search_unuse_class do |c|
37
+ c.action do |global_options, options, args|
38
+ Itools::ClassFinder.search_unuse_class(args)
39
+ end
40
+ end
41
+
33
42
  # 计算占用内存大小
34
43
  desc "calculate the memory footprint of file or folder(contain file)"
35
44
  arg 'xxx.txt'
@@ -3,4 +3,5 @@ require "itools/link_map"
3
3
  require "itools/string_searcher"
4
4
  require "itools/find_unuse_img"
5
5
  require "itools/get_size"
6
- require "itools/file_handle"
6
+ require "itools/file_handle"
7
+ require "itools/class_unuse_finder"
@@ -0,0 +1,126 @@
1
+ require 'find'
2
+ module Itools
3
+ class ClassFinder
4
+ attr_accessor :search_path, :classes, :search_in_files
5
+ def initialize(temp_search_path)
6
+ @search_path = temp_search_path
7
+ @classes = []
8
+ @search_in_files = []
9
+ end
10
+ def search
11
+ # 找到所有的.h以及所有要查找的文件
12
+ Find.find(@search_path) do |path|
13
+ if File.file?(path)
14
+ if !get_not_contain_file_ext.include?(File.extname(path))
15
+ @search_in_files << path
16
+ end
17
+
18
+ if File.extname(path).eql?(".h")
19
+ ff_result = FindResult.new(File.basename(path,".h"),path)
20
+ @classes << ff_result
21
+ end
22
+ end
23
+ end
24
+
25
+ # 删除使用的文件
26
+ use_idxs = Set.new
27
+ @search_in_files.each{|s_file|
28
+ s_containet = ""
29
+ File.read(s_file).each_line do |line|
30
+ s_containet << line
31
+ s_containet << ","
32
+ end
33
+ # 查找所有文件在单个文件中是否被引用
34
+ @classes.each_with_index{|f_result,idx|
35
+ search_file_no_ext = get_no_ext_path(s_file)
36
+ check_file_no_ext = get_no_ext_path(f_result.fr_path)
37
+ # 判断是否是同一个文件或者是通文件的.m/.h,不是同一个文件才查找
38
+ if !check_file_no_ext.eql?(search_file_no_ext)
39
+ inheritance_str = ": #{f_result.fr_name}"
40
+ contain_str = '@"' + f_result.fr_name + '"'
41
+ reference_str = "#{f_result.fr_name}.h"
42
+ if s_containet.include?(inheritance_str) or s_containet.include?(contain_str) or s_containet.include?(reference_str)
43
+ use_idxs << f_result
44
+ puts "#{f_result.fr_name}已使用,剩余查找文件数#{@classes.size - use_idxs.size}..."
45
+ end
46
+ end
47
+ }
48
+
49
+ }
50
+ final_result = []
51
+
52
+ temp_final_result_str = ''
53
+ use_idxs.to_a.each {|u_x|
54
+ temp_final_result_str << u_x.fr_name
55
+ temp_final_result_str << ","
56
+ }
57
+ @classes.delete_if {|find_result| temp_final_result_str.include?(find_result.fr_name) }
58
+ puts "\033[32m查找结束,共同无用文件#{@classes.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
+ sheet1.row(0)[1] = "文件名"
64
+ sheet1.row(0)[2] = "文件路径"
65
+ total_size = 0
66
+ @classes.each_with_index{|r_item,f_index|
67
+ # if !r_item.fr_name.include?("+")
68
+ total_size = total_size + File.size(r_item.fr_path)
69
+ # end
70
+ puts r_item.fr_name
71
+ sheet1.row(f_index+1)[0] = f_index + 1
72
+ sheet1.row(f_index+1)[1] = r_item.fr_name
73
+ sheet1.row(f_index+1)[2] = r_item.fr_path
74
+ sheet1.row(f_index+1).height = 20
75
+ }
76
+ sheet1.column(0).width = 4
77
+ sheet1.column(1).width = 45
78
+ sheet1.column(2).width = 100
79
+ book.write "#{@search_path}/search_unuseclass_result.xls"
80
+ puts "\033[32m文件已经保存到#{@search_path}/search_unuseclass_result.xls,无用文件#{@classes.size}个,预计可减少内存占用#{handleSize(total_size)}\033[0m"
81
+ end
82
+ # 大小格式化
83
+ def handleSize(size)
84
+ if size > 1024 * 1024
85
+ return format("%.2f",(size.to_f/(1024*1024))) + "MB"
86
+ elsif size > 1024
87
+ return format("%.2f",(size.to_f/1024)) + "KB"
88
+ else
89
+ return size.to_s + "B"
90
+ end
91
+ end
92
+ # 不包含后缀的路径
93
+ def get_no_ext_path(item)
94
+ return File.dirname(item) + "/" + File.basename(item,".*")
95
+ end
96
+ # 不需要查找的类
97
+ def get_not_contain_file_ext
98
+ nc_ext = [".jpg",".png",".md",".xls",".xcworkspace",".DS_Store",""]
99
+ return nc_ext
100
+ end
101
+ # 对外暴露
102
+ def self.search_unuse_class(args)
103
+ folder_path = args[0]
104
+ if folder_path.nil?
105
+ puts "\033[31m传入的参数不能为空\033[0m"
106
+ return
107
+ end
108
+ if !File::directory?(folder_path)
109
+ puts "\033[31m参数不是文件夹\033[0m"
110
+ return
111
+ end
112
+ class_finder = ClassFinder.new(folder_path)
113
+ class_finder.search
114
+ end
115
+ end
116
+
117
+ # ------------------------查找结果类------------------------
118
+
119
+ class FindResult
120
+ attr_accessor :fr_name, :fr_path
121
+ def initialize(temp_name,temp_path)
122
+ @fr_name = temp_name
123
+ @fr_path = temp_path
124
+ end
125
+ end
126
+ end
@@ -1,3 +1,3 @@
1
1
  module Itools
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhanggui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-13 00:00:00.000000000 Z
11
+ date: 2018-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ files:
92
92
  - bin/itools
93
93
  - itools.gemspec
94
94
  - lib/itools.rb
95
+ - lib/itools/class_unuse_finder.rb
95
96
  - lib/itools/file_handle.rb
96
97
  - lib/itools/find_unuse_img.rb
97
98
  - lib/itools/get_size.rb