escoffier 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Manifest.txt +13 -0
- data/README.rdoc +44 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/bin/mise +81 -0
- data/bin/normalize_directory.rb +68 -0
- data/escoffier.gemspec +68 -0
- data/lib/escoffier.rb +11 -0
- data/lib/escoffier/compressible.rb +100 -0
- data/lib/escoffier/core_additions.rb +9 -0
- data/lib/escoffier/normalizer.rb +112 -0
- data/lib/escoffier/smepable.rb +25 -0
- data/spec/escoffier_spec.rb +11 -0
- data/spec/normalizer_spec.rb +23 -0
- data/spec/smepable_spec.rb +56 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +107 -0
data/.gitignore
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= escoffier
|
2
|
+
|
3
|
+
Escoffier is a prep chef for simple administrative tasks that I need, like
|
4
|
+
managing the file system to make a local copy and unzip of large directories
|
5
|
+
and the like.
|
6
|
+
|
7
|
+
* Source at: http://github.com/kastman/escoffier
|
8
|
+
|
9
|
+
== DESCRIPTION:
|
10
|
+
|
11
|
+
You'll probably want to 'include compressible' or use the `mise` executible.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
mise /my/large/directory
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* Unzipping is done via brianmario's bzip2-ruby gem, or if that fails (for very large files), falls back to a system call to `bzip2`
|
20
|
+
|
21
|
+
== LICENSE:
|
22
|
+
|
23
|
+
(The MIT License)
|
24
|
+
|
25
|
+
Copyright (c) 2010 Kastman
|
26
|
+
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
28
|
+
a copy of this software and associated documentation files (the
|
29
|
+
'Software'), to deal in the Software without restriction, including
|
30
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
31
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
32
|
+
permit persons to whom the Software is furnished to do so, subject to
|
33
|
+
the following conditions:
|
34
|
+
|
35
|
+
The above copyright notice and this permission notice shall be
|
36
|
+
included in all copies or substantial portions of the Software.
|
37
|
+
|
38
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
39
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
40
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
41
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
42
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
43
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
44
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gemspec|
|
6
|
+
gemspec.name = "escoffier"
|
7
|
+
gemspec.summary = "Mise en Place Prep Tasks"
|
8
|
+
gemspec.description = "Administrative prep tasks, from mother sauces to hotel pans."
|
9
|
+
gemspec.email = "ekk@medicine.wisc.edu"
|
10
|
+
gemspec.homepage = "http://github.com/kastman/escoffier"
|
11
|
+
gemspec.authors = ["Erik Kastman"]
|
12
|
+
gemspec.add_dependency('bzip2-ruby')
|
13
|
+
gemspec.add_development_dependency('rspec')
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/mise
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'etc'
|
6
|
+
require 'pathname'
|
7
|
+
require 'logger'
|
8
|
+
require 'tmpdir'
|
9
|
+
require 'escoffier'
|
10
|
+
|
11
|
+
def parse_options
|
12
|
+
options = Hash.new
|
13
|
+
parser = OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: #{__FILE__} [options] paths"
|
15
|
+
|
16
|
+
opts.on('-o', '--output OUTPUT_DIRECTORY', "Output Destination Directory") do |dir|
|
17
|
+
options[:output] = dir
|
18
|
+
abort "Cannot find directory #{dir}." unless File.directory?(File.dirname(dir))
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-t', '--temp', "Make a temporary directory for output") do |dir|
|
22
|
+
options[:mktmpdir] = true
|
23
|
+
abort "Output directory already specified - not creating a temporary directory." if options[:dir]
|
24
|
+
end
|
25
|
+
|
26
|
+
# opts.on('-f', '--[no-]force', "Force Overwrite of the sandbox") do |f|
|
27
|
+
# options[:force] = f
|
28
|
+
# end
|
29
|
+
|
30
|
+
opts.on('-v', '--[no-]verbose', "Get detailed output") do |v|
|
31
|
+
options[:verbose] = v
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on_tail('-h', '--help', "Show this message") { puts(parser); exit }
|
35
|
+
end
|
36
|
+
|
37
|
+
parser.parse!(ARGV)
|
38
|
+
return options
|
39
|
+
end
|
40
|
+
|
41
|
+
def prep_mise(directories, options)
|
42
|
+
if options[:output]
|
43
|
+
destination = options[:output]
|
44
|
+
elsif options[:mktmpdir]
|
45
|
+
begin
|
46
|
+
destination = Dir.mktmpdir
|
47
|
+
rescue
|
48
|
+
begin
|
49
|
+
destination = Dir.tmpdir
|
50
|
+
rescue
|
51
|
+
destination = '/tmp/'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
destination = Dir.pwd
|
56
|
+
end
|
57
|
+
|
58
|
+
directories.each do |directory|
|
59
|
+
# if options[:force]
|
60
|
+
# sandbox_dir = File.join(destination, File.basename(directory))
|
61
|
+
# if File.exist?(sandbox_dir)
|
62
|
+
# $LOG.info "Freshening up #{sandbox_dir}"
|
63
|
+
# FileUtils.rm_r(sandbox_dir)
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
|
67
|
+
directory.prep_mise_to(destination)
|
68
|
+
end
|
69
|
+
|
70
|
+
Dir.chdir(destination)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
|
75
|
+
$LOG = Logger.new(STDOUT)
|
76
|
+
$LOG.level = Logger::INFO
|
77
|
+
|
78
|
+
options = parse_options
|
79
|
+
directories = ARGV.collect { |dir| Pathname.new(dir) }
|
80
|
+
prep_mise(directories, options)
|
81
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
3
|
+
|
4
|
+
# require 'rubygems'
|
5
|
+
require 'optparse'
|
6
|
+
require 'etc'
|
7
|
+
require 'logger'
|
8
|
+
require 'yaml'
|
9
|
+
require 'escoffier'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def parse_options
|
14
|
+
options = Hash.new
|
15
|
+
parser = OptionParser.new do |opts|
|
16
|
+
opts.banner = "Usage: normalize_directory.rb [options] list of directories."
|
17
|
+
|
18
|
+
# opts.on('-d', '--directory DIR', "Directory to Normalize") do |dir|
|
19
|
+
# abort
|
20
|
+
# options[:directory] = dir
|
21
|
+
# end
|
22
|
+
|
23
|
+
opts.on('-u', '--user USER', "The user who should own the files.") do |user|
|
24
|
+
abort "Cannot find user #{user}." unless Etc.getpwnam(user)
|
25
|
+
options[:user] = user
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-g', '--group GROUP', "The group who should own the files.") do |group|
|
29
|
+
abort "Cannot find group #{group}." unless Etc.getgrnam(group)
|
30
|
+
options[:group] = group
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-s', '--spec FILE', "A configuration file of directories.") do |file|
|
34
|
+
options[:specfile] = file
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('--dry-run', "Display Ownership Changes but don't make them.") do
|
38
|
+
options[:dry_run] = true
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on_tail('-h', '--help', "Show this message") { puts(parser); exit }
|
42
|
+
opts.on_tail("Example: normalize_directory.rb -u raw -g raw /Data/vtrak1/raw")
|
43
|
+
end
|
44
|
+
parser.parse!(ARGV)
|
45
|
+
return options
|
46
|
+
end
|
47
|
+
|
48
|
+
def normalize!(options)
|
49
|
+
directories = ARGV.to_a
|
50
|
+
directories.each do |directory|
|
51
|
+
unless File.directory?(directory)
|
52
|
+
puts "Error: Cannot find directory #{dir}."
|
53
|
+
next
|
54
|
+
end
|
55
|
+
normalizer = Normalizer.new(directory, options)
|
56
|
+
normalizer.normalize_directory!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
|
61
|
+
$LOG = Logger.new(STDOUT)
|
62
|
+
|
63
|
+
options = parse_options
|
64
|
+
if options[:spec]
|
65
|
+
directories =
|
66
|
+
end
|
67
|
+
normalize!(options)
|
68
|
+
end
|
data/escoffier.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{escoffier}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Erik Kastman"]
|
12
|
+
s.date = %q{2010-04-26}
|
13
|
+
s.description = %q{Administrative prep tasks, from mother sauces to hotel pans.}
|
14
|
+
s.email = %q{ekk@medicine.wisc.edu}
|
15
|
+
s.executables = ["normalize_directory.rb", "mise"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"Manifest.txt",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"bin/mise",
|
26
|
+
"bin/normalize_directory.rb",
|
27
|
+
"escoffier.gemspec",
|
28
|
+
"lib/escoffier.rb",
|
29
|
+
"lib/escoffier/compressible.rb",
|
30
|
+
"lib/escoffier/core_additions.rb",
|
31
|
+
"lib/escoffier/normalizer.rb",
|
32
|
+
"lib/escoffier/smepable.rb",
|
33
|
+
"spec/escoffier_spec.rb",
|
34
|
+
"spec/normalizer_spec.rb",
|
35
|
+
"spec/smepable_spec.rb",
|
36
|
+
"spec/spec.opts",
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"tasks/rspec.rake"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/kastman/escoffier}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.6}
|
44
|
+
s.summary = %q{Mise en Place Prep Tasks}
|
45
|
+
s.test_files = [
|
46
|
+
"spec/escoffier_spec.rb",
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
"spec/normalizer_spec.rb",
|
49
|
+
"spec/smepable_spec.rb"
|
50
|
+
]
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<bzip2-ruby>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<bzip2-ruby>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<bzip2-ruby>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/lib/escoffier.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'escoffier/core_additions'
|
5
|
+
require 'escoffier/normalizer'
|
6
|
+
require 'escoffier/compressible'
|
7
|
+
require 'escoffier/smepable'
|
8
|
+
|
9
|
+
module Escoffier
|
10
|
+
VERSION = '0.0.1'
|
11
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Compressible
|
2
|
+
# Unzips a file on the filesystem using the bzip2 algorithm.
|
3
|
+
# Pass in a path to a file, and optional options.
|
4
|
+
#
|
5
|
+
# options:
|
6
|
+
# :output_path => 'path' Where the file should go if not the same directory as the zipped file.
|
7
|
+
# :remove_original => [true] Specify if the original zipped file should be
|
8
|
+
# removed after unzipping.
|
9
|
+
# :recursive => [true]
|
10
|
+
def unzip(entry, options = Hash.new)
|
11
|
+
|
12
|
+
if options[:recursive]
|
13
|
+
Find.find(entry) do |entry|
|
14
|
+
next unless File.exists?(entry)
|
15
|
+
next if File.directory?(entry)
|
16
|
+
next unless entry =~ /.bz2$/
|
17
|
+
|
18
|
+
unzip_entry(entry, options)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
unzip_entry(entry, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Zips a file on the filesystem using the bzip2 algorithm.
|
27
|
+
# Pass in a path to a file, and optional options.
|
28
|
+
# options:
|
29
|
+
# :output_path => Where the file should go if not the same directory as the unzipped file.
|
30
|
+
# :remove_original => [true] Specify if the original zipped file should be
|
31
|
+
# removed after unzipping.
|
32
|
+
def zip(file, options = Hash.new)
|
33
|
+
if options[:output_path]
|
34
|
+
output_path = options[:output_path]
|
35
|
+
else
|
36
|
+
output_path = File.dirname(File.expand_path(file))
|
37
|
+
end
|
38
|
+
|
39
|
+
options[:remove_original] = true if options[:remove_original].nil?
|
40
|
+
|
41
|
+
decompressed_filename = File.expand_path(file)
|
42
|
+
compressed_filename = File.join(output_path, File.basename(file) + '.bz2')
|
43
|
+
puts "Compressing #{decompressed_filename} to #{compressed_filename}"
|
44
|
+
Bzip2::Writer.open(compressed_filename, 'w') do |compressed_file|
|
45
|
+
File.open(decompressed_filename, 'r') do |decompressed_file|
|
46
|
+
compressed_file << decompressed_file.read
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if File.exist?(compressed_filename)
|
51
|
+
File.delete(decompressed_filename) if options[:remove_original]
|
52
|
+
end
|
53
|
+
|
54
|
+
return compressed_filename
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def unzip_entry(file, options = Hash.new)
|
60
|
+
if options[:output_path]
|
61
|
+
output_path = options[:output_path]
|
62
|
+
else
|
63
|
+
output_path = File.dirname(File.expand_path(file))
|
64
|
+
end
|
65
|
+
|
66
|
+
options[:remove_original] = true if options[:remove_original].nil?
|
67
|
+
|
68
|
+
compressed_filename = File.expand_path(file)
|
69
|
+
decompressed_filename = File.join(output_path, File.basename(file, '.bz2'))
|
70
|
+
$LOG.debug "Decompressing #{compressed_filename} to #{decompressed_filename}"
|
71
|
+
|
72
|
+
begin
|
73
|
+
# raise NoMemoryError
|
74
|
+
|
75
|
+
Bzip2::Reader.open(compressed_filename, 'r') do |compressed_file|
|
76
|
+
begin
|
77
|
+
File.open(decompressed_filename, 'w') do |decompressed_file|
|
78
|
+
decompressed_file << compressed_file.read
|
79
|
+
end
|
80
|
+
rescue Bzip2::EOZError => e
|
81
|
+
raise(Bzip2::EOZError, "Problem decompressing #{compressed_filename}")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if File.exist?(decompressed_filename)
|
86
|
+
File.delete(compressed_filename) if options[:remove_original]
|
87
|
+
end
|
88
|
+
# Currently the Bzip2 library has a problem with very large files.
|
89
|
+
rescue NoMemoryError => e
|
90
|
+
# raise e
|
91
|
+
File.delete(decompressed_filename) if File.exists?(decompressed_filename)
|
92
|
+
cmd = "bunzip2 #{compressed_filename} #{decompressed_filename}"
|
93
|
+
puts cmd
|
94
|
+
system(cmd)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
return decompressed_filename
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'find'
|
2
|
+
require 'etc'
|
3
|
+
require 'bzip2_ext'
|
4
|
+
require 'escoffier/compressible'
|
5
|
+
|
6
|
+
class Normalizer
|
7
|
+
COMPRESSION_REGEXES = /\.bz2$/
|
8
|
+
DICOM_REGEXES = [/\d{3,5}.dcm$/, /I?.\d{4}$/ ]
|
9
|
+
|
10
|
+
include Compressible
|
11
|
+
attr_reader :entry_path
|
12
|
+
|
13
|
+
def initialize(entry_path, options = Hash.new)
|
14
|
+
if options[:user]
|
15
|
+
user = options[:user]
|
16
|
+
else
|
17
|
+
user = 'raw'
|
18
|
+
end
|
19
|
+
|
20
|
+
if options[:group]
|
21
|
+
group = options[:group]
|
22
|
+
else
|
23
|
+
group = 'raw'
|
24
|
+
end
|
25
|
+
|
26
|
+
if options[:dry_run]
|
27
|
+
@dry_run = true
|
28
|
+
else
|
29
|
+
@dry_run = false
|
30
|
+
end
|
31
|
+
|
32
|
+
unless Process.uid == 0 || @dry_run
|
33
|
+
puts "The normalizer must be run as root for correct permissions. Please use 'sudo'."
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
@entry_path = entry_path
|
38
|
+
@uid, @gid, @username, @groupname = Etc.getpwnam(user).uid, Etc.getgrnam(group).gid, user, group
|
39
|
+
end
|
40
|
+
|
41
|
+
def normalize_directory!
|
42
|
+
puts "Scanning #{@entry_path}"
|
43
|
+
|
44
|
+
# Toggle Zippedness
|
45
|
+
Find.find(@entry_path) do |file|
|
46
|
+
next unless File.exists?(file)
|
47
|
+
next if File.directory?(file)
|
48
|
+
|
49
|
+
file = normalize_compression(file)
|
50
|
+
normalize_ownership(file)
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def normalize_compression(file)
|
56
|
+
DICOM_REGEXES.each do |regex|
|
57
|
+
if file =~ regex
|
58
|
+
file = zip(file) unless @dry_run
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# if file =~ COMPRESSION_REGEXES
|
63
|
+
# unzip(file)
|
64
|
+
# end
|
65
|
+
|
66
|
+
return file
|
67
|
+
end
|
68
|
+
|
69
|
+
def normalize_ownership(file, owner = 'raw', maximum_perms = 0755)
|
70
|
+
stat = File.stat(file)
|
71
|
+
|
72
|
+
file_uid, file_gid, mode = stat.uid, stat.gid, stat.mode
|
73
|
+
|
74
|
+
begin
|
75
|
+
if file_uid != @uid
|
76
|
+
begin
|
77
|
+
current_owner = Etc.getpwuid(file_uid).name
|
78
|
+
rescue ArgumentError # No such user; just use UID
|
79
|
+
current_owner = "uid #{file_uid}"
|
80
|
+
end
|
81
|
+
puts " CHOWN #{file}"
|
82
|
+
puts " Current owner is #{current_owner}, should be #{@username}"
|
83
|
+
File.chown(@uid, nil, file) unless @dry_run
|
84
|
+
end
|
85
|
+
|
86
|
+
if file_gid != @gid
|
87
|
+
begin
|
88
|
+
current_group = Etc.getgrgid(file_gid).name
|
89
|
+
rescue ArgumentError # No such group; just use GID
|
90
|
+
current_group = "gid #{file_gid}"
|
91
|
+
end
|
92
|
+
puts " CHOWN #{file}"
|
93
|
+
puts " Current group is #{current_group}, should be #{@groupname}"
|
94
|
+
File.chown(nil, @gid, file) unless @dry_run
|
95
|
+
end
|
96
|
+
|
97
|
+
perms = mode & 0777
|
98
|
+
should_be = perms & maximum_perms
|
99
|
+
if perms != should_be
|
100
|
+
puts " CHMOD #{file}"
|
101
|
+
puts " Current perms are #{perms.to_s(8)}, should be #{should_be.to_s(8)}"
|
102
|
+
File.chmod(perms & maximum_perms, file) unless @dry_run
|
103
|
+
end
|
104
|
+
rescue Exception => e
|
105
|
+
if e.errno == 'eperm'
|
106
|
+
puts "Cannot change ownership - insufficient permissions."
|
107
|
+
else
|
108
|
+
raise e
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'logger'
|
5
|
+
require 'escoffier/compressible'
|
6
|
+
|
7
|
+
# Standard Mise en Place-able
|
8
|
+
module Smepable
|
9
|
+
$LOG ||= Logger.new(STDOUT)
|
10
|
+
include Compressible
|
11
|
+
|
12
|
+
def prep_mise(input_entry, output_directory = Dir.mktmpdir)
|
13
|
+
# destination_dirname = File.dirname(output_directory)
|
14
|
+
FileUtils.mkdir_p(output_directory) unless File.exist?(output_directory)
|
15
|
+
$LOG.info "Copying #{input_entry} to #{output_directory}"
|
16
|
+
verbose = $LOG.level <= Logger::DEBUG
|
17
|
+
source = input_entry
|
18
|
+
FileUtils.cp_r(source, output_directory, :verbose => verbose)
|
19
|
+
$LOG.info "Unzipping #{output_directory}"
|
20
|
+
unzip(output_directory, :recursive => true)
|
21
|
+
|
22
|
+
return output_directory
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'escoffier'
|
6
|
+
|
7
|
+
|
8
|
+
describe "Normalize Compression" do
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
options = Hash.new
|
12
|
+
options[:dry_run] = true
|
13
|
+
@normalizer = Normalizer.new('/tmp/awr011_8414_06182009', options)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should normalize compression" do
|
17
|
+
@normalizer.normalize_directory!
|
18
|
+
end
|
19
|
+
|
20
|
+
# after(:each) do
|
21
|
+
# end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
# require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'logger'
|
7
|
+
require 'escoffier'
|
8
|
+
require 'escoffier/smepable'
|
9
|
+
require 'escoffier/core_additions'
|
10
|
+
|
11
|
+
|
12
|
+
describe "Test Copying and Unzipping with Standard Mise En Place SMEP" do
|
13
|
+
|
14
|
+
before(:all) do
|
15
|
+
@test_directories = {
|
16
|
+
:small_dataset => {
|
17
|
+
:raw => '/Data/vtrak1/raw/carlson.sharp.visit1/shp00005_421_02232010/006',
|
18
|
+
:source => '/tmp/shp00005_006',
|
19
|
+
:destination => '/tmp/shp00005_006_sandbox'
|
20
|
+
},
|
21
|
+
:full_visit => {
|
22
|
+
:raw => '/Data/vtrak1/raw/carlson.sharp.visit1/shp00005_421_02232010/',
|
23
|
+
:source => '/tmp/shp00005',
|
24
|
+
:destination => '/tmp/shp00005_sandbox'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
@test_directories.each do |label, directory|
|
29
|
+
unless File.exists?(directory[:source])
|
30
|
+
puts "One-time preparation of Testing Source Directory"
|
31
|
+
FileUtils.cp_r(directory[:raw], directory[:source])
|
32
|
+
end
|
33
|
+
FileUtils.rm_r(directory[:destination]) if File.exists?(directory[:destination])
|
34
|
+
end
|
35
|
+
|
36
|
+
$LOG = Logger.new(STDOUT)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should unzip and decompress a small image dataset inside a sandbox" do
|
41
|
+
directory = @test_directories[:small_dataset]
|
42
|
+
d = Pathname.new(directory[:source])
|
43
|
+
d.prep_mise(directory[:source], directory[:destination])
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should unzip and decompress a full visit inside a sandbox" do
|
47
|
+
directory = @test_directories[:full_visit]
|
48
|
+
d = Pathname.new(directory[:source])
|
49
|
+
d.prep_mise(directory[:source], directory[:destination])
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# after(:each) do
|
54
|
+
# end
|
55
|
+
|
56
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: escoffier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Erik Kastman
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-26 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bzip2-ruby
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rspec
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
description: Administrative prep tasks, from mother sauces to hotel pans.
|
45
|
+
email: ekk@medicine.wisc.edu
|
46
|
+
executables:
|
47
|
+
- normalize_directory.rb
|
48
|
+
- mise
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Manifest.txt
|
56
|
+
- README.rdoc
|
57
|
+
- Rakefile
|
58
|
+
- VERSION
|
59
|
+
- bin/mise
|
60
|
+
- bin/normalize_directory.rb
|
61
|
+
- escoffier.gemspec
|
62
|
+
- lib/escoffier.rb
|
63
|
+
- lib/escoffier/compressible.rb
|
64
|
+
- lib/escoffier/core_additions.rb
|
65
|
+
- lib/escoffier/normalizer.rb
|
66
|
+
- lib/escoffier/smepable.rb
|
67
|
+
- spec/escoffier_spec.rb
|
68
|
+
- spec/normalizer_spec.rb
|
69
|
+
- spec/smepable_spec.rb
|
70
|
+
- spec/spec.opts
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- tasks/rspec.rake
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/kastman/escoffier
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --charset=UTF-8
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Mise en Place Prep Tasks
|
103
|
+
test_files:
|
104
|
+
- spec/escoffier_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/normalizer_spec.rb
|
107
|
+
- spec/smepable_spec.rb
|