ratch 0.3.0 → 0.4.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 (132) hide show
  1. data/{log/history → CHANGES} +0 -0
  2. data/{log/todo → TODO} +0 -0
  3. data/bin/manifest +451 -0
  4. data/bin/ratch +3 -3
  5. data/demo/task/config.yaml +4 -0
  6. data/lib/ratch/{batch/argvutils.rb → dsl/argv.rb} +9 -4
  7. data/lib/ratch/dsl/batch.rb +226 -0
  8. data/lib/ratch/{batch → dsl}/build.rb +83 -4
  9. data/lib/ratch/{batch/consoleutils.rb → dsl/console.rb} +13 -5
  10. data/lib/ratch/{batch/emailutils.rb → dsl/email.rb} +21 -25
  11. data/lib/ratch/{batch/fileutils.rb → dsl/file.rb} +56 -56
  12. data/lib/ratch/dsl/meta.rb +132 -0
  13. data/lib/ratch/{batch → dsl}/options.rb +7 -5
  14. data/lib/ratch/dsl/setup.rb +124 -0
  15. data/lib/ratch/{support/signiture.rb → dsl/sign.rb} +9 -18
  16. data/lib/ratch/dsl/stage.rb +147 -0
  17. data/lib/ratch/dsl/task.rb +139 -0
  18. data/lib/ratch/{uploadutils.rb → dsl/upload.rb} +7 -5
  19. data/lib/ratch/{batch/task.rb → dsl/zip.rb} +30 -14
  20. data/lib/ratch/dsl.rb +52 -0
  21. data/lib/ratch/extra/email.rb +5 -0
  22. data/lib/ratch/extra/stage.rb +5 -0
  23. data/lib/ratch/extra/zip.rb +5 -0
  24. data/lib/ratch/manifest.rb +540 -0
  25. data/lib/ratch/{project → metadata}/information.rb +1 -0
  26. data/lib/ratch/{project → metadata}/package.rb +28 -2
  27. data/lib/ratch/{project → metadata}/project.rb +8 -16
  28. data/lib/ratch/{project → metadata}/release.rb +6 -6
  29. data/lib/ratch/support/errors.rb +4 -0
  30. data/lib/ratch/support/filename.rb +18 -0
  31. data/lib/ratch/toolset/ruby/compile +49 -0
  32. data/lib/ratch/toolset/ruby/pack/gem +26 -18
  33. data/lib/ratch/toolset/ruby/pack/tgz +25 -64
  34. data/lib/ratch/toolset/ruby/pack/zip +46 -0
  35. data/lib/ratch/toolset/ruby/publish +23 -24
  36. data/lib/ratch/toolset/ruby/release +8 -0
  37. data/lib/ratch/toolset/ruby/stamp +33 -0
  38. data/lib/ratch/toolset/sandbox +11 -0
  39. data/meta/MANIFEST +101 -23
  40. data/meta/ROLLRC +1 -1
  41. data/meta/config.yaml +10 -0
  42. data/meta/icli.yaml +2 -2
  43. data/meta/project.yaml +9 -10
  44. data/meta/xProjectInfo +41 -0
  45. data/task/release +1 -4
  46. metadata +82 -156
  47. data/demo/task/rdoc +0 -88
  48. data/demo/task/rdoc-old +0 -182
  49. data/doc/images/clipboard.jpg +0 -0
  50. data/doc/images/clipboard2.png +0 -0
  51. data/doc/images/milles-tn.jpg +0 -0
  52. data/doc/images/mints.png +0 -0
  53. data/doc/images/ratch2.png +0 -0
  54. data/doc/images/ruby-sm.png +0 -0
  55. data/doc/images/silver.gif +0 -0
  56. data/doc/images/toolbox.jpg +0 -0
  57. data/doc/index.html +0 -181
  58. data/doc/notes/original.rb +0 -308
  59. data/doc/rdoc/classes/Array.html +0 -194
  60. data/doc/rdoc/classes/Dir.html +0 -317
  61. data/doc/rdoc/classes/Hash.html +0 -217
  62. data/doc/rdoc/classes/Ratch/ArgvUtils/Ext.html +0 -285
  63. data/doc/rdoc/classes/Ratch/ArgvUtils.html +0 -173
  64. data/doc/rdoc/classes/Ratch/BatchFile.html +0 -207
  65. data/doc/rdoc/classes/Ratch/BatchManager.html +0 -250
  66. data/doc/rdoc/classes/Ratch/BatchScript.html +0 -127
  67. data/doc/rdoc/classes/Ratch/Batchable.html +0 -373
  68. data/doc/rdoc/classes/Ratch/Build.html +0 -321
  69. data/doc/rdoc/classes/Ratch/BuildManager.html +0 -319
  70. data/doc/rdoc/classes/Ratch/Buildable.html +0 -202
  71. data/doc/rdoc/classes/Ratch/ConfigUtils.html +0 -281
  72. data/doc/rdoc/classes/Ratch/ConsoleUtils.html +0 -189
  73. data/doc/rdoc/classes/Ratch/EmailUtils.html +0 -209
  74. data/doc/rdoc/classes/Ratch/FileUtils.html +0 -674
  75. data/doc/rdoc/classes/Ratch/GeneralOptions.html +0 -430
  76. data/doc/rdoc/classes/Ratch/Task.html +0 -201
  77. data/doc/rdoc/classes/Ratch/TaskManager.html +0 -330
  78. data/doc/rdoc/classes/Ratch/Taskable.html +0 -231
  79. data/doc/rdoc/classes/Ratch/UploadUtils.html +0 -566
  80. data/doc/rdoc/classes/Ratch.html +0 -201
  81. data/doc/rdoc/created.rid +0 -1
  82. data/doc/rdoc/files/COPYING.html +0 -1003
  83. data/doc/rdoc/files/README.html +0 -143
  84. data/doc/rdoc/files/lib/ratch/argvutils_rb.html +0 -131
  85. data/doc/rdoc/files/lib/ratch/batch_rb.html +0 -155
  86. data/doc/rdoc/files/lib/ratch/batchable_rb.html +0 -131
  87. data/doc/rdoc/files/lib/ratch/batchfile_rb.html +0 -148
  88. data/doc/rdoc/files/lib/ratch/buildable_rb.html +0 -131
  89. data/doc/rdoc/files/lib/ratch/consoleutils_rb.html +0 -131
  90. data/doc/rdoc/files/lib/ratch/emailutils_rb.html +0 -139
  91. data/doc/rdoc/files/lib/ratch/facets/multiglob_rb.html +0 -137
  92. data/doc/rdoc/files/lib/ratch/fileutils_rb.html +0 -139
  93. data/doc/rdoc/files/lib/ratch/options_rb.html +0 -131
  94. data/doc/rdoc/files/lib/ratch/taskable_rb.html +0 -131
  95. data/doc/rdoc/files/lib/ratch/uploadutils_rb.html +0 -150
  96. data/doc/rdoc/fr_class_index.html +0 -48
  97. data/doc/rdoc/fr_file_index.html +0 -41
  98. data/doc/rdoc/fr_method_index.html +0 -133
  99. data/doc/rdoc/index.html +0 -24
  100. data/doc/rdoc/rdoc-style.css +0 -208
  101. data/doc/scrap/flexihead-flip.jpg +0 -0
  102. data/doc/scrap/flexihead.jpg +0 -0
  103. data/doc/scrap/head1.jpg +0 -0
  104. data/doc/scrap/ratch.jpg +0 -0
  105. data/doc/scrap/ratch1.png +0 -0
  106. data/doc/scrap/ratch2.jpg +0 -0
  107. data/doc/scrap/ratch3.png +0 -0
  108. data/doc/scrap/red-ratch.jpg +0 -0
  109. data/doc/scrap/redratchet.jpg +0 -0
  110. data/doc/scrap/ruby-kit/ruby.png +0 -0
  111. data/doc/scrap/scrap.red +0 -256
  112. data/doc/sitemap.yaml +0 -10
  113. data/doc/siteparts/index.red +0 -100
  114. data/doc/siteparts/layout.rhtml +0 -56
  115. data/doc/siteparts/tutorial.red +0 -578
  116. data/doc/style.css +0 -112
  117. data/doc/tutorial.html +0 -722
  118. data/lib/ratch/batch.rb +0 -488
  119. data/lib/ratch/support/setuputils.rb +0 -124
  120. data/lib/ratch/support/stage.rb +0 -292
  121. data/lib/ratch/toolset/ruby/rdoc +0 -88
  122. data/task/rdoc +0 -6
  123. data/work/old/batchfile.rb +0 -95
  124. data/work/project-old.rb +0 -67
  125. data/work/scrap/install +0 -89
  126. data/work/scrap/install.0 +0 -49
  127. data/work/scrap/install.1 +0 -63
  128. data/work/scrap/ludo +0 -25
  129. data/work/scrap/oldtaskable.rb +0 -573
  130. data/work/scrap/ratch.man +0 -39
  131. data/work/scrap/taskable-simple.rb +0 -42
  132. data/work/scrap/taskable.rb +0 -120
