proutils 0.3.0 → 0.3.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/CHANGES +4 -0
- data/bin/mint +16 -14
- data/lib/proutils/mint/copier.rb +117 -107
- data/meta/proutils.roll +1 -1
- metadata +2 -2
data/CHANGES
CHANGED
data/bin/mint
CHANGED
@@ -6,6 +6,8 @@ require 'proutils/mint/copier'
|
|
6
6
|
module Mint
|
7
7
|
|
8
8
|
# Scaffolding Console Command
|
9
|
+
#
|
10
|
+
# IMPORTANT: When using system lookup, all globs must be in quotes!!!
|
9
11
|
|
10
12
|
class Command
|
11
13
|
|
@@ -22,7 +24,7 @@ module Mint
|
|
22
24
|
@cmd = 'copy' # default command
|
23
25
|
|
24
26
|
opts = GetoptLong.new(
|
25
|
-
['--
|
27
|
+
['--system', '-s', GetoptLong::NO_ARGUMENT],
|
26
28
|
['--dryrun', '--noharm', '-n', GetoptLong::NO_ARGUMENT],
|
27
29
|
['--skip', GetoptLong::NO_ARGUMENT],
|
28
30
|
['--replace', GetoptLong::NO_ARGUMENT],
|
@@ -37,13 +39,18 @@ module Mint
|
|
37
39
|
@options[:skip] = true
|
38
40
|
when '--replace'
|
39
41
|
@options[:force] = true
|
42
|
+
when '--system'
|
43
|
+
@options[:system] = true
|
40
44
|
when '--help'
|
41
45
|
@cmd = 'help'
|
42
|
-
when '--source'
|
43
|
-
@options[:special] = true
|
44
46
|
end
|
45
47
|
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
46
51
|
|
52
|
+
def options
|
53
|
+
@options
|
47
54
|
end
|
48
55
|
|
49
56
|
# Start execution.
|
@@ -55,17 +62,12 @@ module Mint
|
|
55
62
|
# Copy scaffolding.
|
56
63
|
|
57
64
|
def copy
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#end
|
65
|
-
|
66
|
-
if src
|
67
|
-
Copier.new(src, dst, @options).copy
|
68
|
-
else
|
65
|
+
begin
|
66
|
+
destination = ARGV.pop
|
67
|
+
resource = ARGV.dup
|
68
|
+
copier = Copier.new(resource, destination, options)
|
69
|
+
copier.copy
|
70
|
+
rescue LoadError
|
69
71
|
puts "Unrecognized source, '#{src}'."
|
70
72
|
exit 0
|
71
73
|
end
|
data/lib/proutils/mint/copier.rb
CHANGED
@@ -17,33 +17,14 @@ require 'proutils/mint/fileutils'
|
|
17
17
|
|
18
18
|
module Mint
|
19
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
20
|
def self.paths
|
32
|
-
|
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
|
-
)
|
21
|
+
(ENV['MINT_PATH'] || []) + [datadir]
|
41
22
|
end
|
42
23
|
|
43
24
|
# TODO Better way to support RubyGems and Rolls?
|
44
25
|
|
45
26
|
def self.datadir
|
46
|
-
dir = File.
|
27
|
+
dir = File.expand_path("#{File.dirname(__FILE__)}/../../../data/mint")
|
47
28
|
if File.directory?(dir)
|
48
29
|
dir
|
49
30
|
else
|
@@ -51,97 +32,126 @@ module Mint
|
|
51
32
|
end
|
52
33
|
end
|
53
34
|
|
54
|
-
#
|
35
|
+
# Mint Copier provides a factility for
|
36
|
+
# performing interactive, managed copies.
|
55
37
|
|
56
38
|
class Copier
|
57
39
|
|
58
|
-
IGNORE = [ '.', '..', '.svn']
|
40
|
+
#IGNORE = [ '.', '..', '.svn']
|
59
41
|
|
60
|
-
|
42
|
+
# Look for source file(s) in system locations?
|
61
43
|
|
62
|
-
|
44
|
+
attr_accessor :system
|
63
45
|
|
64
|
-
|
65
|
-
@sources = [sources].flatten
|
66
|
-
@destination = destination
|
67
|
-
@options = options || {}
|
46
|
+
# Source paths to copy. This can be a glob or an array of globs.
|
68
47
|
|
69
|
-
|
48
|
+
attr_accessor :source
|
70
49
|
|
71
|
-
|
72
|
-
@force = options[:force]
|
73
|
-
@skip = options[:skip]
|
50
|
+
# Directory (or a file, if copying one file) in which to store copied source.
|
74
51
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
52
|
+
attr_accessor :destination
|
53
|
+
|
54
|
+
# Just pretend to do the commit action.
|
55
|
+
|
56
|
+
attr_accessor :dryrun
|
57
|
+
|
58
|
+
# Force provided an extra "dangerous" option of "(W)rite all".
|
59
|
+
|
60
|
+
attr_accessor :force
|
61
|
+
|
62
|
+
# Automatically skip all overwrites.
|
63
|
+
|
64
|
+
attr_accessor :skip
|
65
|
+
|
66
|
+
# Stores actions to be performed upon commit.
|
67
|
+
|
68
|
+
attr_reader :actions
|
69
|
+
|
70
|
+
# New copier.
|
71
|
+
|
72
|
+
def initialize(source, destination, options=nil)
|
73
|
+
@source = [source].flatten
|
74
|
+
@destination = destination
|
80
75
|
|
81
76
|
@actions = []
|
77
|
+
|
78
|
+
options.each do |k,v|
|
79
|
+
send("#{k}=",v)
|
80
|
+
end
|
82
81
|
end
|
83
82
|
|
84
|
-
def
|
85
|
-
def dryrun? ; @dryrun ; end
|
86
|
-
def force? ; @force ; end
|
87
|
-
def skip? ; @skip ; end
|
83
|
+
def system? ; @system ; end
|
88
84
|
|
89
|
-
|
85
|
+
def dryrun? ; @dryrun ; end
|
86
|
+
def force? ; @force ; end
|
87
|
+
def skip? ; @skip ; end
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#
|
99
|
-
sources.collect do |source|
|
100
|
-
type = *source.split(/[\/\\]/).first
|
101
|
-
[Mint.paths[type], source]
|
89
|
+
# Files to copy.
|
90
|
+
|
91
|
+
def copies
|
92
|
+
if system?
|
93
|
+
system_lookup
|
94
|
+
else
|
95
|
+
common_lookup
|
102
96
|
end
|
103
97
|
end
|
104
98
|
|
105
|
-
#
|
106
|
-
|
107
|
-
def
|
108
|
-
|
109
|
-
|
99
|
+
# Look up file in system locations.
|
100
|
+
|
101
|
+
def system_lookup
|
102
|
+
copies = []
|
103
|
+
Mint.paths.each do |path|
|
104
|
+
source.each do |src|
|
105
|
+
jpath = File.join(path, src)
|
106
|
+
files = Dir.glob(jpath)
|
107
|
+
files.each do |file|
|
108
|
+
file = file.sub(path+'/','')
|
109
|
+
copies << [path, file]
|
110
|
+
end
|
111
|
+
end
|
110
112
|
end
|
113
|
+
copies
|
111
114
|
end
|
112
115
|
|
113
|
-
#
|
116
|
+
# Non-system lookup.
|
114
117
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
+
def common_lookup
|
119
|
+
copies = []
|
120
|
+
source.each do |src|
|
121
|
+
files = Dir.glob(File.join(path, src))
|
122
|
+
unless files.empty?
|
123
|
+
copies << [nil, files]
|
124
|
+
end
|
118
125
|
end
|
126
|
+
copies
|
119
127
|
end
|
120
128
|
|
121
129
|
# Copy files.
|
122
130
|
|
123
131
|
def copy
|
124
|
-
puts "KEY: (d)iff (r)eplace (s)kip
|
125
|
-
|
126
|
-
path = File.join(dir, file)
|
132
|
+
puts "KEY: (d)iff (r)eplace (s)kip (a)ll (q)uit"
|
133
|
+
copies.each do |dir, file|
|
134
|
+
path = dir ? File.join(dir, file) : file
|
127
135
|
if File.file?(path)
|
128
136
|
copy_file(dir, file)
|
129
|
-
|
130
|
-
dirs, files = *
|
137
|
+
elsif File.directory?(path)
|
138
|
+
dirs, files = *partition(path)
|
131
139
|
# make empty directories
|
132
140
|
dirs.each do |d|
|
133
|
-
if File.directory?(d)
|
141
|
+
if File.directory?(File.join(destination,d))
|
134
142
|
skip_dir(d)
|
135
143
|
else
|
136
144
|
pth = File.join(path,d)
|
137
145
|
entries = Dir.entries(pth) - IGNORE
|
138
|
-
make_dir(d) if entries.empty?
|
146
|
+
make_dir(path, d) if entries.empty?
|
139
147
|
end
|
140
148
|
end
|
141
149
|
# copy files in directories
|
142
150
|
files.each do |f|
|
143
151
|
copy_file(path, f)
|
144
152
|
end
|
153
|
+
else
|
154
|
+
raise ArgumentError, "unsupported file object -- #{path}"
|
145
155
|
end
|
146
156
|
end
|
147
157
|
commit
|
@@ -149,17 +159,11 @@ module Mint
|
|
149
159
|
|
150
160
|
private
|
151
161
|
|
152
|
-
#
|
153
|
-
|
154
|
-
#def source_paths
|
155
|
-
# Dir.glob(File.join(@source, '**/*'))
|
156
|
-
#end
|
157
|
-
|
158
|
-
# Partition a path's contents between dirs and files.
|
162
|
+
# Partition a directory's content between dirs and files.
|
159
163
|
|
160
|
-
def
|
164
|
+
def partition(directory)
|
161
165
|
dirs, files = [], []
|
162
|
-
chdir(
|
166
|
+
chdir(directory) do
|
163
167
|
paths = Dir.glob('**/*')
|
164
168
|
dirs, files = *paths.partition do |f|
|
165
169
|
File.directory?(f)
|
@@ -170,11 +174,11 @@ module Mint
|
|
170
174
|
|
171
175
|
# Make a directory.
|
172
176
|
|
173
|
-
def make_dir(dir)
|
177
|
+
def make_dir(source, dir)
|
174
178
|
dst = File.join(destination, dir)
|
175
179
|
if File.file?(dst)
|
176
180
|
puts "Directory to replace file..."
|
177
|
-
action = query(
|
181
|
+
action = query(source, dir) || 'skip'
|
178
182
|
else
|
179
183
|
action = 'make'
|
180
184
|
end
|
@@ -187,15 +191,13 @@ module Mint
|
|
187
191
|
def copy_file(source, file)
|
188
192
|
src = File.join(source, file)
|
189
193
|
dst = File.join(destination, file)
|
190
|
-
|
191
194
|
action = 'skip'
|
192
|
-
|
193
195
|
if File.directory?(dst)
|
194
196
|
puts "File to replace directory..."
|
195
|
-
action = query(file)
|
197
|
+
action = query(source, file)
|
196
198
|
elsif File.file?(dst)
|
197
199
|
unless FileTest.identical?(src, dst)
|
198
|
-
action = query(file)
|
200
|
+
action = query(source, file)
|
199
201
|
end
|
200
202
|
else
|
201
203
|
action = 'copy'
|
@@ -219,6 +221,8 @@ module Mint
|
|
219
221
|
end
|
220
222
|
|
221
223
|
# Skip file.
|
224
|
+
#
|
225
|
+
# TODO: Why is this never called?
|
222
226
|
|
223
227
|
def skip_file(src, dst)
|
224
228
|
@actions << ['skip', [src, dst]]
|
@@ -227,7 +231,7 @@ module Mint
|
|
227
231
|
|
228
232
|
# Show diff of files.
|
229
233
|
|
230
|
-
def diff(file)
|
234
|
+
def diff(source, file)
|
231
235
|
src = File.join(source, file)
|
232
236
|
dst = File.join(destination, file)
|
233
237
|
diff = FileTest.diff(src, dst)
|
@@ -236,7 +240,7 @@ module Mint
|
|
236
240
|
|
237
241
|
# Query about file.
|
238
242
|
|
239
|
-
def query(file)
|
243
|
+
def query(source, file)
|
240
244
|
return 's' if @safe
|
241
245
|
return 'o' if @force
|
242
246
|
action = nil
|
@@ -246,7 +250,7 @@ module Mint
|
|
246
250
|
ans = ask(msg).strip[0,1]
|
247
251
|
case ans
|
248
252
|
when 'd', 'D'
|
249
|
-
diff(file)
|
253
|
+
diff(source, file)
|
250
254
|
when 'r', 'R'
|
251
255
|
action = 'replace'
|
252
256
|
when 's', 'S'
|
@@ -261,34 +265,21 @@ module Mint
|
|
261
265
|
return action
|
262
266
|
end
|
263
267
|
|
264
|
-
#
|
265
|
-
|
266
|
-
def ask(msg)
|
267
|
-
print "#{msg} "
|
268
|
-
until inp = $stdin.gets ; sleep 1 ; end
|
269
|
-
inp.chomp
|
270
|
-
end
|
268
|
+
# Action print.
|
271
269
|
|
272
|
-
# Action print
|
273
270
|
def action_print(action, file)
|
274
271
|
file = file.sub(/^[.]\//,'')
|
275
272
|
action = (' ' * (8 - action.size)) + action
|
276
273
|
puts "#{action} #{file}"
|
277
274
|
end
|
278
275
|
|
279
|
-
|
280
|
-
ans = ask("Commit y/N?")
|
281
|
-
case ans.downcase
|
282
|
-
when 'y', 'yes'
|
283
|
-
commit!
|
284
|
-
end
|
285
|
-
end
|
276
|
+
# Perform actions.
|
286
277
|
|
287
278
|
def commit!
|
288
|
-
|
279
|
+
actions.each do |action, path|
|
289
280
|
case action
|
290
281
|
when 'make'
|
291
|
-
rm(path)
|
282
|
+
#rm(path) if File.directory?(path)
|
292
283
|
mkdir_p(path)
|
293
284
|
when 'copy'
|
294
285
|
src, dst = *path
|
@@ -301,12 +292,30 @@ module Mint
|
|
301
292
|
#mkdir_p(File.dirname(dst))
|
302
293
|
cp(src, dst)
|
303
294
|
else # skip
|
304
|
-
#
|
295
|
+
# do nothing
|
305
296
|
end
|
306
297
|
end
|
307
298
|
end
|
308
299
|
|
309
|
-
#
|
300
|
+
# Confirm commit.
|
301
|
+
|
302
|
+
def commit
|
303
|
+
ans = ask("Commit y/N?")
|
304
|
+
case ans.downcase
|
305
|
+
when 'y', 'yes'
|
306
|
+
commit!
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
# Get user input.
|
311
|
+
|
312
|
+
def ask(msg)
|
313
|
+
print "#{msg} "
|
314
|
+
until inp = $stdin.gets ; sleep 1 ; end
|
315
|
+
inp.chomp
|
316
|
+
end
|
317
|
+
|
318
|
+
# Delegation to FileUtils.
|
310
319
|
|
311
320
|
def fu
|
312
321
|
@dryrun ? FileUtils::DryRun : FileUtils
|
@@ -321,4 +330,5 @@ module Mint
|
|
321
330
|
def mkdir_p(*a,&b) ; fu.mkdir_p(*a,&b) ; end
|
322
331
|
|
323
332
|
end
|
333
|
+
|
324
334
|
end
|
data/meta/proutils.roll
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.6
|
|
3
3
|
specification_version: 2
|
4
4
|
name: proutils
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2007-12-
|
6
|
+
version: 0.3.1
|
7
|
+
date: 2007-12-18 00:00:00 -05:00
|
8
8
|
summary: Ruby Recursive Archival Format
|
9
9
|
require_paths:
|
10
10
|
- lib
|