grizzled-ruby 0.1.0 → 0.1.1
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.
- data/lib/grizzled/dir.rb +5 -7
- data/lib/grizzled/fileutil/includer.rb +2 -3
- data/lib/grizzled/fileutil/ziputil.rb +296 -0
- data/lib/grizzled/fileutil.rb +139 -0
- data/lib/grizzled/forwarder.rb +2 -3
- data/lib/grizzled/stack.rb +2 -8
- data/lib/grizzled/string/template.rb +2 -8
- data/lib/grizzled/unix.rb +4 -6
- metadata +6 -4
data/lib/grizzled/dir.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Miscellaneous additional directory-related modules and classes.
|
2
|
+
#
|
3
|
+
#--
|
1
4
|
# This software is released under a BSD license, adapted from
|
2
5
|
# http://opensource.org/licenses/bsd-license.php
|
3
6
|
#
|
@@ -30,13 +33,8 @@
|
|
30
33
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
31
34
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
32
35
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
|
36
|
+
#++
|
34
37
|
|
35
|
-
# Grizzled Ruby: A library of miscellaneous, general-purpose Ruby modules.
|
36
|
-
#
|
37
|
-
# Author:: Brian M. Clapper (mailto:bmc@clapper.org)
|
38
|
-
# Copyright:: Copyright (c) 2011 Brian M. Clapper
|
39
|
-
# License:: BSD License
|
40
38
|
class Dir
|
41
39
|
|
42
40
|
# Adds a +walk+ method to the standard Ruby +Dir+ class. +walk+ walks a
|
@@ -61,7 +59,7 @@ module Grizzled
|
|
61
59
|
# Useful directory-related methods.
|
62
60
|
class Directory
|
63
61
|
|
64
|
-
# Walk a directory tree, starting at
|
62
|
+
# Walk a directory tree, starting at +dirname+, invoking the supplied
|
65
63
|
# block on each directory. The block is passed a +Dir+ object. The
|
66
64
|
# directory is walked top-down, not depth-first. To terminate the
|
67
65
|
# traversal, the block should return +false+. Anything else (including
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# Provides a file inclusion preprocessor. See the documentation for
|
2
2
|
# the Grizzled::FileUtil::Includer class for complete details.
|
3
3
|
#
|
4
|
-
|
5
|
-
#
|
4
|
+
#--
|
6
5
|
# This software is released under a BSD license, adapted from
|
7
6
|
# http://opensource.org/licenses/bsd-license.php
|
8
7
|
#
|
@@ -35,7 +34,7 @@
|
|
35
34
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
36
35
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
37
36
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
|
-
|
37
|
+
#++
|
39
38
|
|
40
39
|
require 'open-uri'
|
41
40
|
require 'uri'
|
@@ -0,0 +1,296 @@
|
|
1
|
+
# Provides convenient, simple front-end functions for the 'rubyzip' gem.
|
2
|
+
# NOTE: To use this module, you _must_ have the 'rubyzip' gem installed.
|
3
|
+
#
|
4
|
+
#--
|
5
|
+
# This software is released under a BSD license, adapted from
|
6
|
+
# http://opensource.org/licenses/bsd-license.php
|
7
|
+
#
|
8
|
+
# Copyright (c) 2011, Brian M. Clapper
|
9
|
+
# All rights reserved.
|
10
|
+
#
|
11
|
+
# Redistribution and use in source and binary forms, with or without
|
12
|
+
# modification, are permitted provided that the following conditions are
|
13
|
+
# met:
|
14
|
+
#
|
15
|
+
# * Redistributions of source code must retain the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer.
|
17
|
+
#
|
18
|
+
# * Redistributions in binary form must reproduce the above copyright
|
19
|
+
# notice, this list of conditions and the following disclaimer in the
|
20
|
+
# documentation and/or other materials provided with the distribution.
|
21
|
+
#
|
22
|
+
# * Neither the names "clapper.org", "Grizzled Ruby Library", nor the
|
23
|
+
# names of its contributors may be used to endorse or promote products
|
24
|
+
# derived from this software without specific prior written permission.
|
25
|
+
#
|
26
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
27
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
28
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
29
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
30
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
31
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
32
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
33
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
34
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
35
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
36
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
37
|
+
#++
|
38
|
+
|
39
|
+
require 'open-uri'
|
40
|
+
require 'uri'
|
41
|
+
require 'pathname'
|
42
|
+
require 'rubygems'
|
43
|
+
require 'zip/zip'
|
44
|
+
require 'fileutils'
|
45
|
+
|
46
|
+
module Grizzled
|
47
|
+
|
48
|
+
module FileUtil
|
49
|
+
|
50
|
+
# Namespace module, containing contains some simplified, front-end
|
51
|
+
# "zip" and "unzip" utility wrappers for the +rubyzip+ gem. This
|
52
|
+
# module requires the +rubyzip+ gem to be present.
|
53
|
+
module ZipUtil
|
54
|
+
|
55
|
+
# +ZipMixin+ provides convenient front-end methods for zipping files;
|
56
|
+
# it uses the 'rubyzip' gem under the covers, so you must have
|
57
|
+
# 'rubyzip' installed to use this class. Mixing this module into your
|
58
|
+
# class mixes in methods that will allow you to zip up files. Related
|
59
|
+
# modules and classes:
|
60
|
+
#
|
61
|
+
# [Grizzled::FileUtil::Zipper] A class that includes this module
|
62
|
+
# and can be instantiated by itself.
|
63
|
+
# [Grizzled::FileUtil::UnzipMixin] A module mixin for unzipping zip files.
|
64
|
+
# [Grizzled::FileUtil::Unzipper] A class that includes `UnzipMixin'
|
65
|
+
# and can be instantiated by itself.
|
66
|
+
module ZipMixin
|
67
|
+
|
68
|
+
# Create a zip file from the contents of a directory.
|
69
|
+
#
|
70
|
+
# Parameters:
|
71
|
+
#
|
72
|
+
# [+zip_file+] The zip file to open. The file is created if it doesn't
|
73
|
+
# already exists.
|
74
|
+
# [+directory+] The directory whose contents are to be included in
|
75
|
+
# the file.
|
76
|
+
# [+options+] Options hash, as described below.
|
77
|
+
# [+&select+] If a block (+select+) is given, then +zip+ passes each
|
78
|
+
# file or directory to the block and only adds the entry
|
79
|
+
# to the zip file if the block returns +true+. If no
|
80
|
+
# block is given, then all files and directories are
|
81
|
+
# added (subject also to the +:recursive+ option, below).
|
82
|
+
#
|
83
|
+
# Options:
|
84
|
+
#
|
85
|
+
# [+:recursive+] If +false+, only zip the files in the directory; if
|
86
|
+
# +true+ (the default), recursively zip the entire
|
87
|
+
# directory.
|
88
|
+
# [+:dir_at_top+] If +false+, don't include zip the directory itself
|
89
|
+
# (i.e., the top-level files will be at the top level
|
90
|
+
# of the zip file). If +true+ (the default), the
|
91
|
+
# the directory itself (the basename) will be the
|
92
|
+
# top-level element of the zip file.
|
93
|
+
# [+:recreate] If +true+, remove the zip file if it exists already,
|
94
|
+
# so it's recreated from scratch. If +false+ (the
|
95
|
+
# default), don't recreate the zip file if it doesn't
|
96
|
+
# exist; instead, update the existing file.
|
97
|
+
#
|
98
|
+
# Returns:
|
99
|
+
#
|
100
|
+
# The +zip_file+ argument, for convenience.
|
101
|
+
#
|
102
|
+
# Example:
|
103
|
+
#
|
104
|
+
# require 'grizzled/fileutil/ziputil'
|
105
|
+
# import 'tmpdir'
|
106
|
+
#
|
107
|
+
# include Grizzled::FileUtil::ZipUtil::ZipMixin
|
108
|
+
#
|
109
|
+
# Dir.mktmpdir do |d|
|
110
|
+
# zip zipfile_path, d
|
111
|
+
# end
|
112
|
+
def zip(zip_file, directory, options = {}, &select)
|
113
|
+
recurse = options.fetch(:recursive, true)
|
114
|
+
dir_at_top = options.fetch(:dir_at_top, true)
|
115
|
+
recreate = options.fetch(:recreate, true)
|
116
|
+
|
117
|
+
if dir_at_top
|
118
|
+
abs_dir = File.expand_path(directory)
|
119
|
+
entry_dir = File.basename(abs_dir)
|
120
|
+
chdir_to = File.dirname(abs_dir)
|
121
|
+
glob = File.join(entry_dir, '**', '*').to_s
|
122
|
+
else
|
123
|
+
chdir_to = directory
|
124
|
+
entry_dir = '.'
|
125
|
+
glob = File.join('**', '*').to_s
|
126
|
+
end
|
127
|
+
|
128
|
+
# Remove the existing zip file, if asked to do so.
|
129
|
+
FileUtils::rm_f zip_file if recreate
|
130
|
+
|
131
|
+
# Open the zip file. Then, CD to the appropriate directory
|
132
|
+
# and pack it up.
|
133
|
+
zip = Zip::ZipFile.open(zip_file, Zip::ZipFile::CREATE)
|
134
|
+
FileUtils::cd chdir_to do |d|
|
135
|
+
Dir[glob].each do |path|
|
136
|
+
|
137
|
+
# If the caller supplied a block, only add the file if the block
|
138
|
+
# says we can.
|
139
|
+
add = block_given? ? select.call(path) : true
|
140
|
+
if add
|
141
|
+
if File.directory? path
|
142
|
+
zip.mkdir path if recurse
|
143
|
+
else
|
144
|
+
zip.add(path, path) if (File.dirname(path) == '.') or recurse
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
zip.close
|
149
|
+
end
|
150
|
+
zip_file
|
151
|
+
end
|
152
|
+
end # module ZipMixin
|
153
|
+
|
154
|
+
# +UnzipMixin+ provides convenient front-end methods for unzipping
|
155
|
+
# files; it uses the 'rubyzip' gem under the covers, so you must have
|
156
|
+
# 'rubyzip' installed to use this class. Mixing this module into your
|
157
|
+
# class mixes in methods that will allow you to unzip zip files.
|
158
|
+
# Related modules and classes:
|
159
|
+
#
|
160
|
+
# [Grizzled::FileUtil::Zipper] A class that includes this module
|
161
|
+
# and can be instantiated by itself.
|
162
|
+
# [Grizzled::FileUtil::ZipMixin] A module mixin for zipping zip files.
|
163
|
+
# [Grizzled::FileUtil::Unzipper] A class that includes `UnzipMixin'
|
164
|
+
# and can be instantiated by itself.
|
165
|
+
module UnzipMixin
|
166
|
+
# Unzips a zip file into a directory.
|
167
|
+
#
|
168
|
+
# Parameters:
|
169
|
+
#
|
170
|
+
# [+zip_file+] The zip file to unzip.
|
171
|
+
# [+directory+] The directory into which to unzip the file. The
|
172
|
+
# directory is created if it doesn't already exist.
|
173
|
+
# [+options+] Options hash, as described below.
|
174
|
+
# [+&select+] If a block (+select+) is given, then +unzip+ passes each
|
175
|
+
# zip file entry name to the block and only unzips the
|
176
|
+
# entry if the block returns +true+. If no block is
|
177
|
+
# given, then everything is unzipped (subject also to
|
178
|
+
# the +:recursive+ option, below).
|
179
|
+
#
|
180
|
+
# Options:
|
181
|
+
#
|
182
|
+
# [+:recursive+] If +false+, only extract the top-level files from
|
183
|
+
# the zip file. If +true+ (the default),
|
184
|
+
# recursively extract everything.
|
185
|
+
# [+:overwrite+] If +false+ (the default), do not overwrite existing
|
186
|
+
# files in the directory. If +true+, overwrite
|
187
|
+
# any existing files in the directory with extracted
|
188
|
+
# zip files whose names match.
|
189
|
+
#
|
190
|
+
# Example:
|
191
|
+
#
|
192
|
+
# import 'grizzled/fileutil/ziputil'
|
193
|
+
# import 'tmpdir'
|
194
|
+
#
|
195
|
+
# include Grizzled::FileUtil::ZipUtil
|
196
|
+
#
|
197
|
+
# Dir.mktmpdir do |d|
|
198
|
+
# unzip zipfile_path, d
|
199
|
+
# # muck with unpacked contents
|
200
|
+
# end
|
201
|
+
|
202
|
+
def unzip(zip_file, directory, options = {}, &select)
|
203
|
+
overwrite = options.fetch(:overwrite, false)
|
204
|
+
recurse = options.fetch(:recursive, true)
|
205
|
+
|
206
|
+
zip = Zip::ZipFile.open(zip_file)
|
207
|
+
Zip::ZipFile.foreach(zip_file) do |entry|
|
208
|
+
file_path = File.join(directory, entry.to_s)
|
209
|
+
parent_dir = File.dirname file_path
|
210
|
+
if recurse or (parent_dir == '.') or (parent_dir == '')
|
211
|
+
# If the caller supplied a block, only extract the file if
|
212
|
+
# the block says we can.
|
213
|
+
extract = block_given? ? select.call(path) : true
|
214
|
+
if extract
|
215
|
+
if parent_dir != ''
|
216
|
+
if not File.exists? parent_dir
|
217
|
+
FileUtils::mkdir_p parent_dir
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
zip.extract(entry, file_path)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Call a given block with the list of entries in a zip file, without
|
227
|
+
# extracting them.
|
228
|
+
#
|
229
|
+
# Parameters:
|
230
|
+
#
|
231
|
+
# [+zip_file+] The zip file to unzip.
|
232
|
+
# [+block+] Block to execute on each entry. If omitted, an
|
233
|
+
# Enumerator is returned. The block receives a string
|
234
|
+
# representing the path of the item in the file.
|
235
|
+
def zip_file_entries(zip_file, &block)
|
236
|
+
if not block_given?
|
237
|
+
a = []
|
238
|
+
end
|
239
|
+
|
240
|
+
Zip::ZipFile.foreach(zip_file) do |entry|
|
241
|
+
if block_given?
|
242
|
+
block.call(entry.to_s)
|
243
|
+
else
|
244
|
+
a << entry.to_s
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
if not block_given?
|
249
|
+
return a.each
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end # module UnzipMixin
|
253
|
+
|
254
|
+
# +Zipper+ is a class version of +ZipMixin+ and is useful when you
|
255
|
+
# don't want to mix the methods directly into your class or module.
|
256
|
+
# It provides the methods of +ZipMixin+ as class methods.
|
257
|
+
#
|
258
|
+
# Example:
|
259
|
+
#
|
260
|
+
# require 'grizzled/fileutil/ziputil'
|
261
|
+
# import 'tmpdir'
|
262
|
+
#
|
263
|
+
# include Grizzled::FileUtil::ZipUtil
|
264
|
+
#
|
265
|
+
# Dir.mktmpdir do |d|
|
266
|
+
# Zipper.zip zipfile_path, d
|
267
|
+
# end
|
268
|
+
class Zipper
|
269
|
+
class << self
|
270
|
+
include Grizzled::FileUtil::ZipUtil::ZipMixin
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
# +Unzipper+ is a class version of +UnzipMixin+ and is useful when
|
275
|
+
# you don't want to mix the methods directly into your class or
|
276
|
+
# module. It provides the methods of +UnzipMixin+ as class methods.
|
277
|
+
#
|
278
|
+
# import 'grizzled/fileutil/ziputil'
|
279
|
+
# import 'tmpdir'
|
280
|
+
#
|
281
|
+
# include Grizzled::FileUtil::ZipUtil
|
282
|
+
#
|
283
|
+
# Dir.mktmpdir do |d|
|
284
|
+
# Unzipper.unzip zipfile_path, d
|
285
|
+
# # muck with unpacked contents
|
286
|
+
# end
|
287
|
+
class Unzipper
|
288
|
+
class << self
|
289
|
+
include Grizzled::FileUtil::ZipUtil::UnzipMixin
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
end # module ZipUtil
|
294
|
+
end # module File
|
295
|
+
end # module Grizzled
|
296
|
+
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# Miscellaneous additional Ruby file utility modules and classes.
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# This software is released under a BSD license, adapted from
|
5
|
+
# http://opensource.org/licenses/bsd-license.php
|
6
|
+
#
|
7
|
+
# Copyright (c) 2011, Brian M. Clapper
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are
|
12
|
+
# met:
|
13
|
+
#
|
14
|
+
# * Redistributions of source code must retain the above copyright notice,
|
15
|
+
# this list of conditions and the following disclaimer.
|
16
|
+
#
|
17
|
+
# * Redistributions in binary form must reproduce the above copyright
|
18
|
+
# notice, this list of conditions and the following disclaimer in the
|
19
|
+
# documentation and/or other materials provided with the distribution.
|
20
|
+
#
|
21
|
+
# * Neither the names "clapper.org", "Grizzled Ruby Library", nor the
|
22
|
+
# names of its contributors may be used to endorse or promote products
|
23
|
+
# derived from this software without specific prior written permission.
|
24
|
+
#
|
25
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
26
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
27
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
28
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
29
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
30
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
31
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
32
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
33
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
34
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
35
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
|
+
#++
|
37
|
+
|
38
|
+
module Grizzled
|
39
|
+
|
40
|
+
# This module and its submodules contain various file-related utility
|
41
|
+
# methods.
|
42
|
+
module FileUtil
|
43
|
+
|
44
|
+
# Exception thrown for a bad directory tree value.
|
45
|
+
class BadDirectoryTreeValue < StandardError
|
46
|
+
def initialize(key, value)
|
47
|
+
super("Directory tree key '#{key}' has unsupported value '#{value}' " +
|
48
|
+
"of type #{value.class}. Values must be hashes or strings.")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Exception thrown for bad directory tree key.
|
53
|
+
class BadDirectoryTreeKey < StandardError; end
|
54
|
+
|
55
|
+
# Create a file/directory hierarchy. The hash table specifies the
|
56
|
+
# entries, using the following rules.
|
57
|
+
#
|
58
|
+
# - A hash entry whose value is another hash table is taken to
|
59
|
+
# be a directory and will be recursively created.
|
60
|
+
# - A hash entry with a String value is a file, whose contents are the
|
61
|
+
# string.
|
62
|
+
# - A hash entry with an Enumerable value is a file, whose contents are
|
63
|
+
# the enumerable values, rendered as strings.
|
64
|
+
# - Anything else is an error.
|
65
|
+
#
|
66
|
+
# For instance, this hash:
|
67
|
+
#
|
68
|
+
# tree = {"foo" =>
|
69
|
+
# {"bar" => {"a" => "File a's contents",
|
70
|
+
# "b" => "File b's contents"},
|
71
|
+
# "baz" => {"c" => "Blah blah blah"},
|
72
|
+
# "xyzzy" => "Yadda yadda yadda"}}
|
73
|
+
#
|
74
|
+
# results in this directory tree:
|
75
|
+
#
|
76
|
+
# foo/
|
77
|
+
# bar/
|
78
|
+
# a # File a's contents
|
79
|
+
# b # File a's contents
|
80
|
+
#
|
81
|
+
# baz/
|
82
|
+
# c # Blah blah blah
|
83
|
+
#
|
84
|
+
# xyzzy # Yadda yadda yadda
|
85
|
+
#
|
86
|
+
# The keys should be simple file names, with no file separators (i.e.,
|
87
|
+
# no parent directories).
|
88
|
+
#
|
89
|
+
# Parameters:
|
90
|
+
#
|
91
|
+
# [+directory+] The starting directory, which is created if it does not
|
92
|
+
# exist.
|
93
|
+
# [+tree+] The entry tree, as described above
|
94
|
+
#
|
95
|
+
# Returns:
|
96
|
+
#
|
97
|
+
# A +Dir+ object for +directory+, for convenience.
|
98
|
+
def make_directory_tree(directory, tree)
|
99
|
+
|
100
|
+
require 'fileutils'
|
101
|
+
|
102
|
+
if File.exists? directory
|
103
|
+
if not File.directory? directory
|
104
|
+
raise BadDirectoryTreeKey.new("Directory '#{directory}' already " +
|
105
|
+
"exists and isn't a directory.")
|
106
|
+
end
|
107
|
+
else
|
108
|
+
Dir.mkdir directory
|
109
|
+
end
|
110
|
+
|
111
|
+
FileUtils.cd directory do
|
112
|
+
tree.each do |entry, contents|
|
113
|
+
if entry.include? File::SEPARATOR
|
114
|
+
raise BadDirectoryTreeKey.new("File tree key '#{key}' contains " +
|
115
|
+
"illegal file separator character.");
|
116
|
+
end
|
117
|
+
|
118
|
+
# Must test Hash first, because Hash is Enumerable.
|
119
|
+
|
120
|
+
if contents.kind_of? Hash
|
121
|
+
# This is a directory
|
122
|
+
make_directory_tree(entry, contents)
|
123
|
+
|
124
|
+
elsif contents.kind_of? Enumerable
|
125
|
+
f = File.open(File.join(entry), 'w')
|
126
|
+
contents.each {|thing| f.write(thing.to_s)}
|
127
|
+
f.close
|
128
|
+
|
129
|
+
else
|
130
|
+
raise BadDirectoryTreeValue.new(entry, contents)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
return Dir.new(directory)
|
136
|
+
end
|
137
|
+
|
138
|
+
end # Module FileUtil
|
139
|
+
end # module Grizzled
|
data/lib/grizzled/forwarder.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Provides a module which, when mixed in, can be used to forward all
|
2
2
|
# missing methods to another object.
|
3
3
|
#
|
4
|
-
|
5
|
-
#
|
4
|
+
#--
|
6
5
|
# This software is released under a BSD license, adapted from
|
7
6
|
# http://opensource.org/licenses/bsd-license.php
|
8
7
|
#
|
@@ -35,7 +34,7 @@
|
|
35
34
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
36
35
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
37
36
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
|
-
|
37
|
+
#++
|
39
38
|
|
40
39
|
module Grizzled
|
41
40
|
|
data/lib/grizzled/stack.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Provides a simple stack implementation. See the Grizzled::Stack class
|
2
2
|
# for complete details.
|
3
3
|
#
|
4
|
-
|
5
|
-
#
|
4
|
+
#--
|
6
5
|
# This software is released under a BSD license, adapted from
|
7
6
|
# http://opensource.org/licenses/bsd-license.php
|
8
7
|
#
|
@@ -35,13 +34,8 @@
|
|
35
34
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
36
35
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
37
36
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
|
-
|
37
|
+
#++
|
39
38
|
|
40
|
-
# Grizzled Ruby: A library of miscellaneous, general-purpose Ruby modules.
|
41
|
-
#
|
42
|
-
# Author:: Brian M. Clapper (mailto:bmc@clapper.org)
|
43
|
-
# Copyright:: Copyright (c) 2011 Brian M. Clapper
|
44
|
-
# License:: BSD License
|
45
39
|
module Grizzled
|
46
40
|
|
47
41
|
# Thrown for un-safe stacks if the stack
|
@@ -3,8 +3,7 @@
|
|
3
3
|
# module, the Grizzled::String::UnixShellStringTemplate class and the
|
4
4
|
# Grizzled::String::WindowsCmdStringTemplate class for complete details.
|
5
5
|
#
|
6
|
-
|
7
|
-
#
|
6
|
+
#--
|
8
7
|
# This software is released under a BSD license, adapted from
|
9
8
|
# http://opensource.org/licenses/bsd-license.php
|
10
9
|
#
|
@@ -37,13 +36,8 @@
|
|
37
36
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
38
37
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
39
38
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
40
|
-
|
39
|
+
#++
|
41
40
|
|
42
|
-
# Grizzled Ruby: A library of miscellaneous, general-purpose Ruby modules.
|
43
|
-
#
|
44
|
-
# Author:: Brian M. Clapper (mailto:bmc@clapper.org)
|
45
|
-
# Copyright:: Copyright (c) 2011 Brian M. Clapper
|
46
|
-
# License:: BSD License
|
47
41
|
module Grizzled
|
48
42
|
|
49
43
|
module String
|
data/lib/grizzled/unix.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Miscellaneous Unix-related modules and classes
|
2
|
+
#
|
3
|
+
#--
|
1
4
|
# This software is released under a BSD license, adapted from
|
2
5
|
# http://opensource.org/licenses/bsd-license.php
|
3
6
|
#
|
@@ -30,13 +33,8 @@
|
|
30
33
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
31
34
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
32
35
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
|
36
|
+
#++
|
34
37
|
|
35
|
-
# Grizzled Ruby: A library of miscellaneous, general-purpose Ruby modules.
|
36
|
-
#
|
37
|
-
# Author:: Brian M. Clapper (mailto:bmc@clapper.org)
|
38
|
-
# Copyright:: Copyright (c) 2011 Brian M. Clapper
|
39
|
-
# License:: BSD License
|
40
38
|
module Grizzled
|
41
39
|
|
42
40
|
# Unix-related OS things.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grizzled-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian M. Clapper
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-18 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -30,8 +30,10 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
|
32
32
|
files:
|
33
|
+
- lib/grizzled/fileutil.rb
|
33
34
|
- lib/grizzled/stack.rb
|
34
35
|
- lib/grizzled/fileutil/includer.rb
|
36
|
+
- lib/grizzled/fileutil/ziputil.rb
|
35
37
|
- lib/grizzled/dir.rb
|
36
38
|
- lib/grizzled/forwarder.rb
|
37
39
|
- lib/grizzled/string/template.rb
|