mdq 0.2.0 → 0.4.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: 7cac0bbdd587c39245b20565f173c940cc3820d013e85ea49cdeef449fbba699
4
+ data.tar.gz: 13ccafb7f07a7e52425f350d26315a0e6638cbd2f6cf07a83d3c2e58501b6293
5
5
  SHA512:
6
- metadata.gz: a26e2f9fdb44629c5e478845bc227fe2efe7354b1e1e01f84214e9b2c36fe6edaea6d95e17c25a333ecad911bb203e5321192ffd5a3ebd9d66da283413a70608
7
- data.tar.gz: b936990fa4c104841742c5cc1bb11c791e7c96b98585ffe29cb08dc42729eece6aaa06c8ca935545e7e5ad67d3d3c933673c1ea7f3e92f49097f20b75d6c68dc
6
+ metadata.gz: 7dc6da32e3ab760db20aa66e1c744506eacee4ab46f210f212742faac3622bddc9b340d9565c31466b20104fcec674f61eca9d5a26ab8d87343b5404a5745669
7
+ data.tar.gz: 853b11146f7ea736f48ef558e7d88eae4f43d4d55da1056dfaa00d1179fcba0cfea1812df5edc4e0a7ecc6f8784706fef394c4d58405c263e6ce8abb52c66b1e
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
@@ -7,6 +7,8 @@
7
7
 
8
8
  # mdq - Mobile Device Query
9
9
 
10
+ [![Gem Version](https://badge.fury.io/rb/mdq.svg)](https://badge.fury.io/rb/mdq)
11
+
10
12
  MDQ stands for Mobile Device Query and is a command line tool for displaying information about Android and Apple devices.
11
13
 
12
14
  # Usage
@@ -83,6 +85,34 @@ $ mdq list -q="select * from devices where platform='iOS'"
83
85
  ]
84
86
  ```
85
87
 
88
+ View apps installed on your device.
89
+ Apple Devices displays the apps installed with Xcode.
90
+
91
+ ```
92
+ $ mdq list -q='select * from apps'
93
+ ```
94
+
95
+ Take a screenshot on Android.
96
+
97
+ ```
98
+ $ mdq list --cap='/Users/xxxxx/'
99
+ ```
100
+
101
+ Install the app.
102
+
103
+ ```
104
+ $ mdq list --install='/Users/xxxxx/example.apk'
105
+ $ mdq list --install='/Users/xxxxx/example.ipa'
106
+ ```
107
+
108
+ Uninstall the app.
109
+
110
+ ```
111
+ $ mdq list --uninstall='com.example.app'
112
+ ```
113
+
114
+
115
+
86
116
  # Specification
87
117
 
88
118
  Details of the devices table.
@@ -99,5 +129,16 @@ Details of the devices table.
99
129
  | build_version | ro.build.version.release | deviceProperties.osVersionNumber |
100
130
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
101
131
  | battery_level | battery | Always "null" |
102
- | total_capacity | df | Always "null" |
103
- | free_capacity | df | Always "null" |
132
+ | total_capacity | df | hardwareProperties.internalStorageCapacity |
133
+ | free_capacity | df | Always "null" |
134
+
135
+
136
+ Details of the apps table.
137
+ Apple Devices displays the apps installed with Xcode.
138
+
139
+ | name | android | apple devices |
140
+ | -- | -- | -- |
141
+ | udid | Serial number | hardwareProperties.udid |
142
+ | name | Always "null" | name |
143
+ | package_name | Package name | bundleIdentifier |
144
+ | version | Always "null" | version |
data/README.ja.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # mdq - Mobile Device Query
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/mdq.svg)](https://badge.fury.io/rb/mdq)
6
+
5
7
  MDQ stands for Mobile Device Query and is a command line tool for displaying information about Android and Apple devices.
6
8
 
7
9
  # Usage
@@ -78,6 +80,34 @@ $ mdq list -q="select * from devices where platform='iOS'"
78
80
  ]
79
81
  ```
80
82
 
83
+ View apps installed on your device.
84
+ Apple Devices displays the apps installed with Xcode.
85
+
86
+ ```
87
+ $ mdq list -q='select * from apps'
88
+ ```
89
+
90
+ Take a screenshot on Android.
91
+
92
+ ```
93
+ $ mdq list --cap='/Users/xxxxx/'
94
+ ```
95
+
96
+ Install the app.
97
+
98
+ ```
99
+ $ mdq list --install='/Users/xxxxx/example.apk'
100
+ $ mdq list --install='/Users/xxxxx/example.ipa'
101
+ ```
102
+
103
+ Uninstall the app.
104
+
105
+ ```
106
+ $ mdq list --uninstall='com.example.app'
107
+ ```
108
+
109
+
110
+
81
111
  # Specification
82
112
 
83
113
  Details of the devices table.
@@ -94,5 +124,16 @@ Details of the devices table.
94
124
  | build_version | ro.build.version.release | deviceProperties.osVersionNumber |
95
125
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
96
126
  | battery_level | battery | Always "null" |
97
- | total_capacity | df | Always "null" |
98
- | free_capacity | df | Always "null" |
127
+ | total_capacity | df | hardwareProperties.internalStorageCapacity |
128
+ | free_capacity | df | Always "null" |
129
+
130
+
131
+ Details of the apps table.
132
+ Apple Devices displays the apps installed with Xcode.
133
+
134
+ | name | android | apple devices |
135
+ | -- | -- | -- |
136
+ | udid | Serial number | hardwareProperties.udid |
137
+ | name | Always "null" | name |
138
+ | package_name | Package name | bundleIdentifier |
139
+ | version | Always "null" | version |
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # mdq - Mobile Device Query
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/mdq.svg)](https://badge.fury.io/rb/mdq)
6
+
5
7
  MDQ stands for Mobile Device Query and is a command line tool for displaying information about Android and Apple devices.
6
8
 
7
9
  # Usage
@@ -78,6 +80,34 @@ $ mdq list -q="select * from devices where platform='iOS'"
78
80
  ]
