radb 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ed515a06f15faa329ce1009f07ae9ab8e553693
4
+ data.tar.gz: 191a25e2435cfa6e05b6235990c841aa38d8e972
5
+ SHA512:
6
+ metadata.gz: 44a49b4d5dd651ead0dde323811d3ad445b492cd3162f0fc9e1fa9e1ef1638625aa5647666d5b27262413ab575ab95e0d67fffa5e5039f8ee234c706ae0a08c7
7
+ data.tar.gz: f0f954e4c529b8e10d59b929c906f423d03037dc5435c3a7d1bdda977f784ed2fb55593f12d79469745f2b3c2c3acc76018d631682007c4d37fdc2588ffa9a34
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in radb.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Radb
2
+
3
+ Radb is a gem that provide cli for some adb tasks in android device. It required `adb` for adb command set and `logcat-color` for better logcat output.
4
+
5
+ ## Installation
6
+
7
+ ### On Mac OSX
8
+
9
+ Install xcode command-line tool:
10
+
11
+ `$ xcode-select --install`
12
+
13
+ Install `adb`:
14
+
15
+ `$ bash <(curl https://raw.github.com/corbindavenport/nexus-tools/master/install.sh)`
16
+
17
+ Install `python, pip, ruby` through `homebrew`
18
+
19
+ Install `logcat-color` through `pip`
20
+
21
+ Install it yourself as:
22
+
23
+ `$ gem install radb`
24
+
25
+ ## Usage
26
+
27
+ At this version, `radb` provides 4 commands:
28
+
29
+ `$ radb pull <package>`: pull database and images data from app to PC
30
+ Example:
31
+ $ radb pull com.cloudjay.cjay -d cjay.db -i CJay
32
+ $ radb pull com.cloudjay.cjay -d cjay.db -i CJay -s <device serial>
33
+
34
+ `$ radb push <package>`: push database and images from PC to app
35
+ Example:
36
+ $ radb push com.cloudjay.cjay -d cjay.db -i CJay
37
+ $ radb push com.cloudjay.cjay -d cjay.db -i CJay -s <device serial>
38
+
39
+ `$ radb logcat <package>`: display logcat for specific app
40
+ Example:
41
+ $ radb logcat com.cloudjay.cjay
42
+ $ radb logcat com.cloudjay.cjay -s <device serial>
43
+
44
+ `$ radb otadebug`: enable ota debugging for android device.
45
+ Example:
46
+ $ radb otadebug
47
+ $ radb otadebug -s <device serial>
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/tieubao/radb/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'radb'
4
+ require 'fileutils'
5
+
6
+ # CONFIG_FILE = File.expand_path("~/.badb_config.yaml")
7
+ #
8
+ # def read_settings
9
+ # Settings.use :config_file
10
+ # Settings({:device_history => [],:aliases => {}})
11
+ # FileUtils.touch(CONFIG_FILE)
12
+ # Settings.read(CONFIG_FILE)
13
+ # end
14
+ #
15
+ # read_settings
16
+
17
+ Radb::Application.start(ARGV)
@@ -0,0 +1,124 @@
1
+ require "radb/version"
2
+ require "radb/helper"
3
+ require "thor"
4
+ include Radb
5
+
6
+ module Radb
7
+ class Application < Thor
8
+
9
+ include Thor::Actions
10
+ class_option :verbose, :type => :boolean
11
+
12
+ #
13
+ desc 'pull <package_name>', 'Pull database and images from android device'
14
+ long_desc <<-LONGDESC
15
+ `pull <package name>` will pull database and images from android device to your computer.
16
+
17
+ Example:
18
+ \x5> $ radb pull com.cloudjay.com -db cjay.db -i CJay
19
+ \x5>
20
+ LONGDESC
21
+ option :database, :type => :string, :desc => 'Database filename', :required => true, :aliases => "-d"
22
+ option :image_dir, :type => :string, :desc => 'Images directory', :required => true, :aliases => "-i"
23
+ option :serial, :type => :string, :desc => 'Device serial', :required => false, :aliases => '-s'
24
+ def pull(package)
25
+
26
+ target = get_target(options[:serial])
27
+ database_path = "/data/data/#{package}/databases/" + options[:database]
28
+ images_path = "/sdcard/DCIM/" + options[:image_dir]
29
+
30
+ say " > Pull database from " + database_path
31
+ run "adb #{which_one(target)} shell \"run-as #{package} chmod 666 #{database_path}\"", :verbose => false
32
+ run "adb #{which_one(target)} pull #{database_path}", :verbose => false
33
+ run "adb #{which_one(target)} shell \"run-as #{package} chmod 600 #{database_path}\"", :verbose => false
34
+
35
+ say " > Pull images from " + images_path
36
+ run "adb #{which_one(target)} pull #{images_path} #{options[:image_dir]} ", :verbose => false
37
+ end
38
+
39
+ #
40
+ desc 'push <package_name>', 'Push database and images to android device'
41
+ long_desc <<-LONGDESC
42
+ `push <package name>` will push database and images from your computer to android device.
43
+
44
+ Example:
45
+ \x5> $ radb push com.cloudjay.com -d cjay.db -i CJay/
46
+ \x5>
47
+ LONGDESC
48
+ option :database, :type => :string, :desc => 'Database filepath', :required => true, :aliases => "-d"
49
+ option :image_dir, :type => :string, :desc => 'Images directory', :required => true, :aliases => "-i"
50
+ option :serial, :type => :string, :desc => 'Device serial', :required => false, :aliases => '-s'
51
+ def push(package)
52
+
53
+ target = get_target(options[:serial])
54
+ database_dir = "/data/data/#{package}/databases/"
55
+ database_path = options[:database]
56
+ images_path = "/sdcard/DCIM/" + options[:image_dir]
57
+
58
+ say " > Push database from " + database_path + " to " + database_dir
59
+ run "adb #{which_one(target)} shell \"run-as #{package} chmod 666 #{database_dir}#{database_path}\"", :verbose => false
60
+ run "adb #{which_one(target)} push '#{database_path}' '#{database_dir}' ", :verbose => false
61
+ run "adb #{which_one(target)} shell \"run-as #{package} chmod 600 #{database_dir}#{database_path}\"", :verbose => false
62
+ run "adb #{which_one(target)} push '#{options[:image_dir]}' '#{images_path}'", :verbose => false
63
+ end
64
+
65
+ # Connect devices to PC
66
+ # Run command:
67
+ # `radb debug`
68
+ # 1. Show list devices
69
+ # 2. Choose device if there are many devices
70
+ # 3. Get chosen ip address
71
+ # 4. Enable ota debug
72
+ #
73
+ # Run command:
74
+ # `radb debug -s <serial>`
75
+ # 1. Get choose ip address
76
+ # 2. Enable ota debug
77
+ long_desc <<-LONGDESC
78
+ `otadebug -s <serial>` will enable ota debug.
79
+
80
+ Example:
81
+ \x5> $ radb otadebug -s 81f42e1
82
+ \x5>
83
+ LONGDESC
84
+ desc 'otadebug', 'Debug android device over the air'
85
+ option :serial, :type => :string, :desc => 'Device serial', :required => false, :aliases => '-s'
86
+ def otadebug
87
+ target = get_target(options[:serial])
88
+ ip = get_ipv4(target)
89
+ say "Target ip: " + ip
90
+ run "adb #{which_one(target)} tcpip 5555", :verbose => false
91
+ run "adb #{which_one(target)} connect #{ip}", :verbose => false
92
+ end
93
+
94
+ long_desc <<-LONGDESC
95
+ `logcat -s <serial>` will display logcat for specific device.
96
+
97
+ Example:
98
+ \x5> $ radb logcat -s 81f42e1
99
+ \x5>
100
+ LONGDESC
101
+ desc 'logcat <package_name>', 'Display logcat for specific device'
102
+ option :serial, :type => :string, :desc => 'Device serial', :required => false, :aliases => '-s'
103
+ def logcat(package)
104
+ target = get_target(options[:serial])
105
+ process_id = %x(adb #{which_one(target)} shell ps | grep #{package} | cut -c10-15)
106
+
107
+ if command?("logcat-color")
108
+ s = "logcat-color #{which_one(target)} \"*:I\""
109
+ else
110
+ puts "You should install `logcat-color` for better output"
111
+ s = "adb #{which_one(target)} \"*:I\""
112
+ end
113
+
114
+ if process_id.empty?
115
+ say "Cannot found #{package}. It will print all logs."
116
+ else
117
+ s = s + " | grep #{process_id}"
118
+ end
119
+
120
+ run s, :verbose => false
121
+ rescue
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,133 @@
1
+ require 'highline/import'
2
+ require 'configliere'
3
+ require 'fileutils'
4
+ require 'childprocess'
5
+ require 'tempfile'
6
+ require 'date'
7
+
8
+ module Radb
9
+
10
+ attr_reader :last_stdout, :last_stderr
11
+
12
+ CONFIG_FILE = File.expand_path("~/.badb_config.yaml")
13
+
14
+ def adb_path
15
+ return @adb_path if @adb_path
16
+ @adb_path = `which adb`.strip
17
+ if @adb_path.empty?
18
+ raise "Can't find your adb command. Is your path set\?"
19
+ end
20
+ @adb_path
21
+ end
22
+
23
+ def get_devices
24
+ devices = []
25
+ IO.popen("#{adb_path} devices").each_line do |line|
26
+ line = line.strip
27
+ if line =~ /^(.*)\tdevice$/
28
+ devices << $1
29
+ end
30
+ end
31
+ devices
32
+ end
33
+
34
+ def get_target(serial)
35
+
36
+ if serial
37
+ device = serial
38
+ else
39
+ device = choose_device
40
+ end
41
+
42
+ if device.nil?
43
+ raise "Device not found"
44
+ end
45
+
46
+ target = { :serial => device }
47
+ return target
48
+ end
49
+
50
+ def which_one(target)
51
+ direct = ''
52
+ direct = '-d' if target[:device]
53
+ direct = '-e' if target[:emulator]
54
+ direct = "-s #{target[:serial]}" if target[:serial]
55
+ direct
56
+ end
57
+
58
+ def get_ipv4(target={})
59
+
60
+ lines = %x(adb #{which_one(target)} shell ip -f inet addr show wlan0)
61
+ lines.each_line do |line|
62
+ line.strip
63
+ if line =~ /inet (.*)\/24/
64
+ return $1
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ def choose_device()
71
+ devices = get_devices
72
+
73
+ if devices.empty?
74
+ raise "No devices attached"
75
+
76
+ elsif devices.size == 1
77
+ # yield devices[0] if block_given?
78
+ return devices[0]
79
+ else
80
+ choose do |menu|
81
+ menu.prompt = "Choose your adb device: "
82
+ devices.each do |device|
83
+ menu.choice device do
84
+ # yield device if block_given?
85
+ return device
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ def current_device
93
+
94
+ devices = get_devices
95
+ return devices[0] if devices.size == 1
96
+ return nil
97
+ end
98
+
99
+ def list_devices
100
+ devices = get_devices
101
+
102
+ puts "List of devices: "
103
+ devices.each do |d|
104
+ puts d
105
+ end
106
+ end
107
+
108
+ def command?(name)
109
+ `which #{name}`
110
+ $?.success?
111
+ end
112
+
113
+ #
114
+ def execute_adb_with(timeout, arguments)
115
+ args = arguments.split
116
+ execute_adb_with_exactly timeout, *args
117
+ end
118
+
119
+ def execute_adb_with_exactly(timeout, *arguments)
120
+
121
+ process = ChildProcess.build('adb', *arguments)
122
+ process.io.stdout, process.io.stderr = std_out_err
123
+ process.start
124
+
125
+ kill_if_longer_than(process, timeout)
126
+ @last_stdout = output(process.io.stdout)
127
+ @last_stderr = output(process.io.stderr)
128
+ end
129
+
130
+ def wait_for_device(target={}, timeout=30)
131
+ execute_adb_with(timeout, "#{which_one(target)} wait-for-device")
132
+ end
133
+ end
@@ -0,0 +1,3 @@
1
+ module Radb
2
+ VERSION = "0.0.3"
3
+ end
@@ -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 'radb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "radb"
8
+ spec.version = Radb::VERSION
9
+ spec.authors = ["tieubao"]
10
+ spec.email = ["nntruonghan@gmail.com"]
11
+ spec.summary = %q{A cli utilities which wrap Android Debug Bridge}
12
+ spec.description = %q{radb provides some commands that helps non-geeks take advantage on android devices}
13
+ spec.homepage = "https://github.com/tieubao/radb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency 'thor', '>= 0.18'
24
+ spec.add_dependency 'highline', ">= 0"
25
+ spec.add_dependency 'configliere', ">= 0"
26
+ spec.add_dependency 'childprocess', '>= 0.3.5'
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - tieubao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0.18'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
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
+ - !ruby/object:Gem::Dependency
70
+ name: configliere
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: childprocess
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.5
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.5
97
+ description: radb provides some commands that helps non-geeks take advantage on android
98
+ devices
99
+ email:
100
+ - nntruonghan@gmail.com
101
+ executables:
102
+ - radb
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/radb
112
+ - lib/radb.rb
113
+ - lib/radb/helper.rb
114
+ - lib/radb/version.rb
115
+ - radb.gemspec
116
+ homepage: https://github.com/tieubao/radb
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: A cli utilities which wrap Android Debug Bridge
140
+ test_files: []