mdq 0.2.0 → 0.3.0

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: 8a9f4ec5652eddd07350b8957261163db13ce51c1d36c7e7e109c8eb0836dc0a
4
- data.tar.gz: 9bfbf94ee8f84849beb7a719b3170dc4b989dc1b988cb1b4b6b2dba0bab41ea2
3
+ metadata.gz: 11207ffa243aa9925a945ecf3e989f3ef136a36d3ef3d574e32372528097e09f
4
+ data.tar.gz: 642365689def13a8c56769d3f070954b123f3c6ebf7ca23f2a781415a1a44f5d
5
5
  SHA512:
6
- metadata.gz: a26e2f9fdb44629c5e478845bc227fe2efe7354b1e1e01f84214e9b2c36fe6edaea6d95e17c25a333ecad911bb203e5321192ffd5a3ebd9d66da283413a70608
7
- data.tar.gz: b936990fa4c104841742c5cc1bb11c791e7c96b98585ffe29cb08dc42729eece6aaa06c8ca935545e7e5ad67d3d3c933673c1ea7f3e92f49097f20b75d6c68dc
6
+ metadata.gz: 9b8812fd72184096df44cec5361a071e7b3c6f0175768efb32ecd9e1149e9d73d9d334c82ea83764fab67415a7680c854ec97d9f31508649c7265a3db62b2358
7
+ data.tar.gz: 74ff17f9a43ff731d42fff94055c718ce85408e1dc641d5d70bed51e4fff6cd8be3dcd39ddca65fed082ed8e2bda7e018c0a750bbff3009eb80aba79f2922a3f
data/.rubocop_todo.yml CHANGED
@@ -9,18 +9,18 @@
9
9
  # Offense count: 2
10
10
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 38
12
+ Max: 50
13
13
 
14
14
  # Offense count: 1
15
15
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
16
16
  # AllowedMethods: refine
17
17
  Metrics/BlockLength:
18
- Max: 46
18
+ Max: 70
19
19
 
20
20
  # Offense count: 1
21
21
  # Configuration parameters: CountComments, CountAsOne.
22
22
  Metrics/ClassLength:
23
- Max: 160
23
+ Max: 180
24
24
 
25
25
  # Offense count: 1
26
26
  # Configuration parameters: AllowedMethods, AllowedPatterns.
data/README.base.md CHANGED
@@ -83,6 +83,34 @@ $ mdq list -q="select * from devices where platform='iOS'"
83
83
  ]
84
84
  ```
85
85
 
86
+ View apps installed on your device.
87
+ Apple Devices displays the apps installed with Xcode.
88
+
89
+ ```
90
+ $ mdq list -q='select * from apps'
91
+ ```
92
+
93
+ Take a screenshot on Android.
94
+
95
+ ```
96
+ $ mdq list --cap='/Users/xxxxx/'
97
+ ```
98
+
99
+ Install the app.
100
+
101
+ ```
102
+ $ mdq list --install='/Users/xxxxx/example.apk'
103
+ $ mdq list --install='/Users/xxxxx/example.ipa'
104
+ ```
105
+
106
+ Uninstall the app.
107
+
108
+ ```
109
+ $ mdq list --uninstall='com.example.app'
110
+ ```
111
+
112
+
113
+
86
114
  # Specification
87
115
 
88
116
  Details of the devices table.
@@ -100,4 +128,15 @@ Details of the devices table.
100
128
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
101
129
  | battery_level | battery | Always "null" |
102
130
  | total_capacity | df | Always "null" |
103
- | free_capacity | df | Always "null" |
131
+ | free_capacity | df | Always "null" |
132
+
133
+
134
+ Details of the apps table.
135
+ Apple Devices displays the apps installed with Xcode.
136
+
137
+ | name | android | apple devices |
138
+ | -- | -- | -- |
139
+ | udid | Serial number | hardwareProperties.udid |
140
+ | name | Always "null" | name |
141
+ | package_name | Package name | bundleIdentifier |
142
+ | version | Always "null" | version |
data/README.ja.md CHANGED
@@ -78,6 +78,34 @@ $ mdq list -q="select * from devices where platform='iOS'"
78
78
  ]
79
79
  ```
80
80
 
81
+ View apps installed on your device.
82
+ Apple Devices displays the apps installed with Xcode.
83
+
84
+ ```
85
+ $ mdq list -q='select * from apps'
86
+ ```
87
+
88
+ Take a screenshot on Android.
89
+
90
+ ```
91
+ $ mdq list --cap='/Users/xxxxx/'
92
+ ```
93
+
94
+ Install the app.
95
+
96
+ ```
97
+ $ mdq list --install='/Users/xxxxx/example.apk'
98
+ $ mdq list --install='/Users/xxxxx/example.ipa'
99
+ ```
100
+
101
+ Uninstall the app.
102
+
103
+ ```
104
+ $ mdq list --uninstall='com.example.app'
105
+ ```
106
+
107
+
108
+
81
109
  # Specification
