mdq 0.1.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: 5b6ccf8139b087e853fd80d2f993a1ed23f36fdb9f00e91a9cdfbe139ad925cc
4
- data.tar.gz: 27be35859eb50189dfc0a892340f66c135f0b5071eacf4ef8b3d775a58397fcc
3
+ metadata.gz: 11207ffa243aa9925a945ecf3e989f3ef136a36d3ef3d574e32372528097e09f
4
+ data.tar.gz: 642365689def13a8c56769d3f070954b123f3c6ebf7ca23f2a781415a1a44f5d
5
5
  SHA512:
6
- metadata.gz: e667d4599d3a713d5eccfa134559d73b58c62ad7a86421dd02522cc3302925884e36785be34937b27ec39f243e466cdd4841bd9e0a75aa2619f88dd28b99688d
7
- data.tar.gz: 9ed7bf1a7bde453757d2924eb9b9b64b9ee0289a76baa1720ffcfcd53a2d1f88cc37990d67ae11adcbc31a0e29beb28bb9f2ab64363ae8420a73659b308c7c88
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/cli.rb CHANGED
@@ -26,8 +26,8 @@ module Mdq
26
26
  method_option :output, desc: 'Save the results as a JSON file', aliases: '-o'
27
27
  method_option :query, desc: 'SQL to filter devices', aliases: '-q'
28
28
  method_option :cap, desc: 'Path to save screenshots(Android only)'
29
- method_option :install, desc: 'Installing the app'
30
- method_option :uninstall, desc: 'Uninstalling the app'
29
+ method_option :install, desc: 'Installing the app(apk, ipa)'
30
+ method_option :uninstall, desc: 'Uninstalling the app(Package Name, Bundle Identifier)'
31
31
  def list
32
32
  Mdq::List.new(options)
33
33
  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,68 +6,45 @@ 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
14
  end
41
15
 
42
- # Androidデバイスのスクリーンショットを撮る
43
- def device_screencap(output, udid, is_android)
44
- return unless is_android
16
+ private
45
17
 
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
- end
18
+ # ADBコマンド
19
+ def adb_command(arg, udid = nil)
20
+ command = if udid.nil?
21
+ "adb #{arg}"
22
+ else
23
+ "adb -s #{udid} #{arg}"
24
+ end
52
25
 
53
- def app_install(input, udid, is_android)
54
- if is_android && input.end_with?('.apk')
55
- adb_command("install #{input}", udid)
56
- else
57
- apple_command("device install app #{input}", udid)
26
+ begin
27
+ Open3.capture3(command)
28
+ rescue StandardError
29
+ nil
58
30
  end
59
31
  end
60
32
 
61
- def app_uninstall(input, udid, is_android)
62
- if is_android
63
- adb_command("uninstall #{input}", udid)
64
- else
65
- apple_command("device uninstall app #{input}", udid)
33
+ # devicectlコマンド
34
+ def apple_command(arg, udid = nil)
35
+ command = if udid.nil?
36
+ "xcrun devicectl #{arg}"
37
+ else
38
+ "xcrun devicectl #{arg} --device #{udid}"
39
+ end
40
+
41
+ begin
42
+ Open3.capture3(command)
43
+ rescue StandardError
44
+ nil
66
45
  end
67
46
  end
68
47
 
69
- private
70
-
71
48
  # Androidデバイス一覧を取得する
72
49
  def android_discover
73
50
  output, = adb_command('devices -l')
@@ -82,10 +59,10 @@ module Mdq
82
59
  authorized = line.index('unauthorized').nil?
83
60
 
84
61
  if authorized
85
- model = adb_command('shell getprop ro.product.model', udid)
86
- build_version = adb_command('shell getprop ro.build.version.release', udid)
87
- build_id = adb_command('shell getprop ro.build.id', udid)
88
- name = adb_command('shell settings get global device_name', udid)
62
+ model, = adb_command('shell getprop ro.product.model', udid)
63
+ build_version, = adb_command('shell getprop ro.build.version.release', udid)
64
+ build_id, = adb_command('shell getprop ro.build.id', udid)
65
+ name, = adb_command('shell settings get global device_name', udid)
89
66
  battery_level = nil
