mdq 0.1.0 → 0.2.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 +4 -4
 - data/lib/mdq/cli.rb +2 -2
 - data/lib/mdq/ddb.rb +57 -55
 - data/lib/mdq/list.rb +1 -1
 - data/lib/mdq/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8a9f4ec5652eddd07350b8957261163db13ce51c1d36c7e7e109c8eb0836dc0a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9bfbf94ee8f84849beb7a719b3170dc4b989dc1b988cb1b4b6b2dba0bab41ea2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a26e2f9fdb44629c5e478845bc227fe2efe7354b1e1e01f84214e9b2c36fe6edaea6d95e17c25a333ecad911bb203e5321192ffd5a3ebd9d66da283413a70608
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b936990fa4c104841742c5cc1bb11c791e7c96b98585ffe29cb08dc42729eece6aaa06c8ca935545e7e5ad67d3d3c933673c1ea7f3e92f49097f20b75d6c68dc
         
     | 
    
        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/ddb.rb
    CHANGED
    
    | 
         @@ -48,28 +48,67 @@ module Mdq 
     | 
|
| 
       48 
48 
     | 
    
         
             
                  adb_command("shell screencap -p #{file}", udid)
         
     | 
| 
       49 
49 
     | 
    
         
             
                  adb_command("pull #{file} #{output}", udid)
         
     | 
| 
       50 
50 
     | 
    
         
             
                  adb_command("adb shell rm #{file}")
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  puts "# Screenshot of #{udid} to #{output}"
         
     | 
| 
       51 
53 
     | 
    
         
             
                end
         
     | 
| 
       52 
54 
     | 
    
         | 
| 
       53 
55 
     | 
    
         
             
                def app_install(input, udid, is_android)
         
     | 
| 
       54 
     | 
    
         
            -
                  if is_android && input.end_with?('.apk')
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       59 
63 
     | 
    
         
             
                end
         
     | 
| 
       60 
64 
     | 
    
         | 
| 
       61 
65 
     | 
    
         
             
                def app_uninstall(input, udid, is_android)
         
     | 
| 
       62 
66 
     | 
    
         
             
                  if is_android
         
     | 
| 
       63 
     | 
    
         
            -
                    adb_command("uninstall #{input}", udid)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    output, = adb_command("uninstall #{input}", udid)
         
     | 
| 
       64 
68 
     | 
    
         
             
                  else
         
     | 
| 
       65 
     | 
    
         
            -
                    apple_command("device uninstall app #{input}", udid)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    output, = apple_command("device uninstall app #{input}", udid)
         
     | 
| 
       66 
70 
     | 
    
         
             
                  end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  return unless output
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  puts "# Uninstall #{input} from #{udid}"
         
     | 
| 
      
 75 
     | 
    
         
            +
                  puts output
         
     | 
| 
       67 
76 
     | 
    
         
             
                end
         
     | 
| 
       68 
77 
     | 
    
         | 
| 
       69 
78 
     | 
    
         
             
                private
         
     | 
| 
       70 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
                # ADBコマンド
         
     | 
| 
      
 81 
     | 
    
         
            +
                def adb_command(arg, udid = nil)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  command = if udid.nil?
         
     | 
| 
      
 83 
     | 
    
         
            +
                              "adb #{arg}"
         
     | 
| 
      
 84 
     | 
    
         
            +
                            else
         
     | 
| 
      
 85 
     | 
    
         
            +
                              "adb -s #{udid} #{arg}"
         
     | 
| 
      
 86 
     | 
    
         
            +
                            end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 89 
     | 
    
         
            +
                    Open3.capture3(command)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  rescue StandardError
         
     | 
| 
      
 91 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 92 
     | 
    
         
            +
                  end
         
     | 
| 
      
 93 
     | 
    
         
            +
                end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                # devicectlコマンド
         
     | 
| 
      
 96 
     | 
    
         
            +
                def apple_command(arg, udid = nil)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  command = if udid.nil?
         
     | 
| 
      
 98 
     | 
    
         
            +
                              "xcrun devicectl #{arg}"
         
     | 
| 
      
 99 
     | 
    
         
            +
                            else
         
     | 
| 
      
 100 
     | 
    
         
            +
                              "xcrun devicectl #{arg} --device #{udid}"
         
     | 
| 
      
 101 
     | 
    
         
            +
                            end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 104 
     | 
    
         
            +
                    Open3.capture3(command)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  rescue StandardError
         
     | 
| 
      
 106 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
       71 
110 
     | 
    
         
             
                # Androidデバイス一覧を取得する
         
     | 
| 
       72 
     | 
    
         
            -
                def android_discover
         
     | 
| 
      
 111 
     | 
    
         
            +
                def android_discover # rubocop:disable Metrics/AbcSize
         
     | 
| 
       73 
112 
     | 
    
         
             
                  output, = adb_command('devices -l')
         
     | 
| 
       74 
113 
     | 
    
         
             
                  return if output.nil?
         
     | 
| 
       75 
114 
     | 
    
         | 
