android-command-line-tools 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbf03da4ca8b3036eec70e1f13c0952078ed79fc
4
+ data.tar.gz: 841473fd6501e7b97cbccee14ad92f43db03e129
5
+ SHA512:
6
+ metadata.gz: afa814085380a0012c84efcef9cc677e849957c591a3dbc2b7c940b700b7e97873b76a31f511a0b85be3bbf107717a5a316afb38da0533bcd7fd8f10a7aad53e
7
+ data.tar.gz: f0b76223ea15d01b43e66681774145aca8ab9d3e57c4e6e77c023c31421edd16f499c6e6b2896917de7aabc55f79c4579cc449b65bcf9928c8b2175a55eee682
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in android-command-line-tools.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tomoki Yamashita
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Android::Command::Line::Tools
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/android/command/line/tools`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'android-command-line-tools'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install android-command-line-tools
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomorrowkey/android-command-line-tools.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'android/command/line/tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'android-command-line-tools'
8
+ spec.version = Android::Command::Line::Tools::VERSION
9
+ spec.authors = ['Tomoki Yamashita']
10
+ spec.email = ['tomorrowkey@gmail.com']
11
+
12
+ spec.summary = %q{Useful command line tools for android developers}
13
+ spec.description = %q{Useful command line tools for android developers}
14
+ spec.homepage = 'https://github.com/tomorrowkey/android-command-line-tools'
15
+ spec.license = 'Apache License 2.0'
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'thor', '~> 0.19'
22
+ spec.add_dependency 'device_api-android', '~> 1.2'
23
+ spec.add_dependency 'peco_selector', '~> 1.0'
24
+ spec.add_development_dependency 'bundler', '~> 1.12'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'pry', '~> 0.0'
28
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'android/command/line/tools'
5
+ require 'pry'
6
+
7
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ require 'android/command/line/tools/version'
2
+ require 'android/command/line/tools/cli'
3
+ require 'pry'
4
+
5
+ module Android
6
+ module Command
7
+ module Line
8
+ module Tools
9
+ Tools::CLI.start
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,116 @@
1
+ require 'thor'
2
+ require 'device_api/android'
3
+ require 'peco_selector'
4
+ require 'find'
5
+
6
+ module Android
7
+ module Command
8
+ module Line
9
+ module Tools
10
+ class CLI < Thor
11
+ desc 'uninstall', 'Uninstall an application'
12
+ def uninstall
13
+ return (puts 'device not connected') unless device
14
+
15
+ packages = list_installed_packages(device)
16
+ package = select_installed_package(packages)
17
+ execute_with_serial('adb', device, "uninstall -r #{file}")
18
+ end
19
+
20
+ desc 'install', 'Install an application'
21
+ def install
22
+ return (puts 'device not connected') unless device
23
+
24
+ files = list_apk_files
25
+ return (puts 'apk file not found') if files.empty?
26
+
27
+ file = PecoSelector.select_from(files).first
28
+ execute_with_serial('adb', device, "install -r #{file}")
29
+ end
30
+
31
+ desc 'clear', 'Clear apps data'
32
+ def clear
33
+ return (puts 'device not connected') unless device
34
+
35
+ packages = list_installed_packages(device)
36
+ package = select_installed_package(packages)
37
+ execute_with_serial('adb', device, "shell pm clear #{package}")
38
+ end
39
+
40
+ desc 'screenshot', 'Take a screenshot'
41
+ def screenshot
42
+ return (puts 'device not connected') unless device
43
+
44
+ outfile = "#{ENV['HOME']}/Desktop/screenshot_#{timestamp}.png"
45
+ execute_with_serial('screenshot2', device, outfile)
46
+ execute("open #{outfile}")
47
+ end
48
+
49
+ # ffmpeg -y -i movie.mp4 -vf scale=360:-1 -r 12 movie_360.mp4
50
+ # ffmpeg -i movie_360.mp4 -vf palettegen=max_colors=256 palette.png
51
+ # ffmpeg -i movie_360.mp4 -i palette.png -f gif -filter_complex paletteuse movie.gif
52
+ desc 'screenrecord', 'Take a screenrecord'
53
+ def screenrecord
54
+ return (puts 'device not connected') unless device
55
+
56
+ device_movie_path = "/sdcard/Download/movie_#{timestamp}.mp4"
57
+ begin
58
+ execute_with_serial('adb', device, "shell screenrecord #{device_movie_path}")
59
+ rescue Interrupt
60
+ end
61
+
62
+ movie_path = Tempfile.new('movie_original').path + 'mp4'
63
+ execute_with_serial('adb', device, "pull #{device_movie_path} #{movie_path}")
64
+
65
+ resized_path = Tempfile.new('movie_resized').path + '.mp4'
66
+ execute("ffmpeg -y -i #{movie_path} -vf scale=360:-1 -r 12 -f mp4 #{resized_path}")
67
+ palette_path = Tempfile.new('movie_palette').path + '.png'
68
+ execute("ffmpeg -i #{resized_path} -vf palettegen=max_colors=256 #{palette_path}")
69
+ movie_path = "#{ENV['HOME']}/Desktop/movie_#{timestamp}.gif"
70
+ execute("ffmpeg -i #{resized_path} -i #{palette_path} -f gif -filter_complex paletteuse #{movie_path}")
71
+
72
+ execute("open #{movie_path}")
73
+ end
74
+
75
+ private
76
+ def execute_with_serial(command, device, options)
77
+ serial_option = device.nil? ? '' : "-s #{device.serial}"
78
+ execute("#{command} #{serial_option} #{options}")
79
+ end
80
+
81
+ def execute(command)
82
+ puts "+ #{command}"
83
+ system command
84
+ end
85
+
86
+ def device
87
+ return @device if @device
88
+
89
+ devices = DeviceAPI::Android.devices
90
+ return devices.first if devices.size <= 1
91
+
92
+ @device ||= PecoSelector.select_from(devices.map{|device|
93
+ ["#{device.model} (#{device.serial})", device]
94
+ }).first
95
+ end
96
+
97
+ def list_installed_packages(device)
98
+ device.list_installed_packages.map{|p| p.gsub('package:', '')}
99
+ end
100
+
101
+ def select_installed_package(packages)
102
+ PecoSelector.select_from(packages).first
103
+ end
104
+
105
+ def list_apk_files
106
+ Find.find(Dir.pwd).to_a.select{|f| f =~ /\.apk$/}
107
+ end
108
+
109
+ def timestamp
110
+ Time.now.strftime('%Y%m%d%H%M%S')
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,9 @@
1
+ module Android
2
+ module Command
3
+ module Line
4
+ module Tools
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: android-command-line-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomoki Yamashita
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: device_api-android
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: peco_selector
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.0'
111
+ description: Useful command line tools for android developers
112
+ email:
113
+ - tomorrowkey@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - android-command-line-tools.gemspec
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/android/command/line/tools.rb
129
+ - lib/android/command/line/tools/cli.rb
130
+ - lib/android/command/line/tools/version.rb
131
+ homepage: https://github.com/tomorrowkey/android-command-line-tools
132
+ licenses:
133
+ - Apache License 2.0
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Useful command line tools for android developers
155
+ test_files: []