82
110
 
83
111
  Details of the devices table.
@@ -95,4 +123,15 @@ Details of the devices table.
95
123
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
96
124
  | battery_level | battery | Always "null" |
97
125
  | total_capacity | df | Always "null" |
98
- | free_capacity | df | Always "null" |
126
+ | free_capacity | df | Always "null" |
127
+
128
+
129
+ Details of the apps table.
130
+ Apple Devices displays the apps installed with Xcode.
131
+
132
+ | name | android | apple devices |
133
+ | -- | -- | -- |
134
+ | udid | Serial number | hardwareProperties.udid |
135
+ | name | Always "null" | name |
136
+ | package_name | Package name | bundleIdentifier |
137
+ | version | Always "null" | version |
data/README.md CHANGED
@@ -78,6 +78,34 @@ $ mdq list -q="select * from devices where platform='iOS'"
78
78
  ]
79
79
  ```
80
80
 
81
+ View apps installed on your device.
82
+ Apple Devices displays the apps installed with Xcode.
83
+
84
+ ```
85
+ $ mdq list -q='select * from apps'
86
+ ```
87
+
88
+ Take a screenshot on Android.
89
+
90
+ ```
91
+ $ mdq list --cap='/Users/xxxxx/'
92
+ ```
93
+
94
+ Install the app.
95
+
96
+ ```
97
+ $ mdq list --install='/Users/xxxxx/example.apk'
98
+ $ mdq list --install='/Users/xxxxx/example.ipa'
99
+ ```
100
+
101
+ Uninstall the app.
102
+
103
+ ```
104
+ $ mdq list --uninstall='com.example.app'
105
+ ```
106
+
107
+
108
+
81
109
  # Specification
82
110
 
83
111
  Details of the devices table.
@@ -95,4 +123,15 @@ Details of the devices table.
95
123
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
96
124
  | battery_level | battery | Always "null" |
97
125
  | total_capacity | df | Always "null" |
98
- | free_capacity | df | Always "null" |
126
+ | free_capacity | df | Always "null" |
127
+
128
+
129
+ Details of the apps table.
130
+ Apple Devices displays the apps installed with Xcode.
131
+
132
+ | name | android | apple devices |
133
+ | -- | -- | -- |
134
+ | udid | Serial number | hardwareProperties.udid |
135
+ | name | Always "null" | name |
136
+ | package_name | Package name | bundleIdentifier |
137
+ | version | Always "null" | version |
data/lib/mdq/check.rb CHANGED
@@ -7,9 +7,9 @@ module Mdq
7
7
  # Check
8
8
  class Check
9
9
  def initialize
10
- ddb = Mdq::DDB.new
11
- ddb.show_version('adb', 'adb version')
12
- ddb.show_version('Xcode', 'xcrun devicectl --version')
10
+ db = Mdq::DB.new
11
+ db.show_version('adb', 'adb version')
12
+ db.show_version('Xcode', 'xcrun devicectl --version')
13
13
  end
14
14
  end
15
15
  end
data/lib/mdq/db.rb ADDED
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mdq'
4
+ require 'active_record'
5
+ require 'fileutils'
6
+
7
+ # Mdq
8
+ module Mdq
9
+ # DB
10
+ class DB < Discovery
11
+ # クエリの実行
12
+ def get(sql)
13
+ InitialSchema.migrate(:reset)
14
+
15
+ # デバイスの発見
16
+ android_discover
17
+ apple_discover
18
+
19
+ if sql
20
+ Device.all.each do |model|
21
+ # インストール済みAppの取得
22
+ if model.android?
23
+ android_apps(model.udid)
24
+ else
25
+ apple_apps(model.udid)
26
+ end
27
+ end
28
+
29
+ begin
30
+ ActiveRecord::Base.connection.execute(sql)
31
+ rescue StandardError
32
+ warn 'SQL Syntax Error.'
33
+ exit
34
+ end
35
+ else
36
+ Device.all
37
+ end
38
+ end
39
+
40
+ # 指定したソフトウェアのインストール状況を表示する
41
+ def show_version(name, command)
42
+ output, = Open3.capture3(command)
43
+ puts "# #{name} installed."
44
+ puts output
45
+ rescue StandardError
46
+ puts "# #{name} is not installed."
47
+ end
48
+
49
+ # Androidデバイスのスクリーンショットを撮る
50
+ def device_screencap(output, udid, is_android)
51
+ return unless is_android
52
+
53
+ FileUtils.mkdir_p(output)
54
+ file = "/sdcard/#{udid}.png"
55
+ adb_command("shell screencap -p #{file}", udid)
56
+ adb_command("pull #{file} #{output}", udid)
57
+ adb_command("adb shell rm #{file}")
58
+
59
+ puts "# Screenshot of #{udid} to #{output}"
60
+ end
61
+
62
+ # Appをインストールする
63
+ def app_install(input, udid, is_android)
64
+ output, = adb_command("install #{input}", udid) if is_android && input.end_with?('.apk')
65
+ output, = apple_command("device install app #{input}", udid) if !is_android && input.end_with?('.ipa')
66
+
67
+ return unless output
68
+
69
+ puts "# Install #{input} to #{udid}"
70
+ puts output
71
+ end
72
+
73
+ # Appをアンインストールする
74
+ def app_uninstall(input, udid, is_android)
75
+ if is_android
76
+ output, = adb_command("uninstall #{input}", udid)
77
+ else
78
+ output, = apple_command("device uninstall app #{input}", udid)
79
+ end
80
+
81
+ return unless output
82
+
83
+ puts "# Uninstall #{input} from #{udid}"
84
+ puts output
85
+ end
86
+ end
87
+ end
@@ -6,73 +6,11 @@ require 'fileutils'
6
6
 
7
7
  # Mdq
8
8
  module Mdq
9
- # DDB
10
- class DDB
11
- def initializ; end
12
-
13
- # 接続中のデバイスを取得する
14
- def get(sql)
9
+ # Discovery
10
+ class Discovery
11
+ def initialize
15
12
  ActiveRecord::Schema.verbose = false
16
13
  InitialSchema.migrate(:up)
17
-
18
- android_discover
19
- apple_discover
20
-
21
- if sql
22
- begin
23
- ActiveRecord::Base.connection.execute(sql)
24
- rescue StandardError
25
- warn 'SQL Syntax Error.'
26
- exit
27
- end
28
- else
29
- Device.all
30
- end
31
- end
32
-
33
- # 指定したソフトウェアのインストール状況を表示する
34
- def show_version(name, command)
35
- output, = Open3.capture3(command)
36
- puts "# #{name} installed."
37
- puts output
38
- rescue StandardError
39
- puts "# #{name} is not installed."
40
- end
41
-
42
- # Androidデバイスのスクリーンショットを撮る
43
- def device_screencap(output, udid, is_android)
44
- return unless is_android
45
-
46
- FileUtils.mkdir_p(output)
47
- file = "/sdcard/#{udid}.png"
48
- adb_command("shell screencap -p #{file}", udid)
49
- adb_command("pull #{file} #{output}", udid)
50
- adb_command("adb shell rm #{file}")
51
-
52
- puts "# Screenshot of #{udid} to #{output}"
53
- end
54
-
55
- def app_install(input, udid, is_android)
56
- output, = adb_command("install #{input}", udid) if is_android && input.end_with?('.apk')
57
- output, = apple_command("device install app #{input}", udid) if !is_android && input.end_with?('.ipa')
58
-
59
- return unless output
60
-
61
- puts "# Install #{input} to #{udid}"
62
- puts output
63
- end
64
-
65
- def app_uninstall(input, udid, is_android)
66
- if is_android
67
- output, = adb_command("uninstall #{input}", udid)
68
- else
69
- output, = apple_command("device uninstall app #{input}", udid)
70
- end
71
-
72
- return unless output
73
-
74
- puts "# Uninstall #{input} from #{udid}"
75
- puts output
76
14
  end
77
15
 
78
16
  private
@@ -108,7 +46,7 @@ module Mdq
108
46
  end
109
47
 
110
48
  # Androidデバイス一覧を取得する
111
- def android_discover # rubocop:disable Metrics/AbcSize
49
+ def android_discover
112
50
  output, = adb_command('devices -l')
113
51
  return if output.nil?
114
52
 
@@ -160,6 +98,7 @@ module Mdq
160
98
  free_capacity: free_capacity,
161
99
  platform: 'Android'
162
100
  })
101
+
163
102
  else
164
103
  Device.create({
165
104
  udid: udid,
@@ -173,7 +112,7 @@ module Mdq
173
112
 
174
113
  # Appleデバイス一覧を取得する
175
114
  def apple_discover
176
- file = [Dir.home, '.mdq.json'].join(File::Separator)
115
+ file = [Dir.home, '.mdq'].join(File::Separator)
177
116
  result = apple_command("list devices -v -j #{file}")
178
117
  return if result.nil?
179
118
  return unless File.exist?(file)
@@ -181,8 +120,9 @@ module Mdq
181
120
  File.open(file, 'r') do |f|
182
121
  result = JSON.parse(f.read)
183
122
  result['result']['devices'].each do |device|
123
+ udid = device['hardwareProperties']['udid']
184
124
  Device.create({
185
- udid: device['hardwareProperties']['udid'],
125
+ udid: udid,
186
126
  serial_number: device['hardwareProperties']['serialNumber'],
187
127
  name: device['deviceProperties']['name'],
188
128
  authorized: true,
@@ -197,6 +137,39 @@ module Mdq
197
137
  File.delete(file)
198
138
  end
199
139
  end
140
+
141
+ # Androidのアプリを取得する
142
+ def android_apps(udid)
143
+ apps, = adb_command('shell pm list packages', udid)
144
+ apps.split("\n").each do |line3|
145
+ App.create({
146
+ udid: udid,
147
+ package_name: line3.gsub('package:', '')
148
+ })
149
+ end
150
+ end
151
+
152
+ # Appleデバイスのアプリを取得する
153
+ def apple_apps(udid)
154
+ file = [Dir.home, '.mdq-apps'].join(File::Separator)
155
+ apple_command("device info apps -j #{file}", udid)
156
+ File.open(file, 'r') do |f|
157
+ result = JSON.parse(f.read)
158
+ begin
159
+ result['result']['apps'].each do |app|
160
+ App.create({
161
+ udid: udid,
162
+ package_name: app['bundleIdentifier'],
163
+ name: app['name'],
164
+ version: app['version']
165
+ })
166
+ end
167
+ rescue StandardError
168
+ # none
169
+ end
170
+ end
171
+ File.delete(file)
172
+ end
200
173
  end
201
174
  end
202
175
 
@@ -222,12 +195,28 @@ class InitialSchema < ActiveRecord::Migration[5.1]
222
195
  t.integer :total_capacity
223
196
  t.integer :free_capacity
224
197
  end
198
+
199
+ create_table :apps do |t|
200
+ t.string :udid
201
+ t.string :name
202
+ t.string :package_name
203
+ t.string :version
204
+ end
225
205
  end
226
206
 
227
207
  def self.down
228
208
  drop_table :devices
209
+ drop_table :apps
229
210
  end
230
211
  end
231
212
 
213
+ # Device
232
214
  class Device < ActiveRecord::Base
215
+ def android?
216
+ platform == 'Android'
217
+ end
218
+ end
219
+
220
+ # App
221
+ class App < ActiveRecord::Base
233
222
  end
data/lib/mdq/list.rb CHANGED
@@ -7,10 +7,12 @@ module Mdq
7
7
  # List
8
8
  class List
9
9
  def initialize(options)
10
- ddb = Mdq::DDB.new
11
- devices = ddb.get(options['query'])
10
+ db = Mdq::DB.new
12
11
 
13
- output = JSON.pretty_generate(devices.as_json)
12
+ query = options['query']
13
+ models = db.get(query)
14
+
15
+ output = JSON.pretty_generate(models.as_json)
14
16
  puts output
15
17
  if options['output']
16
18
  File.open(options['output'], 'w') do |f|
@@ -18,10 +20,10 @@ module Mdq
18
20
  end
19
21
  end
20
22
 
21
- devices.each do |device|
23
+ models.each do |device|
22
24
  model = Device.find_by(udid: device.udid)
23
25
  udid = model.udid
24
- is_android = model.platform == 'Android'
26
+ is_android = model.android?
25
27
 
26
28
  ddb.device_screencap(options[:cap], udid, is_android) if options[:cap]
27
29
  ddb.app_install(options[:install], udid, is_android) if options[:install]
data/lib/mdq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mdq
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/mdq.rb CHANGED
@@ -4,7 +4,9 @@ require_relative 'mdq/version'
4
4
  require 'mdq/cli'
5
5
  require 'mdq/check'
6
6
  require 'mdq/list'
7
- require 'mdq/ddb'
7
+ require 'mdq/discovery'
8
+ require 'mdq/db'
9
+
8
10
  require 'open3'
9
11
  require 'active_record'
10
12
  require 'json'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arthur87
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-20 00:00:00.000000000 Z
11
+ date: 2025-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -87,7 +87,8 @@ files:
87
87
  - lib/mdq.rb
88
88
  - lib/mdq/check.rb
89
89
  - lib/mdq/cli.rb
90
- - lib/mdq/ddb.rb
90
+ - lib/mdq/db.rb
91
+ - lib/mdq/discovery.rb
91
92
  - lib/mdq/list.rb
92
93
  - lib/mdq/version.rb
93
94
  homepage: https://github.com/arthur87/mdq