sprout 0.5.29 → 0.7.153

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

Files changed (48) hide show
  1. data/{MIT-LICENSE.txt → MIT-LICENSE} +0 -0
  2. data/TODO +12 -0
  3. data/bin/sprout +83 -140
  4. data/doc/Bundle +14 -0
  5. data/doc/Generator +35 -0
  6. data/doc/Library +63 -0
  7. data/doc/Task +21 -0
  8. data/doc/Tool +20 -0
  9. data/lib/platform.rb +2 -3
  10. data/lib/progress_bar.rb +39 -23
  11. data/lib/sprout/builder.rb +35 -0
  12. data/lib/sprout/commands/generate.rb +14 -0
  13. data/lib/sprout/general_tasks.rb +5 -0
  14. data/lib/sprout/generator/base_mixins.rb +132 -0
  15. data/lib/sprout/generator/named_base.rb +216 -0
  16. data/lib/sprout/generator.rb +6 -0
  17. data/lib/{log.rb → sprout/log.rb} +2 -2
  18. data/lib/sprout/process_runner.rb +46 -0
  19. data/lib/sprout/project_model.rb +114 -0
  20. data/lib/{remote_file_loader.rb → sprout/remote_file_loader.rb} +63 -36
  21. data/lib/sprout/remote_file_target.rb +96 -0
  22. data/lib/sprout/simple_resolver.rb +88 -0
  23. data/lib/sprout/tasks/gem_wrap_task.rb +192 -0
  24. data/lib/sprout/tasks/library_task.rb +103 -0
  25. data/lib/sprout/tasks/sftp_task.rb +245 -0
  26. data/lib/sprout/tasks/tool_task.rb +541 -0
  27. data/lib/sprout/tasks/zip_task.rb +158 -0
  28. data/lib/{template_resolver.rb → sprout/template_resolver.rb} +10 -7
  29. data/lib/{user.rb → sprout/user.rb} +84 -37
  30. data/lib/sprout/version.rb +4 -3
  31. data/lib/sprout/zip_util.rb +61 -0
  32. data/lib/sprout.rb +377 -285
  33. data/rakefile.rb +93 -119
  34. data/samples/gem_wrap/rakefile.rb +17 -0
  35. metadata +131 -96
  36. data/Manifest.txt +0 -9
  37. data/lib/command.rb +0 -29
  38. data/lib/file_target.rb +0 -8
  39. data/lib/generate.rb +0 -37
  40. data/lib/library.rb +0 -18
  41. data/lib/process_runner.rb +0 -27
  42. data/lib/project.rb +0 -10
  43. data/lib/project_model.rb +0 -59
  44. data/lib/remote_file_target.rb +0 -62
  45. data/lib/task.rb +0 -20
  46. data/lib/template.rb +0 -37
  47. data/lib/tool.rb +0 -18
  48. data/setup.rb +0 -1585
