proutils 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,9 @@
1
1
  = ProUtils -- Revision History
2
2
 
3
+ == 0.3.1
4
+
5
+ * Fixed mint.
6
+
3
7
  == 0.3.0
4
8
 
5
9
  * With this release proutils is now a single integrated package.
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
- ['--source', '-s', GetoptLong::NO_ARGUMENT],
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
- #if @source
59
- # src = Mint.lookup(ARGV[0])
60
- # dst = ARGV[1] || '.'
61
- #else
62
- src = ARGV[0]
63
- dst = ARGV[1] || '.'
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
@@ -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
- @paths ||= (
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.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'data', 'mint')
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
- # = Mint Copier
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
- attr_reader :sources, :destination, :options
42
+ # Look for source file(s) in system locations?
61
43
 
62
- attr_reader :actions
44
+ attr_accessor :system
63
45
 
64
- def initialize(sources, destination, options=nil)
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
- @special = options[:special]
48
+ attr_accessor :source
70
49
 
71
- @dryrun = options[:dryrun]
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
- if special?
76
- @sources = special_lookup(*sources)
77
- else
78
- @sources = general_lookup(*sources)
79
- end
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 special? ; @special; end
85
- def dryrun? ; @dryrun ; end
86
- def force? ; @force ; end
87
- def skip? ; @skip ; end
83
+ def system? ; @system ; end
88
84
 
89
- # Lookup in special mint locations.
85
+ def dryrun? ; @dryrun ; end
86
+ def force? ; @force ; end
87
+ def skip? ; @skip ; end
90
88
 
91
- def special_lookup(*sources)
92
- # First lets make sure there are not bad requests.
93
- missing = requested_locations(*sources) - Mint.paths.keys
94
- unless missing.empty?
95
- puts "Missing special sources -- #{missing.join(', ')}"
96
- exit 0
97
- end
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 requested_locations(*sources)
108
- sources.collect do |source|
109
- source.split(/[\/\\]/).first
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 general_lookup(*sources)
116
- sources.collect do |source|
117
- [ '.', source ]
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 skip(a)ll (q)uit"
125
- sources.each do |dir, file|
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
- else
130
- dirs, files = *partition_path(path)
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
- # List of source files.
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 partition_path(path)
164
+ def partition(directory)
161
165
  dirs, files = [], []
162
- chdir(path) do
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(file) || 'skip'
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
- # Get user input
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
- def commit
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
- @actions.each do |action, path|
279
+ actions.each do |action, path|
289
280
  case action
290
281
  when 'make'
291
- rm(path) unless File.directory?(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
- # Delegate to fileutils.
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
@@ -1,3 +1,3 @@
1
- proutils 0.3.0 beta 2007-12-17
1
+ proutils 0.3.1 beta 2007-12-17
2
2
  lib/proutils
3
3
 
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.0
7
- date: 2007-12-17 00:00:00 -05:00
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