rubtools 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 757ab083dd3a5fa2b77ee2af9d468da6cd1a09a3
4
- data.tar.gz: 449d81e9fd91d84a24e9daf7af232eb382642aec
3
+ metadata.gz: f3bc054e20d4ffff30df38666dde16f6f8f25ceb
4
+ data.tar.gz: 8d463efd7f20b3031002690284b65754bd7cbdaa
5
5
  SHA512:
6
- metadata.gz: eb8fc0176d679be081b2cc4de592f15ca8cf13f052f56110a463c308b267d10f34d6991df836352dfc3b6491e1be416d811cc47202b9da96acbc4c4cdf18dad0
7
- data.tar.gz: e5f720c0771623e33ed74c9fcdd59ac242222a2ee06b3d5a1885d9348d3a1c3de3871e928a66f956f5d3c53d4c94dc8a48c49ba88edbf117318c4fd7abfdecda
6
+ metadata.gz: c297f58e745371f96f8ac0f60bcea878490167c931e940cc0e13664c32ce4a0262751e54b037d8026fd1dc724be8b4572dbe8558663df6c54ef790d705099bce
7
+ data.tar.gz: d53f8952318a85cd440abee959d189193459a3549ffc76ba209a56d379d678167fee974302549fa1a05a84e83022bf51b04522042050835908872046a892f6ce
@@ -1,22 +1,65 @@
1
+ require "open3"
2
+
1
3
  module Rubtools
2
4
  class Recipe
3
- attr_accessor :options, :config
5
+ attr_accessor :available_methods, :options, :config
6
+
7
+ def self.register_methods methods
8
+ @available_methods = methods
9
+ end
10
+
11
+ def self.available_methods
12
+ @available_methods ? @available_methods : []
13
+ end
14
+
15
+ ## Override new method to initialize recipes objects without config and options
16
+ #
17
+ def self.new config, options, *args, &blk
18
+ object = allocate
19
+ object.config = config
20
+ object.options = options
21
+ object.instance_eval { initialize( *args, &blk ) }
22
+ object
23
+ end
4
24
 
5
25
  # Exec without output
6
26
  #
7
- def exec_without_output args
8
- success "$ " + args if @options[:verbose]
9
- return `#{args}`
27
+ def exec_without_output cmd, &block
28
+ success "$ " + cmd if @options[:verbose]
29
+
30
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
31
+ exit_status = wait_thr.value
32
+
33
+ if block
34
+ block.call exit_status
35
+ end
36
+
37
+ return stdout
38
+ end
39
+
40
+ return nil
10
41
  end
11
42
 
12
43
  # Exec with output
13
44
  #
14
- def exec args
15
- success "$ " + args if @options[:verbose]
16
- output = `#{args}`
17
- verbose "> " + output
45
+ def exec cmd, &block
46
+ success "$ " + cmd if @options[:verbose]
47
+
48
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
49
+ while line = stdout.gets
50
+ verbose line
51
+ end
52
+
53
+ exit_status = wait_thr.value
54
+
55
+ if block
56
+ block.call exit_status
57
+ end
18
58
 
19
- return output
59
+ return stdout
60
+ end
61
+
62
+ return nil
20
63
  end
21
64
 
22
65
  ## Get operating system name
@@ -39,10 +82,28 @@ module Rubtools
39
82
  )
40
83
  end
41
84
 
85
+ ## Cross-platform way of finding an executable in the $PATH.
86
+ #
87
+ def which cmd
88
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
89
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
90
+ exts.each do |ext|
91
+ exe = File.join(path, "#{cmd}#{ext}")
92
+ return exe if File.executable? exe
93
+ end
94
+ end
95
+ return nil
96
+ end
97
+
42
98
  ## Helper to symlink
43
99
  #
44
100
  def symlink source, dest
45
- FileUtils.symlink source, dest, verbose: true, force: true
101
+ FileUtils.rm dest, verbose: true if File.exists?(dest)
102
+ if File.exists?(source)
103
+ FileUtils.ln_s source, dest, verbose: true, force: true
104
+ else
105
+ raise FileNotFoundException.new("File #{source} not found")
106
+ end
46
107
  end