@@ -1,12 +1,12 @@
1
- # TITLE:
1
+ # = TITLE:
2
2
  #
3
- # Task
3
+ # Zip DSL
4
4
  #
5
- # COPYING:
5
+ # = COPYING:
6
6
  #
7
7
  # Copyright (c) 2007 Psi T Corp.
8
8
  #
9
- # This file is part of the ProUtils' Ratch program.
9
+ # This file is part of the Ratch program.
10
10
  #
11
11
  # Ratch is free software: you can redistribute it and/or modify
12
12
  # it under the terms of the GNU General Public License as published by
@@ -21,23 +21,39 @@
21
21
  # You should have received a copy of the GNU General Public License
22
22
  # along with Ratch. If not, see <http://www.gnu.org/licenses/>.
23
23
 
24
+ require 'facets/ziputils'
25
+
24
26
  module Ratch
27
+ module Dsl
28
+
29
+ module Zip
30
+
31
+ #
32
+
33
+ def zip(folder, file=nil, options={})
34
+ ziputils.zip(folder, file, options)
35
+ end
25
36
 
26
- # Task is a very simple store for the defined
27
- # actions and it's prerequisites.
37
+ #
28
38
 
29
- class Task
30
- attr_reader :name, :needs, :action
39
+ def tar_bzip(folder, file=nil, options={})
40
+ ziputils.tar_bzip(folder, file, options)
41
+ end
42
+
43
+ #
31
44
 
