mdq 0.1.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 +7 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +38 -0
- data/CHANGELOG.md +0 -0
- data/LICENSE +21 -0
- data/README.base.md +103 -0
- data/README.ja.md +98 -0
- data/README.md +98 -0
- data/Rakefile +4 -0
- data/exe/mdq +6 -0
- data/lib/mdq/check.rb +15 -0
- data/lib/mdq/cli.rb +35 -0
- data/lib/mdq/ddb.rb +231 -0
- data/lib/mdq/list.rb +34 -0
- data/lib/mdq/version.rb +5 -0
- data/lib/mdq.rb +15 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b6ccf8139b087e853fd80d2f993a1ed23f36fdb9f00e91a9cdfbe139ad925cc
|
4
|
+
data.tar.gz: 27be35859eb50189dfc0a892340f66c135f0b5071eacf4ef8b3d775a58397fcc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e667d4599d3a713d5eccfa134559d73b58c62ad7a86421dd02522cc3302925884e36785be34937b27ec39f243e466cdd4841bd9e0a75aa2619f88dd28b99688d
|
7
|
+
data.tar.gz: 9ed7bf1a7bde453757d2924eb9b9b64b9ee0289a76baa1720ffcfcd53a2d1f88cc37990d67ae11adcbc31a0e29beb28bb9f2ab64363ae8420a73659b308c7c88
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config --exclude-limit 999999`
|
3
|
+
# on 2025-05-18 05:31:37 UTC using RuboCop version 1.71.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 38
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
16
|
+
# AllowedMethods: refine
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Max: 46
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: CountComments, CountAsOne.
|
22
|
+
Metrics/ClassLength:
|
23
|
+
Max: 160
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
27
|
+
Metrics/CyclomaticComplexity:
|
28
|
+
Max: 9
|
29
|
+
|
30
|
+
# Offense count: 4
|
31
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 50
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
37
|
+
Metrics/PerceivedComplexity:
|
38
|
+
Max: 10
|
data/CHANGELOG.md
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 arthur87
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.base.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
<!---------------------------->
|
2
|
+
<!-- multilingual suffix: en, ja -->
|
3
|
+
<!-- no suffix: en -->
|
4
|
+
<!---------------------------->
|
5
|
+
|
6
|
+
<!-- $ mmg -y README.base.md -->
|
7
|
+
|
8
|
+
# mdq - Mobile Device Query
|
9
|
+
|
10
|
+
MDQ stands for Mobile Device Query and is a command line tool for displaying information about Android and Apple devices.
|
11
|
+
|
12
|
+
# Usage
|
13
|
+
|
14
|
+
## Check
|
15
|
+
|
16
|
+
To fully use MDQ, you need to install ADB and Xcode beforehand.
|
17
|
+
Check the software installation status.
|
18
|
+
|
19
|
+
```
|
20
|
+
$ mdq check
|
21
|
+
```
|
22
|
+
|
23
|
+
## List
|
24
|
+
|
25
|
+
It's easy to use.
|
26
|
+
|
27
|
+
```
|
28
|
+
$ mdq list
|
29
|
+
[
|
30
|
+
{
|
31
|
+
"id": 1,
|
32
|
+
"udid": "XXXXX",
|
33
|
+
"serial_number": "XXXXX",
|
34
|
+
"name": "Pixel Tablet",
|
35
|
+
"authorized": true,
|
36
|
+
"platform": "Android",
|
37
|
+
"marketing_name": null,
|
38
|
+
"model": "Pixel Tablet",
|
39
|
+
"build_version": "16",
|
40
|
+
"build_id": "BP22.250325.012",
|
41
|
+
"battery_level": 89,
|
42
|
+
"total_capacity": 115855444,
|
43
|
+
"free_capacity": 101137652
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"id": 2,
|
47
|
+
"udid": "XXXXX",
|
48
|
+
"serial_number": "XXXXX",
|
49
|
+
"name": "iPhone 16 Pro",
|
50
|
+
"authorized": true,
|
51
|
+
"platform": "iOS",
|
52
|
+
"marketing_name": "iPhone 16 Pro",
|
53
|
+
"model": "iPhone17,1",
|
54
|
+
"build_version": "18.4.1",
|
55
|
+
"build_id": "22E252",
|
56
|
+
"battery_level": null,
|
57
|
+
"total_capacity": null,
|
58
|
+
"free_capacity": null
|
59
|
+
}
|
60
|
+
]
|
61
|
+
```
|
62
|
+
|
63
|
+
You can filter using SQL.
|
64
|
+
|
65
|
+
```
|
66
|
+
$ mdq list -q="select * from devices where platform='iOS'"
|
67
|
+
[
|
68
|
+
{
|
69
|
+
"id": 1,
|
70
|
+
"udid": "XXXXX",
|
71
|
+
"serial_number": "XXXXX",
|
72
|
+
"name": "iPhone 16 Pro",
|
73
|
+
"authorized": true,
|
74
|
+
"platform": "iOS",
|
75
|
+
"marketing_name": "iPhone 16 Pro",
|
76
|
+
"model": "iPhone17,1",
|
77
|
+
"build_version": "18.4.1",
|
78
|
+
"build_id": "22E252",
|
79
|
+
"battery_level": null,
|
80
|
+
"total_capacity": null,
|
81
|
+
"free_capacity": null
|
82
|
+
}
|
83
|
+
]
|
84
|
+
```
|
85
|
+
|
86
|
+
# Specification
|
87
|
+
|
88
|
+
Details of the devices table.
|
89
|
+
|
90
|
+
| name | android | apple devices |
|
91
|
+
| -- | -- | -- |
|
92
|
+
| udid | Serial number | hardwareProperties.udid |
|
93
|
+
| serial_number | Serial number | hardwareProperties.serialNumber |
|
94
|
+
| name | device_name | deviceProperties.name |
|
95
|
+
| authorized | "False" if additional authentication is required. | Always "True" |
|
96
|
+
| platform | Always "Android" | hardwareProperties.platform |
|
97
|
+
| marketing_name | Always "null" | hardwareProperties.marketingName |
|
98
|
+
| model | ro.product.model | hardwareProperties.productType |
|
99
|
+
| build_version | ro.build.version.release | deviceProperties.osVersionNumber |
|
100
|
+
| build_id | ro.build.id | deviceProperties.osBuildUpdate |
|
101
|
+
| battery_level | battery | Always "null" |
|
102
|
+
| total_capacity | df | Always "null" |
|
103
|
+
| free_capacity | df | Always "null" |
|
data/README.ja.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# mdq - Mobile Device Query
|
4
|
+
|
5
|
+
MDQ stands for Mobile Device Query and is a command line tool for displaying information about Android and Apple devices.
|
6
|
+
|
7
|
+
# Usage
|
8
|
+
|
9
|
+
## Check
|
10
|
+
|
11
|
+
To fully use MDQ, you need to install ADB and Xcode beforehand.
|
12
|
+
Check the software installation status.
|
13
|
+
|
14
|
+
```
|
15
|
+
$ mdq check
|
16
|
+
```
|
17
|
+
|
18
|
+
## List
|
19
|
+
|
20
|
+
It's easy to use.
|
21
|
+
|
22
|
+
```
|
23
|
+
$ mdq list
|
24
|
+
[
|
25
|
+
{
|
26
|
+
"id": 1,
|
27
|
+
"udid": "XXXXX",
|
28
|
+
"serial_number": "XXXXX",
|
29
|
+
"name": "Pixel Tablet",
|
30
|
+
"authorized": true,
|
31
|
+
"platform": "Android",
|
32
|
+
"marketing_name": null,
|
33
|
+
"model": "Pixel Tablet",
|
34
|
+
"build_version": "16",
|
35
|
+
"build_id": "BP22.250325.012",
|
36
|
+
"battery_level": 89,
|
37
|
+
"total_capacity": 115855444,
|
38
|
+
"free_capacity": 101137652
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"id": 2,
|
42
|
+
"udid": "XXXXX",
|
43
|
+
"serial_number": "XXXXX",
|
44
|
+
"name": "iPhone 16 Pro",
|
45
|
+
"authorized": true,
|
46
|
+
"platform": "iOS",
|
47
|
+
"marketing_name": "iPhone 16 Pro",
|
48
|
+
"model": "iPhone17,1",
|
49
|
+
"build_version": "18.4.1",
|
50
|
+
"build_id": "22E252",
|
51
|
+
"battery_level": null,
|
52
|
+
"total_capacity": null,
|
53
|
+
"free_capacity": null
|
54
|
+
}
|
55
|
+
]
|
56
|
+
```
|
57
|
+
|
58
|
+
You can filter using SQL.
|
59
|
+
|
60
|
+
```
|
61
|
+
$ mdq list -q="select * from devices where platform='iOS'"
|
62
|
+
[
|
63
|
+
{
|
64
|
+
"id": 1,
|
65
|
+
"udid": "XXXXX",
|
66
|
+
"serial_number": "XXXXX",
|
67
|
+
"name": "iPhone 16 Pro",
|
68
|
+
"authorized": true,
|
69
|
+
"platform": "iOS",
|
70
|
+
"marketing_name": "iPhone 16 Pro",
|
71
|
+
"model": "iPhone17,1",
|
72
|
+
"build_version": "18.4.1",
|
73
|
+
"build_id": "22E252",
|
74
|
+
"battery_level": null,
|
75
|
+
"total_capacity": null,
|
76
|
+
"free_capacity": null
|
77
|
+
}
|
78
|
+
]
|
79
|
+
```
|
80
|
+
|
81
|
+
# Specification
|
82
|
+
|
83
|
+
Details of the devices table.
|
84
|
+
|
85
|
+
| name | android | apple devices |
|
86
|
+
| -- | -- | -- |
|
87
|
+
| udid | Serial number | hardwareProperties.udid |
|
88
|
+
| serial_number | Serial number | hardwareProperties.serialNumber |
|
89
|
+
| name | device_name | deviceProperties.name |
|
90
|
+
| authorized | "False" if additional authentication is required. | Always "True" |
|
91
|
+
| platform | Always "Android" | hardwareProperties.platform |
|
92
|
+
| marketing_name | Always "null" | hardwareProperties.marketingName |
|
93
|
+
| model | ro.product.model | hardwareProperties.productType |
|
94
|
+
| build_version | ro.build.version.release | deviceProperties.osVersionNumber |
|
95
|
+
| build_id | ro.build.id | deviceProperties.osBuildUpdate |
|
96
|
+
| battery_level | battery | Always "null" |
|
97
|
+
| total_capacity | df | Always "null" |
|
98
|
+
| free_capacity | df | Always "null" |
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# mdq - Mobile Device Query
|
4
|
+
|
5
|
+
MDQ stands for Mobile Device Query and is a command line tool for displaying information about Android and Apple devices.
|
6
|
+
|
7
|
+
# Usage
|
8
|
+
|
9
|
+
## Check
|
10
|
+
|
11
|
+
To fully use MDQ, you need to install ADB and Xcode beforehand.
|
12
|
+
Check the software installation status.
|
13
|
+
|
14
|
+
```
|
15
|
+
$ mdq check
|
16
|
+
```
|
17
|
+
|
18
|
+
## List
|
19
|
+
|
20
|
+
It's easy to use.
|
21
|
+
|
22
|
+
```
|
23
|
+
$ mdq list
|
24
|
+
[
|
25
|
+
{
|
26
|
+
"id": 1,
|
27
|
+
"udid": "XXXXX",
|
28
|
+
"serial_number": "XXXXX",
|
29
|
+
"name": "Pixel Tablet",
|
30
|
+
"authorized": true,
|
31
|
+
"platform": "Android",
|
32
|
+
"marketing_name": null,
|
33
|
+
"model": "Pixel Tablet",
|
34
|
+
"build_version": "16",
|
35
|
+
"build_id": "BP22.250325.012",
|
36
|
+
"battery_level": 89,
|
37
|
+
"total_capacity": 115855444,
|
38
|
+
"free_capacity": 101137652
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"id": 2,
|
42
|
+
"udid": "XXXXX",
|
43
|
+
"serial_number": "XXXXX",
|
44
|
+
"name": "iPhone 16 Pro",
|
45
|
+
"authorized": true,
|
46
|
+
"platform": "iOS",
|
47
|
+
"marketing_name": "iPhone 16 Pro",
|
48
|
+
"model": "iPhone17,1",
|
49
|
+
"build_version": "18.4.1",
|
50
|
+
"build_id": "22E252",
|
51
|
+
"battery_level": null,
|
52
|
+
"total_capacity": null,
|
53
|
+
"free_capacity": null
|
54
|
+
}
|
55
|
+
]
|
56
|
+
```
|
57
|
+
|
58
|
+
You can filter using SQL.
|
59
|
+
|
60
|
+
```
|
61
|
+
$ mdq list -q="select * from devices where platform='iOS'"
|
62
|
+
[
|
63
|
+
{
|
64
|
+
"id": 1,
|
65
|
+
"udid": "XXXXX",
|
66
|
+
"serial_number": "XXXXX",
|
67
|
+
"name": "iPhone 16 Pro",
|
68
|
+
"authorized": true,
|
69
|
+
"platform": "iOS",
|
70
|
+
"marketing_name": "iPhone 16 Pro",
|
71
|
+
"model": "iPhone17,1",
|
72
|
+
"build_version": "18.4.1",
|
73
|
+
"build_id": "22E252",
|
74
|
+
"battery_level": null,
|
75
|
+
"total_capacity": null,
|
76
|
+
"free_capacity": null
|
77
|
+
}
|
78
|
+
]
|
79
|
+
```
|
80
|
+
|
81
|
+
# Specification
|
82
|
+
|
83
|
+
Details of the devices table.
|
84
|
+
|
85
|
+
| name | android | apple devices |
|
86
|
+
| -- | -- | -- |
|
87
|
+
| udid | Serial number | hardwareProperties.udid |
|
88
|
+
| serial_number | Serial number | hardwareProperties.serialNumber |
|
89
|
+
| name | device_name | deviceProperties.name |
|
90
|
+
| authorized | "False" if additional authentication is required. | Always "True" |
|
91
|
+
| platform | Always "Android" | hardwareProperties.platform |
|
92
|
+
| marketing_name | Always "null" | hardwareProperties.marketingName |
|
93
|
+
| model | ro.product.model | hardwareProperties.productType |
|
94
|
+
| build_version | ro.build.version.release | deviceProperties.osVersionNumber |
|
95
|
+
| build_id | ro.build.id | deviceProperties.osBuildUpdate |
|
96
|
+
| battery_level | battery | Always "null" |
|
97
|
+
| total_capacity | df | Always "null" |
|
98
|
+
| free_capacity | df | Always "null" |
|
data/Rakefile
ADDED
data/exe/mdq
ADDED
data/lib/mdq/check.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mdq'
|
4
|
+
|
5
|
+
# Mdq
|
6
|
+
module Mdq
|
7
|
+
# Check
|
8
|
+
class Check
|
9
|
+
def initialize
|
10
|
+
ddb = Mdq::DDB.new
|
11
|
+
ddb.show_version('adb', 'adb version')
|
12
|
+
ddb.show_version('Xcode', 'xcrun devicectl --version')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/mdq/cli.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mdq'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Mdq
|
7
|
+
# entry point
|
8
|
+
class CLI < Thor
|
9
|
+
class << self
|
10
|
+
def exit_on_failure?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'version', 'Show Version'
|
16
|
+
def version
|
17
|
+
puts(Mdq::VERSION)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'check', 'Check the software installation status'
|
21
|
+
def check
|
22
|
+
Mdq::Check.new
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'list', 'Show mobile devices'
|
26
|
+
method_option :output, desc: 'Save the results as a JSON file', aliases: '-o'
|
27
|
+
method_option :query, desc: 'SQL to filter devices', aliases: '-q'
|
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'
|
31
|
+
def list
|
32
|
+
Mdq::List.new(options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/mdq/ddb.rb
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mdq'
|
4
|
+
require 'active_record'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
# Mdq
|
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
|
+
end
|
52
|
+
|
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)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
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)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Androidデバイス一覧を取得する
|
72
|
+
def android_discover
|
73
|
+
output, = adb_command('devices -l')
|
74
|
+
return if output.nil?
|
75
|
+
|
76
|
+
output.split("\n").each_with_index do |line, index|
|
77
|
+
next if index.zero?
|
78
|
+
|
79
|
+
columns = line.split
|
80
|
+
|
81
|
+
udid = columns[0]
|
82
|
+
authorized = line.index('unauthorized').nil?
|
83
|
+
|
84
|
+
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)
|
89
|
+
battery_level = nil
|
90
|
+
total_capacity = nil
|
91
|
+
free_capacity = nil
|
92
|
+
|
93
|
+
# バッテリー
|
94
|
+
lines1, = adb_command('shell dumpsys battery', udid)
|
95
|
+
if (match = lines1.match(/level: (\d*)/))
|
96
|
+
battery_level = match[1].to_i
|
97
|
+
end
|
98
|
+
|
99
|
+
# ストレージ
|
100
|
+
lines2, = adb_command('shell df', udid)
|
101
|
+
lines2.split("\n").each_with_index do |line2, index2|
|
102
|
+
next if index2.zero?
|
103
|
+
|
104
|
+
columns = line2.split
|
105
|
+
unless columns[5].index('/data').nil?
|
106
|
+
total_capacity = columns[1]
|
107
|
+
free_capacity = columns[3]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Device.create({
|
112
|
+
udid: udid,
|
113
|
+
serial_number: udid,
|
114
|
+
name: name,
|
115
|
+
authorized: true,
|
116
|
+
model: model,
|
117
|
+
build_version: build_version,
|
118
|
+
build_id: build_id,
|
119
|
+
battery_level: battery_level,
|
120
|
+
total_capacity: total_capacity,
|
121
|
+
free_capacity: free_capacity,
|
122
|
+
platform: 'Android'
|
123
|
+
})
|
124
|
+
else
|
125
|
+
Device.create({
|
126
|
+
udid: udid,
|
127
|
+
serial_number: udid,
|
128
|
+
authorized: false,
|
129
|
+
platform: 'Android'
|
130
|
+
})
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
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
|
+
# Appleデバイス一覧を取得する
|
168
|
+
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
|
+
|
177
|
+
return unless File.exist?(file)
|
178
|
+
|
179
|
+
File.open(file, 'r') do |f|
|
180
|
+
result = JSON.parse(f.read)
|
181
|
+
result['result']['devices'].each do |device|
|
182
|
+
Device.create({
|
183
|
+
udid: device['hardwareProperties']['udid'],
|
184
|
+
serial_number: device['hardwareProperties']['serialNumber'],
|
185
|
+
name: device['deviceProperties']['name'],
|
186
|
+
authorized: true,
|
187
|
+
platform: device['hardwareProperties']['platform'],
|
188
|
+
marketing_name: device['hardwareProperties']['marketingName'],
|
189
|
+
model: device['hardwareProperties']['productType'],
|
190
|
+
build_version: device['deviceProperties']['osVersionNumber'],
|
191
|
+
build_id: device['deviceProperties']['osBuildUpdate']
|
192
|
+
})
|
193
|
+
end
|
194
|
+
|
195
|
+
File.delete(file)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
ActiveRecord::Base.establish_connection(
|
202
|
+
adapter: 'sqlite3',
|
203
|
+
database: ':memory:'
|
204
|
+
)
|
205
|
+
|
206
|
+
# スキーマの設定
|
207
|
+
class InitialSchema < ActiveRecord::Migration[5.1]
|
208
|
+
def self.up
|
209
|
+
create_table :devices do |t|
|
210
|
+
t.string :udid
|
211
|
+
t.string :serial_number
|
212
|
+
t.string :name
|
213
|
+
t.boolean :authorized
|
214
|
+
t.string :platform
|
215
|
+
t.string :marketing_name
|
216
|
+
t.string :model
|
217
|
+
t.string :build_version
|
218
|
+
t.string :build_id
|
219
|
+
t.integer :battery_level
|
220
|
+
t.integer :total_capacity
|
221
|
+
t.integer :free_capacity
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.down
|
226
|
+
drop_table :devices
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class Device < ActiveRecord::Base
|
231
|
+
end
|
data/lib/mdq/list.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mdq'
|
4
|
+
|
5
|
+
# Mdq
|
6
|
+
module Mdq
|
7
|
+
# List
|
8
|
+
class List
|
9
|
+
def initialize(options)
|
10
|
+
ddb = Mdq::DDB.new
|
11
|
+
devices = ddb.get(options['query'])
|
12
|
+
|
13
|
+
output = JSON.pretty_generate(devices.as_json)
|
14
|
+
puts output
|
15
|
+
if options['output']
|
16
|
+
File.open(options['output'], 'w') do |f|
|
17
|
+
f.write(output)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
devices.each do |device|
|
22
|
+
model = Device.find_by(udid: device.udid)
|
23
|
+
udid = model.udid
|
24
|
+
is_android = model.platform == 'Android'
|
25
|
+
|
26
|
+
ddb.device_screencap(options[:cap], udid, is_android) if options[:cap]
|
27
|
+
ddb.app_install(options[:install], udid) if options[:install]
|
28
|
+
ddb.app_uninstall(options[:uninstall], udid, is_android) if options[:uninstall]
|
29
|
+
rescue StandardError
|
30
|
+
# none
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/mdq/version.rb
ADDED
data/lib/mdq.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'mdq/version'
|
4
|
+
require 'mdq/cli'
|
5
|
+
require 'mdq/check'
|
6
|
+
require 'mdq/list'
|
7
|
+
require 'mdq/ddb'
|
8
|
+
require 'open3'
|
9
|
+
require 'active_record'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
module Mdq
|
13
|
+
class Error < StandardError; end
|
14
|
+
# Your code goes here...
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mdq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- arthur87
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: mdq is a command line tool for displaying information about Android and
|
70
|
+
Apple devices.
|
71
|
+
email:
|
72
|
+
- arthur87@users.noreply.github.com
|
73
|
+
executables:
|
74
|
+
- mdq
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".rubocop_todo.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- LICENSE
|
82
|
+
- README.base.md
|
83
|
+
- README.ja.md
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- exe/mdq
|
87
|
+
- lib/mdq.rb
|
88
|
+
- lib/mdq/check.rb
|
89
|
+
- lib/mdq/cli.rb
|
90
|
+
- lib/mdq/ddb.rb
|
91
|
+
- lib/mdq/list.rb
|
92
|
+
- lib/mdq/version.rb
|
93
|
+
homepage: https://github.com/arthur87/mdq
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata:
|
97
|
+
homepage_uri: https://github.com/arthur87/mdq
|
98
|
+
source_code_uri: https://github.com/arthur87/mdq
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 3.0.0
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubygems_version: 3.3.3
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: mdq is a command line tool for displaying information about Android and Apple
|
118
|
+
devices.
|
119
|
+
test_files: []
|