47
108
 
48
109
  # Print success arguments
@@ -1,3 +1,3 @@
1
1
  module Rubtools
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/rubtools.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'fileutils'
2
2
  require 'optparse'
3
- require "debugger"
4
3
  require 'yaml'
5
4
  require "ostruct"
6
5
  require "recursive-open-struct"
@@ -82,11 +81,7 @@ module Rubtools
82
81
  for constant in Rubtools::Tools.constants
83
82
  @tools[constant.downcase] = Array.new
84
83
 
85
- methods = Array.new
86
- methods << Rubtools::Tools.const_get(constant).public_instance_methods(false)
87
- methods << Rubtools::Tools.const_get(constant).protected_instance_methods
88
-
89
- for method in methods.flatten
84
+ for method in Rubtools::Tools.const_get(constant).available_methods
90
85
  method_hash = Hash.new
91
86
  method_hash[method] = Array.new
92
87
 
@@ -102,12 +97,12 @@ module Rubtools
102
97
  Logger.verbose "Available commands: \n\n"
103
98
  for constant in @tools.keys
104
99
  for method_hash in @tools[constant]
105
- params = "(#{method_hash.first.last.join(", ")})" if method_hash.first.last.any?
100
+ params = method_hash.first.last.any? ? "(#{method_hash.first.last.join(", ")})" : nil
106
101
  Logger.success "#{constant}:#{method_hash.keys.first}#{params}"
107
102
  end
108
103
 
109
104
  if @tools[constant].any? && @tools.keys.last != constant
110
- Logger.verbose "--------------------------"
105
+ Logger.verbose "\n"
111
106
  end
112
107
  end
113
108
  exit
@@ -128,9 +123,7 @@ module Rubtools
128
123
 
129
124
  begin
130
125
  Logger.verbose "Calling #{constant}::#{method}..."
131
- object = Rubtools::Tools.const_get(constant).new
132
- object.options = @options
133
- object.config = @config
126
+ object = Rubtools::Tools.const_get(constant).new @config, @options
134
127
 
135
128
  if @args.any?
136
129
  object.method(method).call @args
@@ -139,8 +132,10 @@ module Rubtools
139
132
  end
140
133
  rescue Interrupt
141
134
  Logger.verbose "Interrupted"
142
- rescue Exception => e
135
+ rescue NameError => e
143
136
  Logger.error e.message
137
+ rescue ArgumentError => e
138
+ Logger.error "#{e.class} => #{e.message}"
144
139
  for backtrace in e.backtrace
145
140
  Logger.error backtrace
146
141
  end
data/lib/tools/android.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Rubtools
2
2
  module Tools
3
3
  class Android < Rubtools::Recipe
4
+ register_methods %w(devices remove uninstall)
4
5
 
5
6
  # Initialize the Android recipe
6
7
  #
data/lib/tools/git.rb CHANGED
@@ -1,19 +1,74 @@
1
1
  module Rubtools
2
2
  module Tools
3
3
  class Git < Rubtools::Recipe
4
+ register_methods %w(clone_all up_all print_repos)
4
5
 
5
- # Initialize the Android recipe
6
- #
7
6
  def initialize
8
- @git = "git"
7
+ @git = which "git"
8
+
9
+ @git_config = config.git
10
+ raise "Add the key 'git' in the config file" unless @git_config
11
+
12
+ @install_dir = @git_config.install_dir
13
+ raise "Add the key install_dir: /path/to/folder" unless @install_dir
14
+ raise "Git isn't installed" unless @git
15
+ raise "Folder doesn't exists: #{@install_dir}" unless File.exists? @install_dir
16
+ end
17
+
18
+ ## Print all repositories
19
+ def print_repos
20
+ for repo in config.git.repositories
21
+ success "#{repo.name}\t#{repo.url}"
22
+ end
9
23
  end
10
24
 
25
+ ## Cloning all repositories located into rubtools.yml
26
+ #
11
27
  def clone_all
12
- puts @config.git.repos
28
+ for repo in config.git.repositories
29
+ clone repo
30
+ end
13
31
  end