32
- def initialize(name, *needs, &action)
33
- @name = name.to_s
34
- @needs = needs
35
- @action = action
45
+ def tar_gzip(folder, file=nil, options={})
46
+ ziputils.tar_gzip(folder, file, options)
36
47
  end
48
+ alias_method :tgz, :tar_gzip
49
+
50
+ # Delegate access to ZipUtils.
37
51
 
38
- def call
39
- @action.call if @action
52
+ def ziputils
53
+ dryrun? ? ::ZipUtils::DryRun : ::ZipUtils
40
54
  end
55
+
41
56
  end
42
57
 
43
58
  end
59
+ end
data/lib/ratch/dsl.rb ADDED
@@ -0,0 +1,52 @@
1
+ # = TITLE:
2
+ #
3
+ # Main DSL Loader
4
+ #
5
+ # = COPYING:
6
+ #
7
+ # Copyright (c) 2007 Psi T Corp.
8
+ #
9
+ # This file is part of the ProUtils' Ratch program.
10
+ #
11
+ # Ratch is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation, either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # Ratch is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with Ratch. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ require 'yaml' # make it generally available
25
+ require 'rbconfig' # replace with facets/system?
26
+
27
+ require 'ratch/dsl/options'
28
+ require 'ratch/dsl/batch'
29
+ require 'ratch/dsl/build'
30
+ require 'ratch/dsl/task'
31
+ require 'ratch/dsl/console'
32
+ require 'ratch/dsl/file'
33
+ require 'ratch/dsl/argv'
34
+ require 'ratch/dsl/meta'
35
+
36
+ # Load ratch dsl functionality into toplevel.
37
+ # This loads into the toplevel's metaclass b/c we don't want
38
+ # all these utilies to invade every object [do we?]
39
+
40
+ class << self
41
+ include Ratch::Dsl::Options
42
+ include Ratch::Dsl::Batch
43
+ include Ratch::Dsl::Builds
44
+ include Ratch::Dsl::Tasks
45
+ include Ratch::Dsl::Filing
46
+ include Ratch::Dsl::Console
47
+ include Ratch::Dsl::Argv
48
+ include Ratch::Dsl::Meta
49
+ end
50
+
51
+ # run main task
52
+ END { run_main }
@@ -0,0 +1,5 @@
1
+ require 'ratch/dsl/email'
2
+
3
+ class << self
4
+ include Ratch::Dsl::Email
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'ratch/dsl/stage'
2
+
3
+ class << self
4
+ include Ratch::Dsl::Stage
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'ratch/dsl/zip'
2
+
3
+ class << self
4
+ include Ratch::Dsl::Zip
5
+ end
@@ -0,0 +1,540 @@
1
+ # = TITLE:
2
+ #
3
+ # Manifest
4
+ #
5
+ # = SYNOPSIS:
6
+ #
7
+ # Generate manifest/digest list. Usefule for including in package distributions.
8
+ #
9
+ # = COPYING:
10
+ #
11
+ # Copyright (c) 2007 Psi T Corp.
12
+ #
13
+ # This file is part of the ProUtils' Ratch program.
14
+ #
15
+ # Ratch is free software: you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Public License as published by
17
+ # the Free Software Foundation, either version 3 of the License, or
18
+ # (at your option) any later version.
19
+ #
20
+ # Ratch is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU General Public License for more details.
24
+ #
25
+ # You should have received a copy of the GNU General Public License
26
+ # along with Ratch. If not, see <http://www.gnu.org/licenses/>.
27
+ #
28
+ # = TODO:
29
+ # - Integrate file signing and general manifest better (?)
30
+ # - Digester is in sign.rb too. Dry-up?
31
+ # - Is it problematic to add a digest to the manifest?
32
+ # - This needs some TLC. Eg. diff is shelling out, but it would
33
+ # be better if internalized.
34
+ # - Could just use some over all belt tightening.
35
+
36
+ require 'fileutils'
37
+ require 'getoptlong'
38
+ require 'shellwords'
39
+
40
+ require 'facets/dir/multiglob' # for Dir.multiglob_r
41
+ require 'facets/file/read' # for File.read_list
42
+
43
+ module Ratch
44
+
45
+ # Manifest file overwrite error.
46
+ #
47
+ class OverwriteError < Exception
48
+ end
49
+
50
+ # No Manifest File Error.
51
+ #
52
+ class NoManifestError < LoadError
53
+ end
54
+
55
+ # Manifest stores a list of package files, and optionally checksums.
56
+ #
57
+ # The class can be used to create and compare package manifests.
58
+
59
+ class Manifest
60
+
61
+ DEFAULT_EXCLUDE = %w{ InstalledFiles .config *~ CVS _darcs .svn .git }
62
+ DEFAULT_FILE = '{,meta/}manifest{,.txt,.list}'
63
+
64
+ # Possible file name (was for Fileable?).
65
+ def self.filename
66
+ DEFAULT_FILE
67
+ end
68
+
69
+ def self.open(file=nil, options={})
70
+ unless file
71
+ file = Dir.glob(filename, File::FNM_CASEFOLD).first
72
+ raise LoadError, "Manifest file is required." unless file
73
+ end
74
+ options.update(:file => file)
75
+ self.new(options)
76
+ end
77
+
78
+ # File used to store digest/manifest.
79
+
80
+ attr_accessor :file
81
+
82
+ # Encryption type
83
+
84
+ attr_accessor :digest
85
+
86
+ # Do not exclude standard exclusions.
87
+
88
+ attr_accessor :all
89
+ alias_method :all?, :all
90
+
91
+ # What files to exclude from digest.
92
+
93
+ attr_accessor :exclude
94
+ alias_method :ignore, :exclude
95
+
96
+ # Directory to use.
97
+
98
+ attr_accessor :directory
99
+
100
+ # Layout of digest -- csf or sfv. Default is csf.
101
+
102
+ attr_accessor :format
103
+
104
+ # Files and checksums listed in file.
105
+
106
+ attr_reader :list
107
+
108
+ # New Digest object.
109
+
110
+ def initialize(options={})
111
+ @exclude = []
112
+
113
+ change_options(options)
114
+
115
+ if @file
116
+ read(@file)
117
+ #else
118
+ #if file = Dir.glob(self.class.filename)[0]
119
+ # @file = file
120
+ #else
121
+ # @file = DEFAULT_FILE
122
+ #end
123
+ end
124
+ end
125
+
126
+ # Set options.
127
+
128
+ def change_options(opts)
129
+ opts.each do |k,v|
130
+ k = k.to_s.downcase
131
+ send("#{k}=",v||send(k))
132
+ end
133
+ #@file = options[:file] || @file
134
+ #@digest = options[:digest] || @digest
135
+ #@all = options[:all] || @all
136
+ #@exclude = options[:exclude] || options[:ignore] || @exclude
137
+ #@exclude = [@exclude].flatten.compact
138
+ end
139
+
140
+ #
141
+
142
+ def file?
143
+ @read_from_file
144
+ end
145
+
146
+ # Create a digest/manifest file. This saves the list of files
147
+ # and optionally their checksum.
148
+
149
+ #def create(options=nil)
150
+ # change_options(options) if options
151
+ # #@file ||= DEFAULT_FILE
152
+ # raise OverwriteError if FileTest.file?(file)
153
+ # save #(false)
154
+ #end
155
+
156
+ # Update file.
157
+
158
+ def update(options=nil)
159
+ change_options(options) if options
160
+ raise NoManifestError unless file and FileTest.file?(file)
161
+ save
162
+ end
163
+
164
+ # Save as file.
165
+
166
+ def save(options=nil)
167
+ change_options(options) if options
168
+ File.open(file, 'w') do |file|
169
+ file << topline_string
170
+ output(file)
171
+ end
172
+ return file
173
+ end
174
+
175
+ # Diff file against actual files.
176
+
177
+ def diff
178
+ raise NoManifestError unless file and FileTest.file?(file)
179
+ manifest = create_temporary_manifest
180
+ begin
181
+ result = `diff -du #{file} #{manifest.file}`
182
+ ensure
183
+ FileUtils.rm(manifest.file)
184
+ end
185
+ # pass = result.empty?
186
+ return result
187
+ end
188
+
189
+ # Files listed in manifest, but not found.
190
+
191
+ def whatsold
192
+ #raise ManifestMissing unless file
193
+ filelist - files
194
+ end
195
+
196
+ # Files found, but not listed in manifest.
197
+
198
+ def whatsnew
199
+ #raise ManifestMissing unless file
200
+ files - (filelist + [filename])
201
+ end
202
+
203
+ # Clean non-manifest files.
204
+
205
+ def clean
206
+ cfiles, cdirs = clean_files.partition{ |f| !File.directory?(f) }
207
+ FileUtils.rm(cfiles)
208
+ FileUtils.rmdir(cdirs)
209
+ end
210
+
211
+ #
212
+
213
+ def clean_files
214
+ keep = Dir.glob('*').select{|f| File.directory?(f)}
215
+ keep << filename # keep manifest
216
+ Dir.glob('**/*') - (files + keep)
217
+ end
218
+
219
+ # # Clobber non-manifest files.
220
+ # #
221
+ # def clobber
222
+ # clobber_files.each{ |f| rm_r(f) if File.exist?(f) }
223
+ # end
224
+ #
225
+ # #--
226
+ # # TODO Should clobber work off the manifest file itself?
227
+ # #++
228
+ # def clobber_files
229
+ # keep = filelist # + [info.manifest]
230
+ # Dir.glob('**/*') - keep
231
+ # end
232
+
233
+ # File's name.
234
+
235
+ def filename
236
+ File.basename(file)
237
+ end
238
+
239
+ # File's location.
240
+
241
+ def location
242
+ #if directory
243
+ # directory
244
+ #if file
245
+ # File.dirname(file)
246
+ #else
247
+ @location = @directory || Dir.pwd
248
+ #end
249
+ end
250
+
251
+ # List of files as given in the file.
252
+
253
+ def filelist
254
+ list.keys.sort
255
+ end
256
+
257
+ # Generate manifest.
258
+
259
+ def generate(out=$stdout)
260
+ out << topline_string
261
+ output(out)
262
+ end
263
+
264
+ #
265
+
266
+ def output(out=$stdout)
267
+ Dir.chdir(location) do
268
+ rec_output('*', out)
269
+ end
270
+ end
271
+
272
+ # Generate listing on the fly.
273
+
274
+ def rec_output(match, out=$stdout)
275
+ out.flush
276
+ #match = (location == dir ? '*' : File.join(dir,'*'))
277
+ files = Dir.glob(match) - exclusions
278
+ files.sort!
279
+ files.each do |file|
280
+ sum = checksum(file,digest)
281
+ sum = sum + ' ' if sum
282
+ out << "#{sum}#{file}\n"
283
+ if File.directory?(file)
284
+ rec_output(File.join(file,'*'), out)
285
+ end
286
+ end
287
+ #return out
288
+ end
289
+ private :rec_output
290
+
291
+
292
+ # List files in package.
293
+
294
+ def files #(update=false)
295
+ #remove = (update ? (exclude + topline.exclude) : exclude)
296
+ #remove = exclude
297
+ #remove += DEFAULT_EXCLUDE unless all?
298
+ #remove += [filename, filename.chomp('~')]
299
+
300
+ files = []
301
+ Dir.chdir(location) do
302
+ files += Dir.multiglob_r('**/*')
303
+ files -= Dir.multiglob_r(exclusions)
304
+ end
305
+ return files
306
+ end
307
+
308
+ # Compute exclusions.
309
+
310
+ def exclusions
311
+ @_exclusions ||= (
312
+ e = exclude
313
+ e += DEFAULT_EXCLUDE unless all?
314
+ e += [filename, filename.chomp('~')] if file
315
+ e
316
+ )
317
+ end
318
+
319
+ # List of files in package, but omit folders.
320
+
321
+ def files_without_folders
322
+ files.select{ |f| !File.directory?(f) }
323
+ end
324
+
325
+ # Produce textual listing less the manifest file.
326
+
327
+ def listing
328
+ str = ''
329
+ output(str)
330
+ str
331
+
332
+ # #crypt = (update ? (digest || topline.digest) : digest)
333
+ # crypt = digest
334
+ #
335
+ # list = files #(update) #- [filename, filename.chomp('~')]
336
+ # list.sort!
337
+ # list.collect!{ |file| [checksum(file,crypt), file] }
338
+ # list.collect!{ |file| file.compact.join(' ') }
339
+ # list.join("\n") + "\n"
340
+ end
341
+
342
+ # File content.
343
+
344
+ def to_s #(update=false)
345
+ topline_string + listing #(update) + listing(update)
346
+ end
347
+
348
+ private
349
+
350
+ # Create temporary manifest (for comparison).
351
+
352
+ def create_temporary_manifest
353
+ temp_manifest = Manifest.new
354
+ temp_manifest.save(
355
+ :file => file+"~",
356
+ :digest => digest,
357
+ :exclude => exclude,
358
+ :all => all
359
+ )
360
+ #File.open(tempfile, 'w+') do |f|
361
+ # f << to_s(true)
362
+ #end
363
+ return temp_manifest
364
+ end
365
+
366
+ # Produce hexdigest/cheksum for a file.
367
+ # Default digest type is sha1.
368
+
369
+ def checksum(file, digest=nil)
370
+ return nil unless digest
371
+ if FileTest.directory?(file)
372
+ @null_string ||= digester(digest).hexdigest("")
373
+ else
374
+ digester(digest).hexdigest(File.read(file))
375
+ end
376
+ end
377
+
378
+ # Return a digest class for given +type+.
379
+ # Supported digests are:
380
+ #
381
+ # * md5
382
+ # * sha1
383
+ # * sha128 (same as sha1)
384
+ # * sha256
385
+ # * sha512
386
+ #
387
+ # Default digest type is sha256.
388
+
389
+ def digester(type=nil)
390
+ require 'openssl'
391
+ case type.to_s.downcase
392
+ when 'md5'
393
+ require 'digest/md5'
394
+ ::Digest::MD5
395
+ when 'sha128', 'sha1'
396
+ require 'digest/sha1' #need?
397
+ OpenSSL::Digest::SHA1
398
+ when 'sha256'
399
+ require 'digest/sha1' #need?
400
+ OpenSSL::Digest::SHA256
401
+ when 'sha512'
402
+ require 'digest/sha1' #need?
403
+ OpenSSL::Digest::SHA512
404
+ else
405
+ raise "unsupported digest #{type}"
406
+ end
407
+ end
408
+
409
+ # Read manifest file.
410
+
411
+ def read(file)
412
+ @file = file
413
+ #@location = File.dirname(File.expand_path(file))
414
+
415
+ l = {}
416
+ flist = File.read_list(file)
417
+ flist.each do |line|
418
+ left, right = line.split(/\s+/)
419
+ if right
420
+ checksum = left
421
+ filename = right
422
+ l[filename] = checksum
423
+ else
424
+ filename = left
425
+ l[filename] = nil
426
+ end
427
+ end
428
+
429
+ a, d, x = *topline_parse
430
+
431
+ @list = l
432
+ @all = a
433
+ @digest = d
434
+ @exclude = x
435
+
436
+ @read_from_file = file
437
+ end
438
+
439
+ # Get topline of Manifest file, parse and cache.
440
+ #def topline
441
+ # @topline ||= topline_parse
442
+ #end
443
+
444
+ #TOPLINE_ARITY = {:x=>1, :exclude=>1, :g=>1, :digest=>1}
445
+
446
+ #
447
+ def topline_parse
448
+ if line = read_topline
449
+ argv = Shellwords.shellwords(line)
450
+ ARGV.replace(argv)
451
+ opts = GetoptLong.new(
452
+ [ '-g', '--digest' , GetoptLong::REQUIRED_ARGUMENT ],
453
+ [ '-x', '--exclude', '--ignore', GetoptLong::REQUIRED_ARGUMENT ],
454
+ [ '-a', '--all' , GetoptLong::NO_ARGUMENT ]
455
+ )
456
+ a, d, x = false, nil, []
457
+ opts.each do |opt, arg|
458
+ case opt
459
+ when '-g': d = arg.downcase
460
+ when '-a': a = true
461
+ when '-x': x << arg
462
+ end
463
+ end
464
+ return a, d, x
465
+ end
466
+ end
467
+
468
+ #
469
+ def read_topline
470
+ r = nil
471
+ #if file = locate(filename)
472
+ File.open(file) do |f|
473
+ s = f.readline
474
+ if s =~ /^#\s*(.*?)\n/
475
+ r = $1
476
+ end
477
+ end
478
+ return r
479
+ #end
480
+ end
481
+
482
+ # Create topline of MANIFEST file.
483
+ #
484
+ def topline_string(update=false)
485
+ if update
486
+ a = all #|| topline.all
487
+ d = digest #|| topline.digest
488
+ x = exclude #+ topline.exclude
489
+ else
490
+ a, d, x = all, digest, exclude
491
+ end
492
+ top = []
493
+ top << "-a" if a
494
+ top << "-g #{d.to_s.downcase}" if d
495
+ x.each do |e|
496
+ top << "-x #{e}"
497
+ end
498
+ return "# #{top.join(' ')}\n"
499
+ end
500
+
501
+ end
502
+
503
+ end
504
+
505
+
506
+
507
+ =begin
508
+ #
509
+ def manifest_file
510
+ apply_naming_policy(@file || DEFAULT_FILE, 'txt')
511
+ end
512
+
513
+ private
514
+
515
+ # Apply naming policy.
516
+ #
517
+ def apply_naming_policy(name, ext)
518
+ return name unless policy
519
+ policies = naming_policy.split(' ')
520
+ policies.each do |polic|
521
+ case polic
522
+ when 'downcase'
523
+ name = name.downcase
524
+ when 'upcase'
525
+ name = name.upcase
526
+ when 'capitalize'
527
+ name = name.capitalize
528
+ when 'extension'
529
+ name = name + ".#{ext}"
530
+ when 'plain'
531
+ name = name.chomp(File.extname(name))
532
+ else
533
+ name
534
+ end
535
+ end
536
+ return name
537
+ end
538
+ =end
539
+
540
+ #end # module Ratchets
@@ -21,6 +21,7 @@
21
21
  # You should have received a copy of the GNU General Public License
22
22
  # along with Ratch. If not, see <http://www.gnu.org/licenses/>.
23
23
 
24
+ require 'yaml'
24
25
  require 'facets/hash/rekey'
25
26
 
26
27