Class: Mast::Manifest
- Inherits:
-
Object
- Object
- Mast::Manifest
- Defined in:
- lib/mast/manifest.rb
Overview
Manifest stores a list of package files, and optionally checksums.
The class can be used to create and compare package manifests and digests.
Note that the #diff method currently shells out. Eventually this will be internalized.
Constant Summary collapse
- OverwriteError =
Manifest file overwrite error.
Class.new(Exception)
- NoManifestError =
No Manifest File Error.
Class.new(LoadError) do def ; "ERROR: no manifest file"; end end
- DEFAULT_EXCLUDE =
By default mast will exclude any pathname matching ‘CVS’, ‘_darcs’, ‘.git*’ or ‘.config’.
%w{CVS _darcs .git* .config}
- DEFAULT_IGNORE =
By default, mast will ignore any file with a name matching ‘.svn’ or ‘*~’, ie. ending with a tilde.
%w{*~ .svn}
- DEFAULT_FILE =
'{manifest,digest}{,.txt,.list}'
Instance Attribute Summary collapse
-
#all ⇒ Object
(also: #all?)
Do not exclude standard exclusions.
-
#bang ⇒ Object
(also: #bang?)
Show as if another manifest (i.e. use file’s bang options).
-
#digest ⇒ Object
Encryption type.
-
#dir ⇒ Object
(also: #dir?)
Include directories.
-
#directory ⇒ Object
Directory of manifest.
-
#exclude ⇒ Object
What files to exclude.
-
#file ⇒ Object
File used to store manifest/digest file.
-
#format ⇒ Object
Layout of digest – ‘csf’ or ‘sfv’.
-
#headless ⇒ Object
(also: #headless?)
Omit mast header from manifest output.
-
#ignore ⇒ Object
Special files to ignore.
-
#include ⇒ Object
What files to include.
-
#io ⇒ Object
An IO object to output manifest.
Class Method Summary collapse
-
.open(file = nil, options = {}) ⇒ Object
Possible file name (was for Fileable?).
Instance Method Summary collapse
-
#change_options(opts) ⇒ Object
Set options.
-
#changed? ⇒ Boolean
Is the current mainfest in need of updating?.
-
#chart ⇒ Object
Chart of current files (name => checksum).
-
#clean ⇒ Object
Clean non-manifest files.
- #cleanlist ⇒ Object
-
#diff ⇒ Object
Diff file against actual files.
-
#filechart ⇒ Object
Chart of files as given in MANIFEST file (name => checksum).
-
#filelist ⇒ Object
List of files as given in MANIFEST file.
-
#filename ⇒ Object
File’s basename.
-
#generate(out = nil) ⇒ Object
Generate manifest.
-
#initialize(options = {}) ⇒ Manifest
constructor
New Manifest object.
-
#list ⇒ Object
List of current files.
-
#list_without_folders ⇒ Object
List of files in file system, but omit folders.
-
#listing ⇒ Object
Produce textual listing less the manifest file.
- #read? ⇒ Boolean
-
#save ⇒ Object
Save as file.
- #showlist ⇒ Object
- #to_s ⇒ Object
-
#unlisted ⇒ Object
Files not listed in manifest.
-
#update ⇒ Object
Update file.
- #verify ⇒ Object
-
#whatsnew ⇒ Object
Files found in file system, but not listed in the manifest file.
-
#whatsold ⇒ Object
Files listed in the manifest file, but not found in file system.
Constructor Details
#initialize(options = {}) ⇒ Manifest
New Manifest object.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/mast/manifest.rb', line 121 def initialize(={}) @include = ['*'] @exclude = [] @ignore = [] @format = 'csf' @all = false @dir = false @bang = false @digest = nil @directory = Dir.pwd @io = $stdout () #if @file # read(@file) #else #if file = Dir.glob(self.class.filename)[0] # @file = file #else # @file = DEFAULT_FILE #end #end end |
Instance Attribute Details
#all ⇒ Object Also known as: all?
Do not exclude standard exclusions.
74 75 76 |
# File 'lib/mast/manifest.rb', line 74 def all @all end |
#bang ⇒ Object Also known as: bang?
Show as if another manifest (i.e. use file’s bang options).
80 81 82 |
# File 'lib/mast/manifest.rb', line 80 def bang @bang end |
#digest ⇒ Object
Encryption type
71 72 73 |
# File 'lib/mast/manifest.rb', line 71 def digest @digest end |
#dir ⇒ Object Also known as: dir?
Include directories.
77 78 79 |
# File 'lib/mast/manifest.rb', line 77 def dir @dir end |
#directory ⇒ Object
Directory of manifest.
65 66 67 |
# File 'lib/mast/manifest.rb', line 65 def directory @directory end |
#exclude ⇒ Object
What files to exclude.
92 93 94 |
# File 'lib/mast/manifest.rb', line 92 def exclude @exclude end |
#file ⇒ Object
File used to store manifest/digest file.
68 69 70 |
# File 'lib/mast/manifest.rb', line 68 def file @file end |
#format ⇒ Object
Layout of digest – ‘csf’ or ‘sfv’. Default is ‘csf’.
98 99 100 |
# File 'lib/mast/manifest.rb', line 98 def format @format end |
#headless ⇒ Object Also known as: headless?
Omit mast header from manifest output.
83 84 85 |
# File 'lib/mast/manifest.rb', line 83 def headless @headless end |
#ignore ⇒ Object
Special files to ignore.
95 96 97 |
# File 'lib/mast/manifest.rb', line 95 def ignore @ignore end |
#include ⇒ Object
What files to include. Defaults to [‘*’]. Note that Mast automatically recurses through directory entries, so using ‘*/’ would simply be a waste of of processing cycles.
89 90 91 |
# File 'lib/mast/manifest.rb', line 89 def include @include end |
#io ⇒ Object
An IO object to output manifest. Default is ‘$stdout`.
104 105 106 |
# File 'lib/mast/manifest.rb', line 104 def io @io end |
Class Method Details
.open(file = nil, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/mast/manifest.rb', line 55 def self.open(file=nil, ={}) unless file file = Dir.glob(filename, File::FNM_CASEFOLD).first raise NoManifestError, "Manifest file is required." unless file end [:file] = file new() end |
Instance Method Details
#change_options(opts) ⇒ Object
Set options.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/mast/manifest.rb', line 147 def (opts) opts.each do |k,v| k = k.to_s.downcase send("#{k}=",v||send(k)) end #@file = options[:file] || @file #@digest = options[:digest] || @digest #@all = options[:all] || @all #@exclude = options[:exclude] || options[:ignore] || @exclude #@exclude = [@exclude].flatten.compact end |
#changed? ⇒ Boolean
Is the current mainfest in need of updating?
174 175 176 177 178 179 180 |
# File 'lib/mast/manifest.rb', line 174 def changed? raise NoManifestError unless file and FileTest.file?(file) txt = File.read(file) out = StringIO.new #('', 'w') generate(out) out.string != txt end |
#chart ⇒ Object
Chart of current files (name => checksum).
268 269 270 |
# File 'lib/mast/manifest.rb', line 268 def chart @chart ||= parse_directory end |
#clean ⇒ Object
Clean non-manifest files.
252 253 254 255 256 257 258 259 260 |
# File 'lib/mast/manifest.rb', line 252 def clean cfiles, cdirs = cleanlist.partition{ |f| !File.directory?(f) } if cfiles.empty? && cdirs.empty? $stderr < "No difference between list and actual.\n" else FileUtils.rm(cfiles) FileUtils.rmdir(cdirs) end end |
#cleanlist ⇒ Object
283 284 285 |
# File 'lib/mast/manifest.rb', line 283 def cleanlist showlist - filelist end |
#diff ⇒ Object
Diff file against actual files.
TODO: Do not shell out for diff.
219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/mast/manifest.rb', line 219 def diff raise NoManifestError unless file and FileTest.file?(file) parse_topline # parse_file unless read? manifest = create_temporary_manifest begin result = `diff -du #{file} #{manifest.file}` ensure FileUtils.rm(manifest.file) end # pass = result.empty? return result end |
#filechart ⇒ Object
Chart of files as given in MANIFEST file (name => checksum).
278 279 280 |
# File 'lib/mast/manifest.rb', line 278 def filechart @filechart ||= parse_file end |
#filelist ⇒ Object
List of files as given in MANIFEST file.
273 274 275 |
# File 'lib/mast/manifest.rb', line 273 def filelist @filelist ||= filechart.keys.sort end |
#filename ⇒ Object
File’s basename.
317 318 319 |
# File 'lib/mast/manifest.rb', line 317 def filename File.basename(file) end |
#generate(out = nil) ⇒ Object
Generate manifest.
192 193 194 195 196 197 |
# File 'lib/mast/manifest.rb', line 192 def generate(out=nil) out ||= self.io parse_topline unless read? if bang? out << topline_string unless headless? output(out) end |
#list ⇒ Object
List of current files.
263 264 265 |
# File 'lib/mast/manifest.rb', line 263 def list @list ||= chart.keys.sort end |
#list_without_folders ⇒ Object
List of files in file system, but omit folders.
420 421 422 |
# File 'lib/mast/manifest.rb', line 420 def list_without_folders list.select{ |f| !File.directory?(f) } end |
#listing ⇒ Object
Produce textual listing less the manifest file.
426 427 428 429 430 |
# File 'lib/mast/manifest.rb', line 426 def listing str = '' output(str) str end |
#read? ⇒ Boolean
169 170 171 |
# File 'lib/mast/manifest.rb', line 169 def read? @read end |
#save ⇒ Object
Save as file.
207 208 209 210 211 212 213 |
# File 'lib/mast/manifest.rb', line 207 def save File.open(file, 'w') do |file| file << topline_string output(file) end return file end |
#showlist ⇒ Object
297 298 299 300 |
# File 'lib/mast/manifest.rb', line 297 def showlist parse_topline unless read? list end |
#to_s ⇒ Object
433 434 435 |
# File 'lib/mast/manifest.rb', line 433 def to_s topline_string + listing end |
#unlisted ⇒ Object
Files not listed in manifest.
288 289 290 291 292 293 294 |
# File 'lib/mast/manifest.rb', line 288 def unlisted list = [] Dir.chdir(directory) do list = Dir.glob('**/*') end list - filelist end |
#update ⇒ Object
Update file.
200 201 202 203 204 |
# File 'lib/mast/manifest.rb', line 200 def update raise NoManifestError unless file and FileTest.file?(file) parse_topline save end |
#verify ⇒ Object
246 247 248 249 |
# File 'lib/mast/manifest.rb', line 246 def verify parse_file unless read? chart == filechart end |
#whatsnew ⇒ Object
Files found in file system, but not listed in the manifest file.
240 241 242 243 |
# File 'lib/mast/manifest.rb', line 240 def whatsnew parse_file unless read? list - (filelist + [filename]) end |
#whatsold ⇒ Object
Files listed in the manifest file, but not found in file system.
234 235 236 237 |
# File 'lib/mast/manifest.rb', line 234 def whatsold parse_file unless read? filelist - list end |