proutils 0.3.0

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.
Files changed (62) hide show
  1. data/CHANGES +17 -0
  2. data/COPYING +674 -0
  3. data/README +78 -0
  4. data/RELEASE +7 -0
  5. data/TODO +4 -0
  6. data/bin/icli +278 -0
  7. data/bin/mint +139 -0
  8. data/bin/rtar +69 -0
  9. data/bin/xact +121 -0
  10. data/data/mint/cherry/_scaffold.rb +4 -0
  11. data/data/mint/roll/name-1.0.0.roll +26 -0
  12. data/data/mint/ruby/README +17 -0
  13. data/data/mint/ruby/README.first +10 -0
  14. data/data/mint/ruby/README.license +403 -0
  15. data/data/mint/ruby/meta/MANIFEST +2 -0
  16. data/data/mint/ruby/meta/name-1.0.0.roll +26 -0
  17. data/data/mint/ruby/script/finish_scaffold +8 -0
  18. data/data/mint/ruby/script/setup +1600 -0
  19. data/data/mint/website/css/clean.css +5 -0
  20. data/data/mint/website/index.html +0 -0
  21. data/demo/demo_rtar/Lorem_ipsum.txt +233 -0
  22. data/demo/demo_rtar/lib/demo_rock/tryme.rb +2 -0
  23. data/demo/demo_rtar/meta/data +6 -0
  24. data/demo/demo_rtar/web/index.html +13 -0
  25. data/demo/demo_rtar/web/rocklobster.jpg +0 -0
  26. data/demo/mint/loremipsum.txt +9 -0
  27. data/demo/mint/tryme.rb +33 -0
  28. data/lib/proutils/icli/abstract_host.rb +71 -0
  29. data/lib/proutils/icli/gforge.rb +668 -0
  30. data/lib/proutils/icli/rubyforge.rb +26 -0
  31. data/lib/proutils/icli/tool.rb +128 -0
  32. data/lib/proutils/icli/uploadutils.rb +410 -0
  33. data/lib/proutils/mint/copier.rb +324 -0
  34. data/lib/proutils/mint/fileutils.rb +47 -0
  35. data/lib/proutils/mint/help.txt +0 -0
  36. data/lib/proutils/rtar/rtar.rb +309 -0
  37. data/lib/proutils/rtar/vendor/archive/tar/minitar/command.rb +814 -0
  38. data/lib/proutils/rtar/vendor/archive/tar/minitar.rb +979 -0
  39. data/lib/proutils/xact/extract.rb +211 -0
  40. data/lib/proutils/xact/save.rb +151 -0
  41. data/meta/MANIFEST +100 -0
  42. data/meta/config.yaml +12 -0
  43. data/meta/icli.yaml +16 -0
  44. data/meta/project.yaml +27 -0
  45. data/meta/proutils.roll +3 -0
  46. data/test/fixture.rb +6 -0
  47. data/test/lib/test_exacto.rb +54 -0
  48. data/work/ANN +14 -0
  49. data/work/icli/icli +223 -0
  50. data/work/icli/rake.rb +82 -0
  51. data/work/icli/utils/consoleutils.rb +67 -0
  52. data/work/icli/utils/emailutils.rb +85 -0
  53. data/work/icli/utils/fileutils.rb +47 -0
  54. data/work/mint/command-old.rb +48 -0
  55. data/work/mint/lazyfile.rb +97 -0
  56. data/work/mint/part.rb +316 -0
  57. data/work/mint/scaffold-old.rb +420 -0
  58. data/work/rtar/index.html +68 -0
  59. data/work/rtar/old-index.html +63 -0
  60. data/work/xact/xact-ginsu +5 -0
  61. data/work/xact/xact-ruby.rb +155 -0
  62. metadata +178 -0