@@ -0,0 +1,245 @@
1
+ =begin
2
+ Copyright (c) 2007 Pattern Park
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ This class has been commented out because the termios feature
24
+ that allows users to more securely enter passwords does not
25
+ work in a DOS shell.
26
+
27
+ It would be greatly appreciate if someone refactored this to either:
28
+ a) Get the same functionality in a cross-platform manner
29
+ b) Only require and use termios on systems that allow it
30
+ =end
31
+
32
+
33
+ require 'net/ssh'
34
+ require 'net/sftp'
35
+ #require 'termios'
36
+
37
+ module Sprout
38
+ class SFTPError < StandardError #:nodoc:
39
+ end
40
+
41
+ # The SFTPTask provides a simple rake task interface to the SFTP client RubyGem.
42
+ # This task can allow you to easily push build artifacts to a remote server
43
+ # with a single shell command.
44
+ class SFTPTask < Rake::Task
45
+
46
+ # Collection of files that should be transmitted to the remote server
47
+ attr_accessor :files
48
+ # Host name of the server to connect to with no protocol prefix, like: sub.yourhost.com
49
+ attr_accessor :host
50
+ # Username to send to the remote host. You will be prompted for this value if it is left null.
51
+ #
52
+ # NOTE: You should never check a file into version control with this field filled in, it is
53
+ # provided here as a convenience for getting set up.
54
+ attr_accessor :username
55
+ # The mode for transmitted files. Defaults to 0644
56
+ attr_accessor :file_mode
57
+ # the mode for created directories. Defaults to 0755
58
+ attr_accessor :dir_mode
59
+ # The local path to mask from transmitted files. This is key feature for automated file transmission.
60
+ # For example, if you are sending a file:
61
+ # bin/assets/img/SomeImage.jpg
62
+ # into a directory on your server like:
63
+ # /var/www/someproject/
64
+ # You don't necessarily want the 'bin' folder copied over, so you set the local_path to 'bin' like:
65
+ # t.local_path = 'bin'
66
+ # and your server will have the file uploaded to:
67
+ # /var/www/someproject/assets/img/SomeImage.jpg
68
+ attr_accessor :local_path
69
+ # The Remote base path where files should be transmitted, can be absolute or relative.
70
+ attr_accessor :remote_path
71
+ # Password to send to the remote host. You will be prompted for this value if it is left null.
72
+ #
73
+ # NOTE: You should never check a file into version control with this field filled in, it is
74
+ # provided here as a convenience for getting set up.
75
+ attr_accessor :password
76
+
77
+ # TODO: Get this to automatically download and install requisite gems
78
+ def initialize(task_name, app)
79
+ super(task_name, app)
80
+ @name = name
81
+ @files = []
82
+ @host = ''
83
+ @dir_mode = 0755
84
+ @file_mode = 0644
85
+ end
86
+
87
+ def self.define_task(args, &block) # :nodoc:
88
+ t = super
89
+ yield t if block_given?
90
+ end
91
+
92
+ def execute(*args) # :nodoc:
93
+ if(@files.size == 0)
94
+ if(@local_path)
95
+ expr = @local_path + '/**/**/*'
96
+ @files = FileList[expr]
97
+ else
98
+ throw SFTPError.new('SFTP requires either a local_path or files to be transmitted')
99
+ end
100
+ else
101
+ if(!@local_path)
102
+ @local_path = ''
103
+ end
104
+ end
105
+
106
+ if(@host == '' || @host.nil?)
107
+ throw SFTPError.new('SFTP requires non-nil host parameter')
108
+ end
109
+
110
+ if(@username.nil?)
111
+ print "Username: "
112
+ @username = $stdin.gets.chomp!
113
+ throw SFTPError.new('SFTP requires username parameter') unless @username
114
+ end
115
+
116
+ if(@password.nil?)
117
+ @password = $stdin.gets.chomp!
118
+ # @password = Password.get
119
+ throw SFTPError.new('SFTP requires password parameter') unless @password
120
+ end
121
+
122
+ if(get_confirmation)
123
+ puts ">> Connecting to Remote Server: #{@username}@#{@host}:#{@remote_path}"
124
+
125
+ Net::SFTP.start(@host, @username, @password) do |sftp|
126
+ begin
127
+ dir = sftp.opendir(@remote_path)
128
+ rescue Net::SFTP::Operations::StatusException
129
+ puts "[ERROR] [#{@remote_path}] does not exist on the server"
130
+ return
131
+ end
132
+ for file in @files
133
+ next if File.stat(file).directory?
134
+ remote_file = remote_file_name(file)
135
+ put_file(file, remote_file, sftp)
136
+ end
137
+ end
138
+ else
139
+ puts "[WARNING] Publish aborted by user request"
140
+ end
141
+ end
142
+
143
+ def put_file(local_file, remote_file, sftp) # :nodoc:
144
+ begin
145
+ create_remote_dir(remote_file, sftp)
146
+
147
+ if(file_changed(local_file, remote_file, sftp))
148
+ puts ">> Pushing #{local_file} to: #{remote_file}"
149
+ sftp.put_file(local_file, remote_file)
150
+ end
151
+ rescue Net::SFTP::Operations::StatusException => e
152
+ raise unless e.code == 2
153
+ sftp.put_file(local_file, remote_file)
154
+ sftp.setstat(remote_file, :permissions => @file_mode)
155
+ end
156
+ end
157
+
158
+ def create_remote_dir(path, sftp) # :nodoc:
159
+ begin
160
+ sftp.stat(File.dirname(path))
161
+ rescue Net::SFTP::Operations::StatusException => e
162
+ raise unless e.code == 2
163
+ dir = File.dirname(path.sub(@remote_path, ''))
164
+ parts = dir.split(File::SEPARATOR)
165
+ part = File.join(@remote_path, parts.shift)
166
+ while(part)
167
+ begin
168
+ sftp.stat(part)
169
+ rescue Net::SFTP::Operations::StatusException => e
170
+ raise unless e.code == 2
171
+ sftp.mkdir(part, :permissions => @dir_mode)
172
+ end
173
+ if(parts.size > 0)
174
+ part = File.join(part, parts.shift)
175
+ else
176
+ part = nil
177
+ end
178
+ end
179
+ end
180
+ end
181
+
182
+ def file_changed(local_file, remote_file, sftp) # :nodoc:
183
+ local_stat = File.stat(local_file)
184
+ remote_stat = sftp.stat(remote_file)
185
+ time_difference = (local_stat.mtime > Time.at(remote_stat.mtime))
186
+ size_difference = (local_stat.size != remote_stat.size)
187
+ return (time_difference || size_difference)
188
+ end
189
+
190
+ def remote_file_name(file) # :nodoc:
191
+ return @remote_path + file.sub(@local_path, '')
192
+ end
193
+
194
+ def get_confirmation # :nodoc:
195
+ puts "-----------------------------------------"
196
+ puts "Are you sure you want to publish #{@files.size} files to:"
197
+ puts "#{@username}@#{@host}:#{@remote_path}? [Yn]"
198
+ response = $stdin.gets.chomp!
199
+ return (response.downcase == 'y' || response == "")
200
+ end
201
+
202
+ end
203
+
204
+ =begin
205
+ # The following implementation does not work at all on DOS machines,
206
+ # is there a cross-platform way to solve the secure password prompt problem?
207
+ # Password handling snippet found at: http://www.caliban.org/ruby/ruby-password.shtml
208
+ class Password
209
+
210
+ def Password.get(message="Password: ")
211
+ begin
212
+ if $stdin.tty?
213
+ Password.echo false
214
+ print message if message
215
+ end
216
+
217
+ return $stdin.gets.chomp
218
+ ensure
219
+ if $stdin.tty?
220
+ Password.echo true
221
+ print "\n"
222
+ end
223
+ end
224
+ end
225
+
226
+ def Password.echo(on=true, masked=false)
227
+ term = Termios::getattr( $stdin )
228
+
229
+ if on
230
+ term.c_lflag |= ( Termios::ECHO | Termios::ICANON )
231
+ else # off
232
+ term.c_lflag &= ~Termios::ECHO
233
+ term.c_lflag &= ~Termios::ICANON if masked
234
+ end
235
+
236
+ Termios::setattr( $stdin, Termios::TCSANOW, term )
237
+ end
238
+ end
239
+ =end
240
+ end
241
+
242
+
243
+ def sftp(args, &block)
244
+ Sprout::SFTPTask.define_task(args, &block)
245
+ end