14
32
 
33
+ ## Pull all repositories located into rubtools.yml
34
+ #
15
35
  def up_all
16
- puts @config.git.repos
36
+ for repo in config.git.repositories
37
+ up repo
38
+ end
39
+ end
40
+
41
+ private
42
+ ## Cloning a specific repository
43
+ #
44
+ def clone repo
45
+ repo_path = File.join @install_dir, repo.name
46
+
47
+ unless File.exists? repo_path
48
+ success "Cloning #{repo.name} from #{repo.url}"
49
+ exec "#{@git} clone --recursive #{repo.url} #{repo_path}" do |status|
50
+ success "> done" if status.success?
51
+ end
52
+ else
53
+ success "Repository #{repo.name} already cloned"
54
+ end
55
+ end
56
+
57
+
58
+ ## Pulling a specific repository
59
+ #
60
+ def up repo
61
+ repo_path = File.join @install_dir, repo.name
62
+
63
+ if File.exists? repo_path
64
+ success "Pulling #{repo.name} repository"
65
+ exec "GIT_DIR=#{File.join(repo_path, ".git")} #{@git} pull --recurse-submodules=yes" do |status|
66
+ success "> done" if status.success?
67
+ end
68
+ else
69
+ error "Repository #{repo.name} doensn't exists"
70
+ clone repo
71
+ end
17
72
  end
18
73
  end
19
74
  end
data/lib/tools/svn.rb ADDED
@@ -0,0 +1,76 @@
1
+ module Rubtools
2
+ module Tools
3
+ class Svn < Rubtools::Recipe
4
+ register_methods %w(co_all up_all print_repos)
5
+
6
+ def initialize
7
+ @svn = which "svn"
8
+
9
+ @svn_config = config.svn
10
+ raise "Add the key 'svn' in the config file" unless @svn_config
11
+
12
+ @install_dir = @svn_config.install_dir
13
+ raise "Add the key install_dir: /path/to/folder in the config file" unless @install_dir
14
+ raise "Subversion isn't installed" unless @svn
15
+ raise "Folder doesn't exists: #{@install_dir}" unless File.exists? @install_dir
16
+ end
17
+
18
+ ## Print all repositories
19
+ def print_repos
20
+ for repo in config.svn.repositories
21
+ success "#{repo.name}\t#{repo.url}"
22
+ end
23
+ end
24
+
25
+ ## Cloning all repositories located into rubtools.yml
26
+ #
27
+ def co_all
28
+ for repo in config.svn.repositories
29
+ co repo
30
+ end
31
+ end
32
+
33
+ ## Pull all repositories located into rubtools.yml
34
+ #
35
+ def up_all
36
+ for repo in config.svn.repositories
37
+ up repo
38
+ end
39
+ end
40
+
41
+ private
42
+ ## Cloning a specific repository
43
+ #
44
+ def co repo
45
+ repo_path = File.join @install_dir, repo.name
46
+
47
+ unless File.exists? repo_path
48
+ success "Checkouting #{repo.name} from #{repo.url}"
49
+ exec("#{@svn} checkout #{repo.url} #{repo_path}") do |status|
50
+ success "> done" if status.success?
51
+ end
52
+ else
53
+ success "Repository #{repo.name} already checkout"
54
+ end
55
+ end
56
+
57
+
58
+ ## Pulling a specific repository
59
+ #
60
+ def up repo
61
+ repo_path = File.join @install_dir, repo.name
62
+
63
+ if File.exists? repo_path
64
+ success "Updating #{repo.name} repository"
65
+ exec "#{@svn} update #{repo.url}" do |status|
66
+ success "> done" if status.success?
67
+ end
68
+ else
69
+ error "Repository #{repo.name} doensn't exists"
70
+ co repo
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre FILSTROFF
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-06 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -115,6 +115,7 @@ files:
115
115
  - lib/rubtools/version.rb
116
116
  - lib/tools/android.rb
117
117
  - lib/tools/git.rb
118
+ - lib/tools/svn.rb
118
119
  - rubtools.gemspec
119
120
  homepage: ''
120
121
  licenses: