rubtools 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 357520850e728ad030757d8583e17648d33ab473
4
+ data.tar.gz: 4edeb35d5e50ef863195858c43e9a2a8437e016f
5
+ SHA512:
6
+ metadata.gz: 2bf75d14a8ad493b9e81ae69ac2e6f315ee25b671585a829fc6290041c6141aed9134539bd2c73fda6a28cd7fdcf5d5cbb2c1dc9b90c43fd53c2b4d48ef75e1d
7
+ data.tar.gz: 7ef15604ba351d8be003753e30eaf8774a848362db90dc90f56dd96e061f2d840d065f0783a5c70350dc7a695f9edbd6fef01076c7ce918ecf204d3f97f0dc01
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubtools.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pierre FILSTROFF
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rubtools
2
+
3
+ rubTools lets you create command line tasks easily
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubtools'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubtools
18
+
19
+ ## Usage
20
+
21
+ $ rt android:uninstall com.project
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rt ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rubtools'
5
+
6
+ rt = Rubtools::Runner.new(ARGV)
7
+ rt.run!
@@ -0,0 +1,24 @@
1
+ require 'colorize'
2
+
3
+ module Rubtools
4
+ class Logger
5
+
6
+ # Print success string
7
+ #
8
+ def self.success(arg)
9
+ puts arg.colorize(:green)
10
+ end
11
+
12
+ # Print info string
13
+ #
14
+ def self.info(arg)
15
+ puts arg
16
+ end
17
+
18
+ # Print error string
19
+ #
20
+ def self.error(arg)
21
+ puts arg.colorize(:red)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Rubtools
2
+ class Recipe
3
+ attr_writer :options
4
+
5
+ # Exec without output
6
+ #
7
+ def exec_without_output(args)
8
+ Logger.success "$ " + args if @options[:verbose]
9
+ return `#{args}`
10
+ end
11
+
12
+ # Exec with output
13
+ #
14
+ def exec(args)
15
+ Logger.success "$ " + args if @options[:verbose]
16
+ output = `#{args}`
17
+ Logger.info "> " + output
18
+
19
+ return output
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,3 @@
1
+ module Rubtools
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rubtools.rb ADDED
@@ -0,0 +1,109 @@
1
+ require "rubtools/version"
2
+ require "rubtools/recipe"
3
+ require "rubtools/logger"
4
+ require 'optparse'
5
+ require "debugger"
6
+
7
+ module Rubtools
8
+ class Runner
9
+ attr_accessor :args, :tool_libs, :options, :tools
10
+
11
+ # Initialize the rubtool
12
+ # - Find all recipes
13
+ # - Parse options
14
+ #
15
+ def initialize(args)
16
+ @args = args
17
+ @options = Hash.new
18
+ @tools = Hash.new
19
+ @matches = Array.new
20
+
21
+ @tool_libs = Dir.glob(File.join(File.dirname(__FILE__), 'tools', '**', '*.rb'))
22
+ @tool_libs.each {|lib| require lib }
23
+
24
+ option_parser = OptionParser.new do |opts|
25
+ opts.banner = "Usage: rt constant:method [options]"
26
+
27
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
28
+ @options[:verbose] = v
29
+ end
30
+
31
+ opts.separator ""
32
+ opts.separator "Common options:"
33
+
34
+ opts.on_tail("-h", "--help", "Show help") do
35
+ Logger.info opt
36
+ exit
37
+ end
38
+
39
+ opts.on_tail("--version", "Show rubTools version") do
40
+ Logger.info Rubtools::VERSION
41
+ exit
42
+ end
43
+ end
44
+
45
+ begin
46
+ option_parser.parse!(args)
47
+ raise ArgumentError, "missing arguments" unless @args.any?
48
+ rescue OptionParser::InvalidOption, ArgumentError => e
49
+ Logger.info e.message
50
+ Logger.info option_parser
51
+ exit
52
+ end
53
+ end
54
+
55
+ # Run!
56
+ # - Find the best constant method passed in parameter
57
+ # - Execute the method
58
+ #
59
+ def run!
60
+ req_const_method = @args.shift.downcase
61
+ values = req_const_method.split(/\W/)
62
+
63
+ if values.size == 1
64
+ req_method = values.flatten[0]
65
+ elsif values.size == 2
66
+ req_constant = values.flatten[0]
67
+ req_method = values.flatten[1]
68
+ end
69
+
70
+ # Searching in tools libraries the method to call
71
+ for constant in Rubtools::Tools.constants
72
+ @tools[constant] = Array.new
73
+
74
+ for method in Rubtools::Tools.const_get(constant).instance_methods(false)
75
+ @tools[constant] << method
76
+ end
77
+ end
78
+
79
+ for constant in @tools.keys
80
+ for method in @tools[constant]
81
+ if (req_method == method.to_s.downcase && req_constant == constant.to_s.downcase) || req_method == method.to_s.downcase
82
+ @matches << [constant, method]
83
+ end
84
+ end
85
+ end
86
+
87
+ if @matches.any?
88
+ constant = @matches.first[0]
89
+ method = @matches.first[1]
90
+
91
+ Logger.info "Calling #{constant}::#{method}..."
92
+ object = Rubtools::Tools.const_get(constant).new
93
+ object.options = @options
94
+
95
+ begin
96
+ if @args.any?
97
+ object.method(method).call @args
98
+ else
99
+ object.method(method).call
100
+ end
101
+ rescue ArgumentError => e
102
+ Logger.error "Method '#{method}' takes arguments: " + e.message
103
+ end
104
+ else
105
+ Logger.error "No recipe found..."
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,65 @@
1
+ module Rubtools
2
+ module Tools
3
+ class Android < Rubtools::Recipe
4
+ attr_accessor :adb
5
+
6
+ # Initialize the Android recipe
7
+ #
8
+ def initialize
9
+ @adb = "adb"
10
+ end
11
+
12
+ # Puts the list of available devices
13
+ #
14
+ def devices
15
+ puts get_devices()
16
+ end
17
+
18
+ # Remove packages
19
+ #
20
+ def remove(package)
21
+ uninstall(package)
22
+ end
23
+
24
+ # Uninstall packages
25
+ #
26
+ def uninstall(packages)
27
+ devices = get_devices()
28
+
29
+ if devices.any?
30
+ if devices.size > 1
31
+ Logger.info "There is more than one device:"
32
+ devices.each_with_index {|device, index| puts "#{index}: #{device}"}
33
+ print "Choose one: "
34
+
35
+ answer = STDIN.gets.chomp
36
+ begin
37
+ device = devices[Integer(answer)]
38
+ rescue ArgumentError => e
39
+ Logger.error "Error: Not a valid option (" + e.message + ")"
40
+ end
41
+ else
42
+ device = devices.first
43
+ end
44
+
45
+ if device
46
+ while packages.size > 0 do
47
+ exec(@adb + " -s " + device + " uninstall " + packages.pop)
48
+ end
49
+ end
50
+ else
51
+ Logger.error "No found devices..."
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # Get the list of available android
58
+ # devices
59
+ #
60
+ def get_devices
61
+ return exec_without_output(@adb + " devices").scan(/\n(.*?)\t/).flatten
62
+ end
63
+ end
64
+ end
65
+ end
data/rubtools.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubtools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubtools"
8
+ spec.version = Rubtools::VERSION
9
+ spec.authors = ["Pierre FILSTROFF"]
10
+ spec.email = ["pfilstroff@gmail.com"]
11
+ spec.description = %q{rubTools lets you create command line tasks easily}
12
+ spec.summary = %q{A commandline tools framework}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "colorize"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "debugger"
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubtools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pierre FILSTROFF
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: rubTools lets you create command line tasks easily
70
+ email:
71
+ - pfilstroff@gmail.com
72
+ executables:
73
+ - rt
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/rt
83
+ - lib/rubtools.rb
84
+ - lib/rubtools/logger.rb
85
+ - lib/rubtools/recipe.rb
86
+ - lib/rubtools/version.rb
87
+ - lib/tools/android.rb
88
+ - rubtools.gemspec
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.1.11
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: A commandline tools framework
113
+ test_files: []