@@ -0,0 +1,128 @@
1
+ require 'fileutils'
2
+ require 'facets/ziputils'
3
+
4
+ p "TOOL!"
5
+
6
+ module Forge
7
+
8
+ # Tool class provides a base class
9
+ # for packaging tools.
10
+
11
+ class Tool
12
+ attr_accessor :dryrun
13
+ attr_accessor :trace
14
+ attr_accessor :force
15
+ attr_accessor :quiet
16
+ attr_accessor :mode
17
+
18
+ attr_reader :settings
19
+
20
+ # New Tool.
21
+
22
+ def initialize( settings )
23
+ @settings = settings
24
+ settings.each do |k,v|
25
+ send("#{k.to_s.downcase}=",v)
26
+ end
27
+
28
+ if dryrun?
29
+ extend FileUtils::DryRun
30
+ extend ZipUtils::DryRun
31
+ else
32
+ extend FileUtils
33
+ extend ZipUtils
34
+ end
35
+ end
36
+
37
+ def dryrun? ; @dryrun ; end
38
+ def trace? ; @trace ; end
39
+ def force? ; @force ; end
40
+ def quiet? ; @quiet ; end
41
+ def verbose? ; !@quiet ; end
42
+ def mode ; @mode ; end
43
+
44
+ # Verbosity mode allows for gradations of output
45
+ # types. Generally recognized values are:
46
+ #
47
+ # quiet (same as quiet flag)
48
+ # normal (default mode)
49
+ # verbose (give details)
50
+ # progress (use progress bar)
51
+ #
52
+ # You add another mode if you need. any task that
53
+ # doesn't recognize the current mode should fallback
54
+ # to normal.
55
+
56
+ def mode
57
+ return 'quiet' if quiet?
58
+ (@mode || 'normal').downcase
59
+ end
60
+
61
+ # Shell out.
62
+
63
+ def sh(cmd)
64
+ puts cmd unless quiet?
65
+ system(cmd) unless dryrun?
66
+ end
67
+
68
+ # Extra filesystem util
69
+
70
+ def cd(dir, &block)
71
+ status "cd #{dir}"
72
+ Dir.chdir(dir, &block)
73
+ end
74
+
75
+ # Internal status report.
76
+ # Only output if dryrun or trace mode.
77
+
78
+ def status(message)
79
+ puts message if dryrun? or trace?
80
+ end
81
+
82
+ # Standard message to user.
83
+ # Output unless quiet.
84
+
85
+ def say(message)
86
+ puts message unless quiet?
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+
93
+ =begin
94
+ # # Dump project information.
95
+ # #
96
+ # def dump( type='yaml' )
97
+ # case type.to_s.downcase
98
+ # when 'xoxo'
99
+ # puts metadata.to_xoxo
100
+ # else
101
+ # puts metadata.to_yaml
102
+ # end
103
+ # end
104
+
105
+ # apply naming policy
106
+ #
107
+ def apply_naming_policy(name, ext)
108
+ return name unless info.naming_policy
109
+ policies = info.naming_policy.split(' ')
110
+ policies.each do |policy|
111
+ case policy
112
+ when 'downcase'
113
+ name = name.downcase
114
+ when 'upcase'
115
+ name = name.upcase
116
+ when 'capitalize'
117
+ name = name.capitalize
118
+ when 'extension'
119
+ name = name + ".#{ext}"
120
+ when 'plain'
121
+ name = name.chomp(File.extname(name))
122
+ end
123
+ end
124
+ return name
125
+ end
126
+ =end
127
+
128
+ # CREDIT Thomas Sawyer
@@ -0,0 +1,410 @@
1
+ # = uploadutils.rb
2
+ #
3
+ # CREDIT Thomas Sawyer
4
+ #
5
+ # TODO Incorporate password into scp and ftp ?
6
+ # TODO rsync needs --delete option
7
+
8
+ require 'openssl'
9
+ require 'shellwords'
10
+ require 'tmpdir'
11
+
12
+ require 'facets/openobject'
13
+
14
+ # Upload files to host. These means of uploading are current
15
+ # supported: ftp, sftp, scp and rsync.
16
+ #
17
+ # user Username for host.
18
+ # host Host server's domain name.
19
+ # root Document root path on host.
20
+ # copy Directory of files to publish, or
21
+ # Files to publish using from and to.
22
+ #
23
+ # dryrun If true only pretend to upload.
24
+ # quiet Supress all output.
25
+ # verbose Provide extra details.
26
+ #
27
+ # The copy parameter allows you to simply specify a file
28
+ # or directory which will be published to host's document
29
+ # root location.
30
+ #
31
+ # If you need more control over which files to publish
32
+ # where, you can use the copy parameter instead. Provide
33
+ # an array of pattern strings in the form of "{from} {to}".
34
+ # If the desitination is the host's document root you do
35
+ # not need to specify the {to} part. For example:
36
+ #
37
+ # copy = [ 'web/*', 'doc/api/* doc/api' ]
38
+ #
39
+ # The first copies the files under your project's web directory
40
+ # to the host's document root. The second copies your projects
41
+ # doc/api files to the doc/api location on the host.
42
+ #
43
+ # The internal template used for the outbound destination
44
+ # is 'username@host:root/'.
45
+
46
+ module UploadUtils
47
+
48
+ module_function
49
+
50
+ #
51
+ # Upload via given protocol.
52
+ #
53
+
54
+ def upload( protocol, opts )
55
+ send(protocol.to_s.downcase,opts)
56
+ end
57
+
58
+ #
59
+ # Use ftp to upload files.
60
+ #
61
+
62
+ def ftp( keys )
63
+ keys = upload_parameters(keys)
64
+
65
+ # set transfer rules
66
+ if keys.stage
67
+ trans = stage_transfer(keys.stage)
68
+ else
69
+ files(keys.dir, keys.copy).each do |from|
70
+ trans << [from,from]
71
+ end
72
+ end
73
+
74
+ # append location of publication dir to from
75
+ dir = keys.dir
76
+ trans.collect!{ |from,to| [File.join(dir,from), to] }
77
+
78
+ if keys.dryrun
79
+ puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
80
+ keys.trans.each do |f, t|
81
+ puts "ftp put #{f} #{t}"
82
+ end
83
+ else
84
+ require 'net/ftp'
85
+ Net::FTP.open(keys.host) do |ftp|
86
+ ftp.login(keys.user) #password?
87
+ ftp.chdir(keys.root)
88
+ keys.trans.each do |f, t|
89
+ puts "ftp #{f} #{t}" unless keys.quiet
90
+ ftp.putbinaryfile( f, t, 1024 )
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ #
97
+ # Use sftp to upload files.
98
+ #
99
+
100
+ def sftp( keys )
101
+ keys = upload_parameters(keys)
102
+
103
+ # set transfer rules
104
+ if keys.stage
105
+ trans = stage_transfer(keys.stage)
106
+ else
107
+ files(keys.dir, keys.copy).each do |from|
108
+ trans << [from,from]
109
+ end
110
+ end
111
+
112
+ # append location of publication dir to from
113
+ dir = keys.dir
114
+ trans.collect!{ |from,to| [File.join(dir,from), to] }
115
+
116
+ if keys.dryrun
117
+ puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
118
+ keys.trans.each do |f,t|
119
+ puts "sftp put #{f} #{t}"
120
+ end
121
+ else
122
+ require 'net/sftp'
123
+ Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
124
+ #sftp.login( user )
125
+ sftp.chdir(keys.root)
126
+ keys.trans.each do |f,t|
127
+ puts "sftp #{f} #{t}" unless keys.quiet
128
+ sftp.put_file(f,t) #, 1024 )
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ #
135
+ # Use rsync to upload files.
136
+ #
137
+
138
+ def rsync( keys )
139
+ keys = upload_parameters(keys)
140
+
141
+ flags = []
142
+ flags << "-n" if keys.dryrun
143
+ flags << "-q" if keys.quiet
144
+ flags << "-v" if keys.verbose
145
+ flags << "--progress" unless keys.quiet
146
+ flags = flags.join(' ').strip
147
+ flags = ' ' + flags unless flags.empty?
148
+
149
+ manfile = 'Publish.txt'
150
+
151
+ if keys.stage
152
+ dir = stage_linkdir(keys.dir, keys.stage)
153
+ Dir.chdir(dir) do
154
+ cpy = files(keys.copy)
155
+ end
156
+ manifest = File.join(dir,manfile)
157
+ cmd = %{rsync#{flags} -L -arz --files-from='#{manifest}' #{dir} #{keys.user}@#{keys.host}:/#{keys.root}}
158
+ else
159
+ dir = keys.dir
160
+ cpy = files(dir, keys.copy)
161
+ manifest = File.join(dir,manfile)
162
+ cmd = %{rsync#{flags} -arz --files-from='#{manifest}' #{dir} #{keys.user}@#{keys.host}:/#{keys.root}}
163
+ end
164
+
165
+ #Dir.chdir(keys.dir) do
166
+ begin
167
+ File.open(manifest, 'w'){ |f| f << cpy.join("\n") }
168
+ ENV['RSYNC_PASSWORD'] = keys.pass if keys.pass
169
+ puts cmd unless keys.quiet
170
+ system cmd
171
+ ensure
172
+ ENV.delete('RSYNC_PASSWORD') if keys.pass
173
+ end
174
+ #end
175
+
176
+ end
177
+
178
+ # private (can't do b/c of module_function)
179
+
180
+ # parse publishing options.
181
+
182
+ def upload_parameters( keys )
183
+ keys = OpenObject.new(keys)
184
+
185
+ keys.copy = keys.copy || '**/*'
186
+ keys.host = keys.host || keys.domain
187
+ keys.user = keys.user || keys.username
188
+ keys.root = keys.root || '/'
189
+ #keys.pass = keys.pass || keys.password
190
+
191
+ # validate
192
+ raise ArgumentError, "missing publish parameter -- dir" unless keys.dir
193
+ raise ArgumentError, "missing publish parameter -- host" unless keys.host
194
+ raise ArgumentError, "missing publish parameter -- user" unless keys.user
195
+ #raise ArgumentError, "missing publish parameter -- copy" unless keys.copy
196
+ #raise ArgumentError, "missing publish parameter -- root" unless keys.root
197
+
198
+ keys.root = '' if keys.root.nil?
199
+ keys.root.sub!(/^\//,'')
200
+
201
+ if String===keys.copy and File.directory?(keys.copy)
202
+ copy = File.join(keys.copy, '*')
203
+ end
204
+ keys.copy = [keys.copy].flatten.compact
205
+
206
+ # trans = []
207
+ # keys.copy.each do |from|
208
+ # #from, to = *Shellwords.shellwords(c)
209
+ # #to = from if to.nil?
210
+ # #to = to[1..-1] if to[0,1] == '/'
211
+ # from.sub('*','**/*') unless from =~ /\*\*/
212
+ # files = Dir.glob(from)
213
+ # files.each do |f|
214
+ # #t = File.join(to,File.basename(f))
215
+ # #t = t[1..-1] if t[0,1] == '/'
216
+ # trans << [f,f]
217
+ # end
218
+ # end
219
+ # keys.trans = trans
220
+
221
+ return keys
222
+ end
223
+
224
+ # Put together the list of files to copy.
225
+
226
+ def files( dir, copy )
227
+ Dir.chdir(dir) do
228
+ del, add = copy.partition{ |f| /^[-]/ =~ f }
229
+
230
+ # remove - and + prefixes
231
+ del.collect!{ |f| f.sub(/^[-]/,'') }
232
+ add.collect!{ |f| f.sub(/^[+]/,'') }
233
+
234
+ #del.concat(must_exclude)
235
+
236
+ files = []
237
+ add.each{ |g| files += Dir.multiglob(g) }
238
+ del.each{ |g| files -= Dir.multiglob(g) }
239
+
240
+ files.collect!{ |f| f.sub(/^\//,'') }
241
+
242
+ return files
243
+ end
244
+ end
245
+
246
+ # Combine three part stage list into a two part from->to list.
247
+ #
248
+ # Using the stage list of three space separated fields.
249
+ #
250
+ # fromdir file todir
251
+ #
252
+ # This is used to generate a from -> to list of the form:
253
+ #
254
+ # fromdir/file todir/file
255
+ #
256
+
257
+ def stage_transfer( list )
258
+ trans = []
259
+ list.each do |line|
260
+ trans << Shellwords.shellwords(line)
261
+ end
262
+
263
+ trans.collect! do |from, base, to|
264
+ file = File.join(from,base)
265
+ to = File.join(to,base)
266
+ [from, to]
267
+ end
268
+ end
269
+
270
+ # When using stage options this will create temporary linked location.
271
+
272
+ def stage_linkdir( dir, list )
273
+ folder = File.join(Dir.tmpdir, 'ratchets', 'project', object_id.abs.to_s)
274
+ FileUtils.mkdir_p(folder)
275
+
276
+ Dir.chdir(dir) do
277
+ stage_transfer(list).each do |file, to|
278
+ link = File.join(folder,to)
279
+ FileUtils.ln_s(link,file)
280
+ end
281
+ end
282
+
283
+ return folder
284
+ end
285
+
286
+
287
+ =begin
288
+
289
+
290
+ #--
291
+ # SHELLS OUT! Need net/scp library to fix.
292
+ #++
293
+
294
+ # Use scp to upload files.
295
+
296
+ def scp( keys )
297
+ keys = upload_parameters(keys)
298
+
299
+ flags = []
300
+ flags << "-v" if keys.verbose
301
+ flags << "-q" if keys.quiet
302
+ flags = flags.join(' ').strip
303
+ flags = ' ' + flags unless flags.empty?
304
+
305
+ upload_stage(keys) do #|tmpdir|
306
+ cmd = "scp -r#{flags} * #{keys.user}@#{keys.host}:/#{keys.root}"
307
+ puts cmd unless keys.quiet
308
+ system cmd unless keys.dryrun
309
+ end
310
+ end
311
+
312
+ # Use rsync to upload files.
313
+
314
+ def rsync( keys )
315
+ keys = upload_parameters(keys)
316
+
317
+ flags = []
318
+ flags << "-n" if keys.dryrun
319
+ flags << "-v" if keys.verbose
320
+ flags << "-q" if keys.quiet
321
+ flags = flags.join(' ').strip
322
+ flags = ' ' + flags unless flags.empty?
323
+
324
+ upload_stage(keys) do #|tmpdir|
325
+ begin
326
+ ENV['RSYNC_PASSWORD'] = keys.pass if keys.pass
327
+ cmd = "rsync -R#{flags} -arz * #{keys.user}@#{keys.host} /#{keys.root}"
328
+ ensure
329
+ ENV.delete('RSYNC_PASSWORD') if keys.pass
330
+ end
331
+ end
332
+ end
333
+
334
+ # Use ftp to upload files.
335
+
336
+ def ftp( keys )
337
+ keys = upload_parameters(keys)
338
+
339
+ if keys.dryrun
340
+ puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
341
+ keys.trans.each do |f, t|
342
+ puts "ftp put #{f} #{t}"
343
+ end
344
+ else
345
+ require 'net/ftp'
346
+ Net::FTP.open(keys.host) do |ftp|
347
+ ftp.login(keys.user) #password?
348
+ ftp.chdir(keys.root)
349
+ keys.trans.each do |f, t|
350
+ puts "ftp #{f} #{t}" unless keys.quiet
351
+ ftp.putbinaryfile( f, t, 1024 )
352
+ end
353
+ end
354
+ end
355
+ end
356
+
357
+ # Use sftp to upload files.
358
+
359
+ def sftp( keys )
360
+ keys = upload_parameters(keys)
361
+
362
+ if keys.dryrun
363
+ puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
364
+ keys.trans.each do |f,t|
365
+ puts "sftp put #{f} #{t}"
366
+ end
367
+ else
368
+ require 'net/sftp'
369
+ Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
370
+ #sftp.login( user )
371
+ sftp.chdir(keys.root)
372
+ keys.trans.each do |f,t|
373
+ puts "sftp #{f} #{t}" unless keys.quiet
374
+ sftp.put_file(f,t) #, 1024 )
375
+ end
376
+ end
377
+ end
378
+ end
379
+
380
+
381
+
382
+ # Creates a stage from which the whole directory can be uploaded.
383
+ # This is needed for scp and rsync which have to shelled out,
384
+ # and can't conveniently copy one file at a time.
385
+
386
+ def upload_stage(keys) #:yield:
387
+ tmp = "scp_#{object_id.abs}_#{ Time.now.strftime("%Y%m%d%H%M%S")}"
388
+ tmpdir = File.join(Dir.tmpdir,tmp)
389
+
390
+ puts "mkdir -p #{tmpdir}" unless keys.quiet
391
+ FileUtils.mkdir_p(tmpdir) # go ahead and do this even if dryrun
392
+
393
+ fu = keys.dryrun ? FileUtils::DryRun : FileUtils
394
+ keys.trans.each do |f, t|
395
+ to = File.join(tmpdir, t)
396
+ fu.mv(f,to)
397
+ end
398
+
399
+ puts "cd #{tmpdir}" unless keys.quiet
400
+ Dir.chdir(tmpdir) do
401
+ yield #(tmpdir)
402
+ end
403
+
404
+ puts "rm -r #{tmpdir}" unless keys.quiet
405
+ FileUtils.rm_r(tmpdir) # now remove the temp dir
406
+ end
407
+
408
+ =end
409
+
410
+ end