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,324 @@
1
+ # TITLE:
2
+ #
3
+ # Scaffold Controller
4
+ #
5
+ # COPYRIGHT:
6
+ #
7
+ # Copyright (c) 2007 7rans
8
+ #
9
+ # TODOs:
10
+ #
11
+ # - Need to make actions lazy and only commit when
12
+ # everything is acknowledged.
13
+
14
+ require 'rbconfig'
15
+ require 'proutils/mint/fileutils'
16
+
17
+
18
+ module Mint
19
+
20
+ # def self.lookup(type)
21
+ # globs = []
22
+ # paths.each do |path|
23
+ # parts = type.split(/[\/\\]/)
24
+ # if File.basename(path) == parts.first
25
+ # globs << File.join(File.dirname(path), type)
26
+ # end
27
+ # end
28
+ # globs.collect{ |g| Dir.glob(g) }.flatten
29
+ # end
30
+
31
+ def self.paths
32
+ @paths ||= (
33
+ builtin = Dir.glob(File.join(datadir, '*'))
34
+ paths = ENV['MINT_PATH'].to_s.split(/[:;]/) + builtin
35
+ paths.inject({}) do |hash, path|
36
+ dir, type = *File.split(path)
37
+ hash[type] = dir
38
+ hash
39
+ end
40
+ )
41
+ end
42
+
43
+ # TODO Better way to support RubyGems and Rolls?
44
+
45
+ def self.datadir
46
+ dir = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'data', 'mint')
47
+ if File.directory?(dir)
48
+ dir
49
+ else
50
+ File.join(File.join(Config::CONFIG['datadir'], 'mint'))
51
+ end
52
+ end
53
+
54
+ # = Mint Copier
55
+
56
+ class Copier
57
+
58
+ IGNORE = [ '.', '..', '.svn']
59
+
60
+ attr_reader :sources, :destination, :options
61
+
62
+ attr_reader :actions
63
+
64
+ def initialize(sources, destination, options=nil)
65
+ @sources = [sources].flatten
66
+ @destination = destination
67
+ @options = options || {}
68
+
69
+ @special = options[:special]
70
+
71
+ @dryrun = options[:dryrun]
72
+ @force = options[:force]
73
+ @skip = options[:skip]
74
+
75
+ if special?
76
+ @sources = special_lookup(*sources)
77
+ else
78
+ @sources = general_lookup(*sources)
79
+ end
80
+
81
+ @actions = []
82
+ end
83
+
84
+ def special? ; @special; end
85
+ def dryrun? ; @dryrun ; end
86
+ def force? ; @force ; end
87
+ def skip? ; @skip ; end
88
+
89
+ # Lookup in special mint locations.
90
+
91
+ def special_lookup(*sources)
92
+ # First lets make sure there are not bad requests.
93
+ missing = requested_locations(*sources) - Mint.paths.keys
94
+ unless missing.empty?
95
+ puts "Missing special sources -- #{missing.join(', ')}"
96
+ exit 0
97
+ end
98
+ #
99
+ sources.collect do |source|
100
+ type = *source.split(/[\/\\]/).first
101
+ [Mint.paths[type], source]
102
+ end
103
+ end
104
+
105
+ #
106
+
107
+ def requested_locations(*sources)
108
+ sources.collect do |source|
109
+ source.split(/[\/\\]/).first
110
+ end
111
+ end
112
+
113
+ #
114
+
115
+ def general_lookup(*sources)
116
+ sources.collect do |source|
117
+ [ '.', source ]
118
+ end
119
+ end
120
+
121
+ # Copy files.
122
+
123
+ def copy
124
+ puts "KEY: (d)iff (r)eplace (s)kip skip(a)ll (q)uit"
125
+ sources.each do |dir, file|
126
+ path = File.join(dir, file)
127
+ if File.file?(path)
128
+ copy_file(dir, file)
129
+ else
130
+ dirs, files = *partition_path(path)
131
+ # make empty directories
132
+ dirs.each do |d|
133
+ if File.directory?(d)
134
+ skip_dir(d)
135
+ else
136
+ pth = File.join(path,d)
137
+ entries = Dir.entries(pth) - IGNORE
138
+ make_dir(d) if entries.empty?
139
+ end
140
+ end
141
+ # copy files in directories
142
+ files.each do |f|
143
+ copy_file(path, f)
144
+ end
145
+ end
146
+ end
147
+ commit
148
+ end
149
+
150
+ private
151
+
152
+ # List of source files.
153
+
154
+ #def source_paths
155
+ # Dir.glob(File.join(@source, '**/*'))
156
+ #end
157
+
158
+ # Partition a path's contents between dirs and files.
159
+
160
+ def partition_path(path)
161
+ dirs, files = [], []
162
+ chdir(path) do
163
+ paths = Dir.glob('**/*')
164
+ dirs, files = *paths.partition do |f|
165
+ File.directory?(f)
166
+ end
167
+ end
168
+ return dirs, files
169
+ end
170
+
171
+ # Make a directory.
172
+
173
+ def make_dir(dir)
174
+ dst = File.join(destination, dir)
175
+ if File.file?(dst)
176
+ puts "Directory to replace file..."
177
+ action = query(file) || 'skip'
178
+ else
179
+ action = 'make'
180
+ end
181
+ @actions << [action, dst]
182
+ action_print(action, dst + '/')
183
+ end
184
+
185
+ # Copy a file.
186
+
187
+ def copy_file(source, file)
188
+ src = File.join(source, file)
189
+ dst = File.join(destination, file)
190
+
191
+ action = 'skip'
192
+
193
+ if File.directory?(dst)
194
+ puts "File to replace directory..."
195
+ action = query(file)
196
+ elsif File.file?(dst)
197
+ unless FileTest.identical?(src, dst)
198
+ action = query(file)
199
+ end
200
+ else
201
+ action = 'copy'
202
+ end
203
+
204
+ @actions << [action, [src, dst]]
205
+
206
+ #if action == 'copy' or action == 'replace'
207
+ # rm_r(dst) if File.directory?(dst)
208
+ # cp(src, dst)
209
+ #end
210
+
211
+ action_print(action, dst) #, file)
212
+ end
213
+
214
+ # Skip directory.
215
+
216
+ def skip_dir(dst)
217
+ @actions << ['skip', dst]
218
+ action_print('skip', dst + '/')
219
+ end
220
+
221
+ # Skip file.
222
+
223
+ def skip_file(src, dst)
224
+ @actions << ['skip', [src, dst]]
225
+ action_print('skip', dst)
226
+ end
227
+
228
+ # Show diff of files.
229
+
230
+ def diff(file)
231
+ src = File.join(source, file)
232
+ dst = File.join(destination, file)
233
+ diff = FileTest.diff(src, dst)
234
+ puts diff unless diff.empty?
235
+ end
236
+
237
+ # Query about file.
238
+
239
+ def query(file)
240
+ return 's' if @safe
241
+ return 'o' if @force
242
+ action = nil
243
+ #msg = "#{file} -- (d)iff (r)eplace (s)kip (a)ll (q)uit?"
244
+ msg = " ? #{file} "
245
+ until action
246
+ ans = ask(msg).strip[0,1]
247
+ case ans
248
+ when 'd', 'D'
249
+ diff(file)
250
+ when 'r', 'R'
251
+ action = 'replace'
252
+ when 's', 'S'
253
+ action = 'skip'
254
+ when 'a', 'A'
255
+ @safe = true
256
+ action = 'skip'
257
+ when 'q', 'Q'
258
+ exit 0
259
+ end
260
+ end
261
+ return action
262
+ end
263
+
264
+ # Get user input
265
+
266
+ def ask(msg)
267
+ print "#{msg} "
268
+ until inp = $stdin.gets ; sleep 1 ; end
269
+ inp.chomp
270
+ end
271
+
272
+ # Action print
273
+ def action_print(action, file)
274
+ file = file.sub(/^[.]\//,'')
275
+ action = (' ' * (8 - action.size)) + action
276
+ puts "#{action} #{file}"
277
+ end
278
+
279
+ def commit
280
+ ans = ask("Commit y/N?")
281
+ case ans.downcase
282
+ when 'y', 'yes'
283
+ commit!
284
+ end
285
+ end
286
+
287
+ def commit!
288
+ @actions.each do |action, path|
289
+ case action
290
+ when 'make'
291
+ rm(path) unless File.directory?(path)
292
+ mkdir_p(path)
293
+ when 'copy'
294
+ src, dst = *path
295
+ rm_r(dst) if File.directory?(dst)
296
+ mkdir_p(File.dirname(dst))
297
+ cp(src, dst)
298
+ when 'replace'
299
+ src, dst = *path
300
+ rm_r(dst) if File.directory?(dst)
301
+ #mkdir_p(File.dirname(dst))
302
+ cp(src, dst)
303
+ else # skip
304
+ #
305
+ end
306
+ end
307
+ end
308
+
309
+ # Delegate to fileutils.
310
+
311
+ def fu
312
+ @dryrun ? FileUtils::DryRun : FileUtils
313
+ end
314
+
315
+ def chdir(*a,&b) ; fu.chdir(*a,&b) ; end
316
+ def rm(*a,&b) ; fu.rm(*a,&b) ; end
317
+ def rm_r(*a,&b) ; fu.rm_r(*a,&b) ; end
318
+ def cp(*a,&b) ; fu.cp(*a,&b) ; end
319
+ def cp_r(*a,&b) ; fu.cp_r(*a,&b) ; end
320
+ def mkdir(*a,&b) ; fu.mkdir(*a,&b) ; end
321
+ def mkdir_p(*a,&b) ; fu.mkdir_p(*a,&b) ; end
322
+
323
+ end
324
+ end
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+ require 'digest/md5'
3
+
4
+ module FileTest
5
+ module_function
6
+
7
+ BUF_SIZE = 1024*1024
8
+
9
+ # Are two files identical? This compares size and then checksum.
10
+ def identical?(file1, file2)
11
+ size(file1) == size(file2) && md5(file1) == md5(file2)
12
+ end
13
+
14
+ # Return an md5 checkum. If a directory is given, will
15
+ # return a nested array of md5 checksums for all entries.
16
+
17
+ def md5(path)
18
+ if File.directory?(path)
19
+ md5_list = []
20
+ crt_dir = Dir.new(path)
21
+ crt_dir.each do |file_name|
22
+ next if file_name == '.' || file_name == '..'
23
+ md5_list << md5("#{crt_dir.path}#{file_name}")
24
+ end
25
+ md5_list
26
+ else
27
+ hasher = Digest::MD5.new
28
+ open(path, "r") do |io|
29
+ counter = 0
30
+ while (!io.eof)
31
+ readBuf = io.readpartial(BUF_SIZE)
32
+ counter+=1
33
+ #putc '.' if ((counter+=1) % 3 == 0)
34
+ hasher.update(readBuf)
35
+ end
36
+ end
37
+ return hasher.hexdigest
38
+ end
39
+ end
40
+
41
+ # Show diff of two files.
42
+
43
+ def diff(file1, file2)
44
+ `diff #{file1} #{file2}`.strip
45
+ end
46
+
47
+ end
File without changes
@@ -0,0 +1,309 @@
1
+
2
+ require 'zlib'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ require 'proutils/rtar/vendor/archive/tar/minitar'
7
+
8
+
9
+ class NilClass
10
+
11
+ # Nil#status makes it possible to pass messages through
12
+ # a "failure" chain.
13
+
14
+ def status( *status )
15
+ if status.empty?
16
+ return @status
17
+ else
18
+ @status = status
19
+ self
20
+ end
21
+ end
22
+
23
+ # Check status.
24
+
25
+ def status?
26
+ return unless @status
27
+ return false if @status.empty?
28
+ return true
29
+ end
30
+
31
+ end
32
+
33
+
34
+ class File
35
+
36
+ # Is a file a gzip file?
37
+
38
+ def self.gzip?( file )
39
+ File.open(file,'rb') { |f|
40
+ return false unless f.getc == 0x1f
41
+ return false unless f.getc == 0x8b
42
+ }
43
+ true
44
+ end
45
+
46
+ end
47
+
48
+
49
+ module Rock
50
+
51
+ class Package
52
+
53
+ def initialize()
54
+ end
55
+
56
+ # Pack rock archive.
57
+
58
+ def pack(folder)
59
+ basename = File.basename(folder)
60
+ return unless write_okay?(basename + ".rock")
61
+ temp_folder = tmpdir()
62
+ temp_locale = File.join(temp_folder,basename)
63
+ #FileUtils.rm_r( temp_locale ) if File.exist?( temp_locale )
64
+ FileUtils.cp_r(folder,temp_folder)
65
+ file = nil
66
+ Dir.chdir(temp_folder) do
67
+ file = pack_rec(basename)
68
+ end
69
+ raise "unexpect compression error" unless file
70
+ FileUtils.cp(File.join(temp_folder, file), "./#{basename}.rock")
71
+ end
72
+
73
+ # Recursive packing.
74
+
75
+ def pack_rec(folder)
76
+ puts "<< #{folder}" if $VERBOSE
77
+ Dir.chdir(folder) do
78
+ files = Dir.entries('.') - ['.', '..']
79
+ files.each do |f|
80
+ if File.directory?(f)
81
+ pack_rec(f)
82
+ else
83
+ gzip(f)
84
+ end
85
+ end
86
+ end
87
+ seal(folder) #gzip(tar(folder),'.rock')
88
+ end
89
+
90
+ # Unpack rock archive.
91
+
92
+ def unpack(file)
93
+ return unless gzip?(file)
94
+ basename = File.basename(file)
95
+ barename = basename.chomp('.rock')
96
+ rock_ext = (basename != barename)
97
+ rockname = barename + '.rock'
98
+ unless rock_ext or $FORCE
99
+ return nil.status(:no_rock_ext)
100
+ end
101
+ temp_folder = tmpdir()
102
+ to_file = File.join(temp_folder, rockname)
103
+ if rock_ext
104
+ return unless write_okay?(barename)
105
+ FileUtils.cp_r(file, to_file)
106
+ elsif $FORCE
107
+ FileUtils.mv(file, to_file)
108
+ end
109
+ Dir.chdir(temp_folder) do
110
+ unpack_rec(rockname)
111
+ end
112
+ FileUtils.mv(File.join(temp_folder,barename), '.')
113
+ end
114
+
115
+ # Recursive unpacking.
116
+
117
+ def unpack_rec(file)
118
+ puts ">> #{file}" if $VERBOSE
119
+ folder = unseal(file) #untar(gunzip(file))
120
+ Dir.chdir( folder ) do
121
+ files = Dir.entries('.') - ['.','..']
122
+ files.each do |f|
123
+ if f =~ /\.rock$/
124
+ unpack_rec(f)
125
+ else
126
+ gunzip(f)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ # Extract a particular file from the archive.
133
+
134
+ def extract(file)
135
+ puts "NOT WORKING YET"
136
+ return
137
+ # TODO
138
+ end
139
+
140
+ # List contents of rock archive.
141
+
142
+ def list(file)
143
+ puts "NOT WORKING YET"
144
+ return
145
+ name = File.basename(file)
146
+ temp_folder = Dir.tmpdir
147
+ FileUtils.cp_r(file,temp_folder)
148
+ Dir.chdir(temp_folder) do
149
+ unpack_rec(name)
150
+ end
151
+ folder = name.chomp('.tar')
152
+ Dir.glob(File.join(temp_folder,folder,'**/*'))
153
+ end
154
+
155
+ private
156
+
157
+ # Tar and gzip file.
158
+
159
+ def seal(folder)
160
+ puts "seal: #{folder}" if $VERBOSE
161
+
162
+ to_file = folder + '.rock'
163
+ begin
164
+ gzIO = Zlib::GzipWriter.new(File.open(to_file, 'wb'))
165
+ tarIO = Archive::Tar::Minitar::Output.new(gzIO)
166
+ Dir.chdir(folder) do
167
+ files = Dir.entries('.') - ['.', '..']
168
+ files.each do |file|
169
+ #puts "#{folder}/#{file}" if $VERBOSE
170
+ Archive::Tar::Minitar.pack_file(file, tarIO)
171
+ end
172
+ end
173
+ ensure
174
+ tarIO.close # automatically does gzIO.close
175
+ end
176
+ FileUtils.rm_r(folder)
177
+ return to_file
178
+ end
179
+
180
+ # Untar and gunzip file.
181
+
182
+ def unseal(file)
183
+ puts "unseal: #{file}" if $VERBOSE
184
+
185
+ to_file = file.chomp('.rock')
186
+ tgz = Zlib::GzipReader.new(File.open(file, 'rb'))
187
+ Archive::Tar::Minitar.unpack(tgz, to_file)
188
+ FileUtils.rm(file)
189
+ return to_file
190
+ end
191
+
192
+ # Tar a folder.
193
+
194
+ def tar(folder)
195
+ puts "tar: #{folder}" if $VERBOSE
196
+
197
+ begin
198
+ fileIO = File.open("#{folder}.tar", 'wb')
199
+ tarIO = Archive::Tar::Minitar::Output.new(fileIO)
200
+ Dir.chdir(folder) do
201
+ files = Dir.entries('.') - ['.', '..']
202
+ files.each do |file|
203
+ Archive::Tar::Minitar.pack_file(file, tarIO)
204
+ end
205
+ end
206
+ ensure
207
+ tarIO.close # automatically does fileIO.close
208
+ end
209
+ FileUtils.rm_r(folder)
210
+ return "#{folder}.tar"
211
+ end
212
+
213
+ # Untar a folder.
214
+
215
+ def untar(file)
216
+ puts "untar: #{file}" if $VERBOSE
217
+
218
+ to_file = file.chomp('.tar')
219
+ FileUtils.mkdir_p(to_file)
220
+ #FileUtils.mv(file,unfile)
221
+ #Dir.chdir(tofile) do
222
+ Archive::Tar::Minitar.unpack(file,to_file)
223
+ FileUtils.rm(file)
224
+ #end
225
+ return to_file
226
+ end
227
+
228
+ # Compress file with gzip.
229
+
230
+ def gzip(file)
231
+ puts "gzip: #{file}" if $VERBOSE
232
+
233
+ Zlib::GzipWriter.open("#{file}.gz") do |gz|
234
+ gz.write File.read(file)
235
+ end
236
+ FileUtils.rm(file)
237
+ return "#{file}.gz"
238
+ end
239
+
240
+ # Uncompress a gzip file.
241
+
242
+ def gunzip(file)
243
+ puts "gunzip: #{file}" if $VERBOSE
244
+
245
+ to_file = file.chomp('.gz')
246
+ Zlib::GzipReader.open(file) do |gz|
247
+ File.open(to_file,'wb') do |f|
248
+ f << gz.read
249
+ end
250
+ end
251
+ FileUtils.rm(file)
252
+ return to_file
253
+ end
254
+
255
+ # Is gzip file with message.
256
+
257
+ def gzip?(file)
258
+ unless File.gzip?(file)
259
+ return nil.status(:not_rock_archive)
260
+ end
261
+ return true
262
+ end
263
+
264
+ # Is it okay to overwrite this file?
265
+
266
+ def write_okay?(file)
267
+ if File.exist?(file)
268
+ if $FORCE
269
+ FileUtils.rm_r(file)
270
+ else
271
+ return nil.status(:already_exists, file)
272
+ end
273
+ end
274
+ true
275
+ end
276
+
277
+ # Reserve a temproray file space.
278
+
279
+ def tmpdir
280
+ temp_folder = File.join(Dir.tmpdir,'rock')
281
+ FileUtils.rm_r( temp_folder )
282
+ FileUtils.mkdir_p( temp_folder )
283
+ temp_folder
284
+ end
285
+
286
+ end
287
+
288
+ end
289
+
290
+
291
+ # Errors module.
292
+
293
+ module Rock::Errors
294
+
295
+ extend self
296
+
297
+ def not_rock_archive
298
+ "file is not a rock archive"
299
+ end
300
+
301
+ def already_exists( file )
302
+ "'#{file}' already exits. Use -f to overwrite"
303
+ end
304
+
305
+ def no_rock_ext
306
+ "no .rock extension, either rename or use -f to replace"
307
+ end
308
+
309
+ end #module Errors