79
81
  ```
80
82
 
83
+ View apps installed on your device.
84
+ Apple Devices displays the apps installed with Xcode.
85
+
86
+ ```
87
+ $ mdq list -q='select * from apps'
88
+ ```
89
+
90
+ Take a screenshot on Android.
91
+
92
+ ```
93
+ $ mdq list --cap='/Users/xxxxx/'
94
+ ```
95
+
96
+ Install the app.
97
+
98
+ ```
99
+ $ mdq list --install='/Users/xxxxx/example.apk'
100
+ $ mdq list --install='/Users/xxxxx/example.ipa'
101
+ ```
102
+
103
+ Uninstall the app.
104
+
105
+ ```
106
+ $ mdq list --uninstall='com.example.app'
107
+ ```
108
+
109
+
110
+
81
111
  # Specification
82
112
 
83
113
  Details of the devices table.
@@ -94,5 +124,16 @@ Details of the devices table.
94
124
  | build_version | ro.build.version.release | deviceProperties.osVersionNumber |
95
125
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
96
126
  | battery_level | battery | Always "null" |
97
- | total_capacity | df | Always "null" |
98
- | free_capacity | df | Always "null" |
127
+ | total_capacity | df | hardwareProperties.internalStorageCapacity |
128
+ | free_capacity | df | Always "null" |
129
+
130
+
131
+ Details of the apps table.
132
+ Apple Devices displays the apps installed with Xcode.
133
+
134
+ | name | android | apple devices |
135
+ | -- | -- | -- |
136
+ | udid | Serial number | hardwareProperties.udid |
137
+ | name | Always "null" | name |
138
+ | package_name | Package name | bundleIdentifier |
139
+ | version | Always "null" | version |
data/lib/mdq/check.rb CHANGED
@@ -7,9 +7,19 @@ 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
+ show_message('adb', db.android_discoverable?)
12
+ show_message('Xcode', db.apple_discoverable?)
13
+ end
14
+
15
+ private
16
+
17
+ def show_message(name, discoverable)
18
+ if discoverable
19
+ puts "# #{name} is installed."
20
+ else
21
+ puts "# #{name} is not installed."
22
+ end
13
23
  end
14
24
  end
15
25
  end
data/lib/mdq/db.rb ADDED
@@ -0,0 +1,77 @@
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
+ reset
14
+ # デバイスの発見
15
+ android_discover
16
+ apple_discover
17
+
18
+ if sql
19
+ Device.all.each do |model|
20
+ # インストール済みAppの取得
21
+ if model.android?
22
+ android_apps(model.udid)
23
+ else
24
+ apple_apps(model.udid)
25
+ end
26
+ end
27
+
28
+ begin
29
+ ActiveRecord::Base.connection.execute(sql)
30
+ rescue StandardError
31
+ warn 'SQL Syntax Error.'
32
+ exit
33
+ end
34
+ else
35
+ Device.all
36
+ end
37
+ end
38
+
39
+ # Androidデバイスのスクリーンショットを撮る
40
+ def device_screencap(output, udid, is_android)
41
+ return unless is_android
42
+
43
+ FileUtils.mkdir_p(output)
44
+ file = "/sdcard/#{udid}.png"
45
+ adb_command("shell screencap -p #{file}", udid)
46
+ adb_command("pull #{file} #{output}", udid)
47
+ adb_command("adb shell rm #{file}")
48
+
49
+ puts "# Screenshot of #{udid} to #{output}"
50
+ end
51
+
52
+ # Appをインストールする
53
+ def app_install(input, udid, is_android)
54
+ output, = adb_command("install #{input}", udid) if is_android && input.end_with?('.apk')
55
+ output, = apple_command("device install app #{input}", udid) if !is_android && input.end_with?('.ipa')
56
+
57
+ return unless output
58
+
59
+ puts "# Install #{input} to #{udid}"
60
+ puts output
61
+ end
62
+
63
+ # Appをアンインストールする
64
+ def app_uninstall(input, udid, is_android)
65
+ if is_android
66
+ output, = adb_command("uninstall #{input}", udid)
67
+ else
68
+ output, = apple_command("device uninstall app #{input}", udid)
69
+ end
70
+
71
+ return unless output
72
+
73
+ puts "# Uninstall #{input} from #{udid}"
74
+ puts output
75
+ end
76
+ end
77
+ end
@@ -6,73 +6,18 @@ 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)
15
- ActiveRecord::Schema.verbose = false
16
- 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}"
9
+ # Discovery
10
+ class Discovery
11
+ def initialize
12
+ @home = FileUtils.mkdir_p([Dir.home, '.mdq'].join(File::Separator))
53
13
  end
54
14
 
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
15
+ def android_discoverable?
16
+ adb_command('version').present?
63
17
  end
64
18
 
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
19
+ def apple_discoverable?
20
+ apple_command('--version').present?
76
21
  end
77
22
 
78
23
  private
@@ -108,7 +53,7 @@ module Mdq
108
53
  end
109
54
 
110
55
  # Androidデバイス一覧を取得する
111
- def android_discover # rubocop:disable Metrics/AbcSize
56
+ def android_discover
112
57
  output, = adb_command('devices -l')
113
58
  return if output.nil?
114
59
 
@@ -160,6 +105,7 @@ module Mdq
160
105
  free_capacity: free_capacity,
161
106
  platform: 'Android'
162
107
  })
108
+
163
109
  else
164
110
  Device.create({
165
111
  udid: udid,
@@ -173,16 +119,17 @@ module Mdq
173
119
 
174
120
  # Appleデバイス一覧を取得する
175
121
  def apple_discover
176
- file = [Dir.home, '.mdq.json'].join(File::Separator)
122
+ file = [@home, 'mdq.json'].join(File::Separator)
177
123
  result = apple_command("list devices -v -j #{file}")
178
- return if result.nil?
124
+
179
125
  return unless File.exist?(file)
180
126
 
181
127
  File.open(file, 'r') do |f|
182
128
  result = JSON.parse(f.read)
183
129
  result['result']['devices'].each do |device|
130
+ udid = device['hardwareProperties']['udid']
184
131
  Device.create({
185
- udid: device['hardwareProperties']['udid'],
132
+ udid: udid,
186
133
  serial_number: device['hardwareProperties']['serialNumber'],
187
134
  name: device['deviceProperties']['name'],
188
135
  authorized: true,
@@ -190,44 +137,94 @@ module Mdq
190
137
  marketing_name: device['hardwareProperties']['marketingName'],
191
138
  model: device['hardwareProperties']['productType'],
192
139
  build_version: device['deviceProperties']['osVersionNumber'],
193
- build_id: device['deviceProperties']['osBuildUpdate']
140
+ build_id: device['deviceProperties']['osBuildUpdate'],
141
+ total_capacity: device['hardwareProperties']['internalStorageCapacity']
194
142
  })
195
143
  end
196
144
 
197
145
  File.delete(file)
198
146
  end
199
147
  end
148
+
149
+ # Androidのアプリを取得する
150
+ def android_apps(udid)
151
+ apps, = adb_command('shell pm list packages', udid)
152
+ apps.split("\n").each do |line3|
153
+ App.create({
154
+ udid: udid,
155
+ package_name: line3.gsub('package:', '')
156
+ })
157
+ end
158
+ end
159
+
160
+ # Appleデバイスのアプリを取得する
161
+ def apple_apps(udid)
162
+ file = [@home, 'mdq-apps.json'].join(File::Separator)
163
+ apple_command("device info apps -j #{file}", udid)
164
+ File.open(file, 'r') do |f|
165
+ result = JSON.parse(f.read)
166
+ begin
167
+ result['result']['apps'].each do |app|
168
+ App.create({
169
+ udid: udid,
170
+ package_name: app['bundleIdentifier'],
171
+ name: app['name'],
172
+ version: app['version']
173
+ })
174
+ end
175
+ rescue StandardError
176
+ # none
177
+ end
178
+ end
179
+ File.delete(file)
180
+ end
181
+
182
+ def reset
183
+ Device.destroy_all
184
+ App.destroy_all
185
+ ActiveRecord::Base.connection.execute("delete from sqlite_sequence where name='devices'")
186
+ ActiveRecord::Base.connection.execute("delete from sqlite_sequence where name='apps'")
187
+ end
200
188
  end
201
189
  end
202
190
 
191
+ ActiveRecord::Schema.verbose = false
192
+ ActiveRecord::Migration.verbose = false
193
+
203
194
  ActiveRecord::Base.establish_connection(
204
195
  adapter: 'sqlite3',
205
196
  database: ':memory:'
206
197
  )
207
198
 
208
- # スキーマの設定
209
- class InitialSchema < ActiveRecord::Migration[5.1]
210
- def self.up
211
- create_table :devices do |t|
212
- t.string :udid
213
- t.string :serial_number
214
- t.string :name
215
- t.boolean :authorized
216
- t.string :platform
217
- t.string :marketing_name
218
- t.string :model
219
- t.string :build_version
220
- t.string :build_id
221
- t.integer :battery_level
222
- t.integer :total_capacity
223
- t.integer :free_capacity
224
- end
225
- end
199
+ ActiveRecord::Migration.create_table :devices do |t|
200
+ t.string :udid
201
+ t.string :serial_number
202
+ t.string :name
203
+ t.boolean :authorized
204
+ t.string :platform
205
+ t.string :marketing_name
206
+ t.string :model
207
+ t.string :build_version
208
+ t.string :build_id
209
+ t.integer :battery_level
210
+ t.integer :total_capacity
211
+ t.integer :free_capacity
212
+ end
226
213
 
227
- def self.down
228
- drop_table :devices
229
- end
214
+ ActiveRecord::Migration.create_table :apps do |t|
215
+ t.string :udid
216
+ t.string :name
217
+ t.string :package_name
218
+ t.string :version
230
219
  end
231
220
 
221
+ # Device
232
222
  class Device < ActiveRecord::Base
223
+ def android?
224
+ platform == 'Android'
225
+ end
226
+ end
227
+
228
+ # App
229
+ class App < ActiveRecord::Base
233
230
  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.4.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.4.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-24 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