| 
         @@ -82,10 +121,10 @@ module Mdq 
     | 
|
| 
       82 
121 
     | 
    
         
             
                    authorized = line.index('unauthorized').nil?
         
     | 
| 
       83 
122 
     | 
    
         | 
| 
       84 
123 
     | 
    
         
             
                    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)
         
     | 
| 
      
 124 
     | 
    
         
            +
                      model, = adb_command('shell getprop ro.product.model', udid)
         
     | 
| 
      
 125 
     | 
    
         
            +
                      build_version, = adb_command('shell getprop ro.build.version.release', udid)
         
     | 
| 
      
 126 
     | 
    
         
            +
                      build_id, = adb_command('shell getprop ro.build.id', udid)
         
     | 
| 
      
 127 
     | 
    
         
            +
                      name, = adb_command('shell settings get global device_name', udid)
         
     | 
| 
       89 
128 
     | 
    
         
             
                      battery_level = nil
         
     | 
| 
       90 
129 
     | 
    
         
             
                      total_capacity = nil
         
     | 
| 
       91 
130 
     | 
    
         
             
                      free_capacity = nil
         
     | 
| 
         @@ -111,11 +150,11 @@ module Mdq 
     | 
|
| 
       111 
150 
     | 
    
         
             
                      Device.create({
         
     | 
| 
       112 
151 
     | 
    
         
             
                                      udid: udid,
         
     | 
| 
       113 
152 
     | 
    
         
             
                                      serial_number: udid,
         
     | 
| 
       114 
     | 
    
         
            -
                                      name: name,
         
     | 
| 
      
 153 
     | 
    
         
            +
                                      name: name.strip,
         
     | 
| 
       115 
154 
     | 
    
         
             
                                      authorized: true,
         
     | 
| 
       116 
     | 
    
         
            -
                                      model: model,
         
     | 
| 
       117 
     | 
    
         
            -
                                      build_version: build_version,
         
     | 
| 
       118 
     | 
    
         
            -
                                      build_id: build_id,
         
     | 
| 
      
 155 
     | 
    
         
            +
                                      model: model.strip,
         
     | 
| 
      
 156 
     | 
    
         
            +
                                      build_version: build_version.strip,
         
     | 
| 
      
 157 
     | 
    
         
            +
                                      build_id: build_id.strip,
         
     | 
| 
       119 
158 
     | 
    
         
             
                                      battery_level: battery_level,
         
     | 
| 
       120 
159 
     | 
    
         
             
                                      total_capacity: total_capacity,
         
     | 
| 
       121 
160 
     | 
    
         
             
                                      free_capacity: free_capacity,
         
     | 
| 
         @@ -132,48 +171,11 @@ module Mdq 
     | 
|
| 
       132 
171 
     | 
    
         
             
                  end
         
     | 
| 
       133 
172 
     | 
    
         
             
                end
         
     | 
| 
       134 
173 
     | 
    
         | 
| 
       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 
174 
     | 
    
         
             
                # Appleデバイス一覧を取得する
         
     | 
| 
       168 
175 
     | 
    
         
             
                def apple_discover
         
     | 
| 
       169 
176 
     | 
    
         
             
                  file = [Dir.home, '.mdq.json'].join(File::Separator)
         
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
                   
     | 
| 
       172 
     | 
    
         
            -
                    Open3.capture3("xcrun devicectl list devices -v -j #{file}")
         
     | 
| 
       173 
     | 
    
         
            -
                  rescue StandardError
         
     | 
| 
       174 
     | 
    
         
            -
                    return
         
     | 
| 
       175 
     | 
    
         
            -
                  end
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
      
 177 
     | 
    
         
            +
                  result = apple_command("list devices -v -j #{file}")
         
     | 
| 
      
 178 
     | 
    
         
            +
                  return if result.nil?
         
     | 
| 
       177 
179 
     | 
    
         
             
                  return unless File.exist?(file)
         
     | 
| 
       178 
180 
     | 
    
         | 
| 
       179 
181 
     | 
    
         
             
                  File.open(file, 'r') do |f|
         
     | 
    
        data/lib/mdq/list.rb
    CHANGED
    
    | 
         @@ -24,7 +24,7 @@ module Mdq 
     | 
|
| 
       24 
24 
     | 
    
         
             
                    is_android = model.platform == 'Android'
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
                    ddb.device_screencap(options[:cap], udid, is_android) if options[:cap]
         
     | 
| 
       27 
     | 
    
         
            -
                    ddb.app_install(options[:install], udid) if options[:install]
         
     | 
| 
      
 27 
     | 
    
         
            +
                    ddb.app_install(options[:install], udid, is_android) if options[:install]
         
     | 
| 
       28 
28 
     | 
    
         
             
                    ddb.app_uninstall(options[:uninstall], udid, is_android) if options[:uninstall]
         
     | 
| 
       29 
29 
     | 
    
         
             
                  rescue StandardError
         
     | 
| 
       30 
30 
     | 
    
         
             
                    # none
         
     | 
    
        data/lib/mdq/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2025-05-20 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rubocop
         
     |