90
67
  total_capacity = nil
91
68
  free_capacity = nil
@@ -111,16 +88,17 @@ module Mdq
111
88
  Device.create({
112
89
  udid: udid,
113
90
  serial_number: udid,
114
- name: name,
91
+ name: name.strip,
115
92
  authorized: true,
116
- model: model,
117
- build_version: build_version,
118
- build_id: build_id,
93
+ model: model.strip,
94
+ build_version: build_version.strip,
95
+ build_id: build_id.strip,
119
96
  battery_level: battery_level,
120
97
  total_capacity: total_capacity,
121
98
  free_capacity: free_capacity,
122
99
  platform: 'Android'
123
100
  })
101
+
124
102
  else
125
103
  Device.create({
126
104
  udid: udid,
@@ -132,55 +110,19 @@ module Mdq
132
110
  end
133
111
  end
134
112
 
135
- # ADBコマンド
136
- def adb_command(arg, udid = nil)
137
- command = if udid.nil?
138
- "adb #{arg}"
139
- else
140
- "adb -s #{udid} #{arg}"
141
- end
142
-
143
- begin
144
- output, = Open3.capture3(command)
145
- output.strip
146
- rescue StandardError
147
- nil
148
- end
149
- end
150
-
151
- # devicectlコマンド
152
- def apple_command(arg, udid = nil)
153
- command = if udid.nil?
154
- "xcrun devicectl #{arg}"
155
- else
156
- "xcrun devicectl #{arg} --device #{udid}"
157
- end
158
-
159
- begin
160
- output, = Open3.capture3(command)
161
- output.strip
162
- rescue StandardError
163
- nil
164
- end
165
- end
166
-
167
113
  # Appleデバイス一覧を取得する
168
114
  def apple_discover
169
- file = [Dir.home, '.mdq.json'].join(File::Separator)
170
-
171
- begin
172
- Open3.capture3("xcrun devicectl list devices -v -j #{file}")
173
- rescue StandardError
174
- return
175
- end
176
-
115
+ file = [Dir.home, '.mdq'].join(File::Separator)
116
+ result = apple_command("list devices -v -j #{file}")
117
+ return if result.nil?
177
118
  return unless File.exist?(file)
178
119
 
179
120
  File.open(file, 'r') do |f|
180
121
  result = JSON.parse(f.read)
181
122
  result['result']['devices'].each do |device|
123
+ udid = device['hardwareProperties']['udid']
182
124
  Device.create({
183
- udid: device['hardwareProperties']['udid'],
125
+ udid: udid,
184
126
  serial_number: device['hardwareProperties']['serialNumber'],
185
127
  name: device['deviceProperties']['name'],
186
128
  authorized: true,
@@ -195,6 +137,39 @@ module Mdq
195
137
  File.delete(file)
196
138
  end
197
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
198
173
  end
199
174
  end
200
175
 
@@ -220,12 +195,28 @@ class InitialSchema < ActiveRecord::Migration[5.1]
220
195
  t.integer :total_capacity
221
196
  t.integer :free_capacity
222
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
223
205
  end
224
206
 
225
207
  def self.down
226
208
  drop_table :devices
209
+ drop_table :apps
227
210
  end
228
211
  end
229
212
 
213
+ # Device
230
214
  class Device < ActiveRecord::Base
215
+ def android?
216
+ platform == 'Android'
217
+ end
218
+ end
219
+
220
+ # App
221
+ class App < ActiveRecord::Base
231
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,13 +20,13 @@ 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
- ddb.app_install(options[:install], udid) if options[:install]
29
+ ddb.app_install(options[:install], udid, is_android) if options[:install]
28
30
  ddb.app_uninstall(options[:uninstall], udid, is_android) if options[:uninstall]
29
31
  rescue StandardError
30
32
  # none
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.1.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.1.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-19 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