joekhoobyar-capsaicin 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 4
4
2
  :major: 0
3
+ :minor: 1
4
+ :patch: 5
@@ -33,6 +33,10 @@ module Capsaicin
33
33
  cp from, to
34
34
  end
35
35
 
36
+ def put(from, to)
37
+ copy_stream StringIO.new(from), to
38
+ end
39
+
36
40
  def cd(dir, options={})
37
41
  if block_given?
38
42
  dir, dir2 = pwd, dir
@@ -45,7 +49,7 @@ module Capsaicin
45
49
  def tar_c(dest, src, options={}, &filter)
46
50
  logger and
47
51
  logger.trace "tar -cf #{dest} " + Array(src).map { |s| s.gsub ' ', '\\ ' }.join(' ')
48
- _tar File.open(dest, 'wb'), src, v, &filter
52
+ _tar File.open(dest, 'wb'), src, options, &filter
49
53
  end
50
54
 
51
55
  def tar_cz(dest, src, options={}, &filter)
@@ -55,16 +59,22 @@ module Capsaicin
55
59
  _tar Zlib::GzipWriter.new(File.open(dest, 'wb')), src, options, &filter
56
60
  end
57
61
 
62
+ def tar_t(src, options={}, &block)
63
+ logger and logger.trace "tar -tf #{src}"
64
+ _lstar File.open(src, 'wb'), options, &block
65
+ end
66
+
67
+ def tar_tz(src, options={}, &block)
68
+ require 'zlib' unless defined? Zlib::GzipWriter
69
+ logger and logger.trace "tar -tzf #{src}"
70
+ _lstar Zlib::GzipReader.new(File.open(src, 'rb')), options, &block
71
+ end
72
+
58
73
  private
59
74
 
60
75
  def _tar(os, src, options, &filter)
61
76
  verbose = options[:v] || options[:verbose]
62
- require 'find' unless defined? Find
63
- unless defined? Archive::Tar::Minitar
64
- require 'archive/tar/minitar'
65
- end
66
- minitar = Archive::Tar::Minitar
67
-
77
+ minitar = _minitar
68
78
  minitar::Output.open os do |outp|
69
79
  Array(src).each do |path|
70
80
  Find.find(path) do |entry|
@@ -78,6 +88,45 @@ module Capsaicin
78
88
  end
79
89
  end
80
90
  end
91
+
92
+ def _untar(is, dest, files=[], options={}, &callback)
93
+ verbose = options[:v] || options[:verbose]
94
+ minitar = _minitar
95
+ minitar::Input.open is do |inp|
96
+ if File.exist?(dest) and ! File.directory?(dest)
97
+ raise "Can't unpack to a non-directory."
98
+ elsif ! File.exist? dest
99
+ FileUtils.mkdir_p dest
100
+ end
101
+ inp.each do |entry|
102
+ logger.trace " - #{entry}" if verbose
103
+ if files.empty? or files.include?(entry.full_name)
104
+ inp.extract_entry(dest, entry, &callback)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ def _lstar(is, options={}, &block)
111
+ verbose = options[:v] || options[:verbose]
112
+ files, minitar = [], _minitar
113
+ minitar::Input.open is do |inp|
114
+ inp.each do |entry|
115
+ if block.nil? then files << entry else
116
+ f = block[entry]
117
+ files << f unless f.nil?
118
+ end
119
+ logger.trace " - #{entry}" if verbose
120
+ end
121
+ end
122
+ files
123
+ end
124
+
125
+ def _minitar
126
+ require 'find' unless defined? Find
127
+ require 'archive/tar/minitar' unless defined? Archive::Tar::Minitar
128
+ Archive::Tar::Minitar
129
+ end
81
130
  end
82
131
  end
83
132
  end
@@ -73,6 +73,15 @@ module Capsaicin
73
73
  @config.download(*args)
74
74
  end
75
75
  end
76
+
77
+ def put(from, to)
78
+ case _via
79
+ when :system, :local_run
80
+ FileUtils::Verbose.copy_stream StringIO.new(from), to
81
+ else
82
+ @config.put(*args)
83
+ end
84
+ end
76
85
 
77
86
  def cd(dir, options={})
78
87
  if block_given?
@@ -102,6 +111,22 @@ module Capsaicin
102
111
  _r 'tar -cjf', Array(src).unshift(dest)
103
112
  end
104
113
 
114
+ def tar_t(src, options={}, &filter)
115
+ filter and abort "tar_t: remote mode does not support a filtering proc"
116
+ _t 'tar -tf', [src]
117
+ end
118
+
119
+ def tar_tz(src, options={}, &filter)
120
+ filter and abort "tar_tz: remote mode does not support a filtering proc"
121
+ _t 'tar -tzf', [src]
122
+ end
123
+
124
+ def tar_tj(src, options={}, &filter)
125
+ filter and abort "tar_tj: remote mode does not support a filtering proc"
126
+ _t 'tar -tjf', [src]
127
+ end
128
+
129
+
105
130
  private
106
131
 
107
132
  def _t(cmd, args=nil, min=nil)
@@ -21,22 +21,25 @@ module Capsaicin
21
21
  svc_actions += args.pop if Array === args.last
22
22
 
23
23
  namespace id do
24
- case args.first
25
- when String; id = args.shift.intern
26
- when Symbol; id = args.shift
27
- end
28
- svc_cmd = "#{basedir || '/etc/init.d'}/#{id.to_s.split(':').last}"
24
+ svc_id = Symbol === id ? id.to_s : id.split(':').last
25
+ svc_cmd = case basedir
26
+ when String; basedir + '/' + svc_id
27
+ when NilClass; '/etc/init.d' + svc_id
28
+ when Symbol; fetch(basedir) + '/' + svc_id
29
+ when Proc; basedir.call + '/' + svc_id
30
+ end
29
31
 
30
32
  desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:status]}" if svc_desc
31
33
  task :default, options do
32
- send(basedir ? run_method : :sudo, "#{svc_cmd} status")
34
+ status
33
35
  end
34
36
 
35
37
  svc_actions.each do |svc_action|
36
38
  svc_action = svc_action.intern if String === svc_action
37
39
  desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
38
40
  task svc_action, options do
39
- send(basedir ? run_method : :sudo, "#{svc_cmd} #{svc_action}")
41
+ _run_method = basedir ? fetch(:run_method, :sudo) : :sudo
42
+ send(_run_method, "#{svc_cmd} #{svc_action}")
40
43
  end
41
44
  end
42
45
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joekhoobyar-capsaicin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Khoobyar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-29 00:00:00 -07:00
12
+ date: 2009-06-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency