smallcage 0.2.6 → 0.2.7
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile +3 -2
- data/lib/smallcage/application.rb +12 -236
- data/lib/smallcage/commands/auto.rb +46 -23
- data/lib/smallcage/commands/base.rb +5 -2
- data/lib/smallcage/commands/clean.rb +9 -8
- data/lib/smallcage/commands/export.rb +9 -14
- data/lib/smallcage/commands/import.rb +29 -29
- data/lib/smallcage/commands/manifest.rb +8 -10
- data/lib/smallcage/commands/server.rb +2 -2
- data/lib/smallcage/commands/update.rb +30 -17
- data/lib/smallcage/commands/uri.rb +6 -9
- data/lib/smallcage/document_path.rb +10 -12
- data/lib/smallcage/erb_base.rb +7 -3
- data/lib/smallcage/http_server.rb +10 -10
- data/lib/smallcage/loader.rb +57 -57
- data/lib/smallcage/misc.rb +1 -1
- data/lib/smallcage/options_parser.rb +251 -0
- data/lib/smallcage/renderer.rb +3 -4
- data/lib/smallcage/runner.rb +9 -9
- data/lib/smallcage/update_list.rb +50 -40
- data/lib/smallcage/version.rb +1 -1
- data/lib/smallcage.rb +1 -0
- data/spec/lib/smallcage/application_spec.rb +62 -43
- data/spec/lib/smallcage/commands/export_spec.rb +8 -8
- data/spec/lib/smallcage/commands/import_spec.rb +2 -2
- data/spec/lib/smallcage/commands/manifest_spec.rb +1 -1
- data/spec/lib/smallcage/commands/update_spec.rb +13 -13
- data/spec/lib/smallcage/document_path_spec.rb +4 -4
- data/spec/lib/smallcage/loader_spec.rb +3 -3
- data/spec/lib/smallcage/update_list_spec.rb +139 -118
- data/spec/spec_helper.rb +6 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a1fa9291e27aa8accda9f6a2f59110ed2e85e6
|
4
|
+
data.tar.gz: eef2ad497718133501587a57a06b6444a047988f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30db05e645ca960f444d8a9f23fc1e724199e053cc29ccfe1e69cb03117f4e08d1d6f02daff9bbd60cd44a77fc513e9f46b6ca2c1691c9598d899957781b8760
|
7
|
+
data.tar.gz: 1c9dbed249dc5512594639aa1600721c72760186b47b3819feb5fa5b628f943090871fa261c2f9962b7818cbd9f64de95a0877ed53d2f4e75a38308b6acf7172
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
|
|
3
3
|
gem 'syck', :platforms => :ruby_20
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem 'rspec'
|
6
|
+
gem 'rspec', '~> 3.3.0'
|
7
7
|
end
|
8
8
|
|
9
9
|
group :development do
|
@@ -11,9 +11,10 @@ group :development do
|
|
11
11
|
|
12
12
|
platforms :ruby_19, :ruby_20 do
|
13
13
|
gem 'simplecov', :require => false
|
14
|
-
gem '
|
14
|
+
gem 'awesome_print'
|
15
15
|
|
16
16
|
if RUBY_VERSION >= '1.9.3'
|
17
|
+
gem 'rubocop', '~> 0.33.0', :require => false
|
17
18
|
gem 'guard', :require => false
|
18
19
|
gem 'guard-rspec', :require => false
|
19
20
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
+
# Parse command-line arguments and run application.
|
1
2
|
class SmallCage::Application
|
2
|
-
require '
|
3
|
-
VERSION_NOTE = "SmallCage #{SmallCage::VERSION} - a simple website generator"
|
3
|
+
require 'English'
|
4
4
|
|
5
|
-
|
5
|
+
@signal_handlers = nil
|
6
6
|
|
7
7
|
def self.init_signal_handlers
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
@signal_handlers = {
|
9
|
+
'INT' => [],
|
10
|
+
'TERM' => []
|
11
11
|
}
|
12
12
|
|
13
|
-
|
13
|
+
@signal_handlers.keys.each do |signal|
|
14
14
|
Signal.trap(signal) do
|
15
|
-
|
15
|
+
@signal_handlers[signal].each do |proc|
|
16
16
|
proc.call(signal)
|
17
17
|
end
|
18
18
|
end
|
@@ -20,15 +20,15 @@ class SmallCage::Application
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.add_signal_handler(signal, handler)
|
23
|
-
init_signal_handlers if
|
23
|
+
init_signal_handlers if @signal_handlers.nil?
|
24
24
|
signal.to_a.each do |s|
|
25
|
-
|
25
|
+
@signal_handlers[s] << handler
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.execute
|
30
30
|
STDOUT.sync = true
|
31
|
-
|
31
|
+
new.execute
|
32
32
|
end
|
33
33
|
|
34
34
|
def execute(argv = ARGV)
|
@@ -37,230 +37,6 @@ class SmallCage::Application
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def parse_options(argv)
|
40
|
-
|
41
|
-
@options = {}
|
42
|
-
|
43
|
-
@parser = create_main_parser
|
44
|
-
parse_main_options
|
45
|
-
|
46
|
-
@command_parsers = create_command_parsers
|
47
|
-
parse_command
|
48
|
-
parse_command_options
|
49
|
-
|
50
|
-
@options
|
51
|
-
end
|
52
|
-
|
53
|
-
def create_main_parser
|
54
|
-
parser = OptionParser.new
|
55
|
-
parser.banner =<<BANNER
|
56
|
-
Usage: #{File.basename($0)} [options] <subcommand> [subcommand-options]
|
57
|
-
#{VERSION_NOTE}
|
58
|
-
Subcommands are:
|
59
|
-
update [path] Build smc contents.
|
60
|
-
clean [path] Remove files generated from *.smc source.
|
61
|
-
server [path] [port] Start HTTP server.
|
62
|
-
auto [path] [port] [--bell] Start auto update server.
|
63
|
-
import [name|uri] Import project.
|
64
|
-
export [path] [outputpath] Export project.
|
65
|
-
uri [path] Print URIs.
|
66
|
-
manifest [path] Generate Manifest.html file.
|
67
|
-
|
68
|
-
BANNER
|
69
|
-
|
70
|
-
parser.separator "Options are:"
|
71
|
-
parser.on("-h", "--help", "Show this help message.") do
|
72
|
-
puts parser
|
73
|
-
exit(true)
|
74
|
-
end
|
75
|
-
parser.on("-v", "--version", "Show version info.") do
|
76
|
-
puts VERSION_NOTE
|
77
|
-
exit(true)
|
78
|
-
end
|
79
|
-
|
80
|
-
@options[:quiet] = false
|
81
|
-
parser.on("-q", "--quiet", "Do not print message.") do |boolean|
|
82
|
-
@options[:quiet] = boolean
|
83
|
-
end
|
84
|
-
|
85
|
-
return parser
|
86
|
-
end
|
87
|
-
private :create_main_parser
|
88
|
-
|
89
|
-
def parse_main_options
|
90
|
-
@parser.order!(@argv)
|
91
|
-
rescue OptionParser::InvalidOption => e
|
92
|
-
$stderr.puts e.message
|
93
|
-
exit(false)
|
94
|
-
end
|
95
|
-
private :parse_main_options
|
96
|
-
|
97
|
-
def create_command_parsers
|
98
|
-
banners = {
|
99
|
-
:update => <<EOT,
|
100
|
-
smc update [path] [options]
|
101
|
-
path : target directory. (default:'.')
|
102
|
-
EOT
|
103
|
-
|
104
|
-
:clean => <<EOT,
|
105
|
-
smc clean [path] [options]
|
106
|
-
path : target directory (default:'.')
|
107
|
-
EOT
|
108
|
-
|
109
|
-
:server => <<EOT,
|
110
|
-
smc server [path] [port] [options]
|
111
|
-
path : target directory (default:'.')
|
112
|
-
port : HTTP server port number (default:8080)
|
113
|
-
EOT
|
114
|
-
|
115
|
-
:auto => <<EOT,
|
116
|
-
smc auto [path] [port] [options]
|
117
|
-
path : target directory (default:'.')
|
118
|
-
port : HTTP server port number (default:don't launch the server)
|
119
|
-
EOT
|
120
|
-
|
121
|
-
:import => <<EOT,
|
122
|
-
smc import [name|uri] [options]
|
123
|
-
EOT
|
124
|
-
|
125
|
-
:export => <<EOT,
|
126
|
-
smc export [path] [outputpath] [options]
|
127
|
-
EOT
|
128
|
-
|
129
|
-
:help => <<EOT,
|
130
|
-
smc help [command]
|
131
|
-
EOT
|
132
|
-
|
133
|
-
:uri => <<EOT,
|
134
|
-
smc uri [path] [options]
|
135
|
-
EOT
|
136
|
-
|
137
|
-
:manifest => <<EOT,
|
138
|
-
smc manifest [path] [options]
|
139
|
-
EOT
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
parsers = {}
|
144
|
-
banners.each do |command, banner|
|
145
|
-
parsers[command] = create_default_command_parser(banner)
|
146
|
-
end
|
147
|
-
|
148
|
-
parsers[:auto].on("--bell", "Ring bell after publishing files.") do |boolean|
|
149
|
-
@options[:bell] = boolean
|
150
|
-
end
|
151
|
-
|
152
|
-
return parsers
|
153
|
-
end
|
154
|
-
private :create_command_parsers
|
155
|
-
|
156
|
-
def create_default_command_parser(banner)
|
157
|
-
parser = OptionParser.new
|
158
|
-
parser.banner = "Usage: " + banner
|
159
|
-
parser.separator "Options are:"
|
160
|
-
|
161
|
-
# these options can place both before and after the subcommand.
|
162
|
-
parser.on("-h", "--help", "Show this help message.") do
|
163
|
-
puts parser
|
164
|
-
exit(true)
|
165
|
-
end
|
166
|
-
parser.on("-v", "--version", "Show version info.") do
|
167
|
-
puts VERSION_NOTE
|
168
|
-
exit(true)
|
169
|
-
end
|
170
|
-
parser.on("-q", "--quiet", "Do not print message.") do |boolean|
|
171
|
-
@options[:quiet] = boolean
|
172
|
-
end
|
173
|
-
|
174
|
-
return parser
|
175
|
-
end
|
176
|
-
private :create_default_command_parser
|
177
|
-
|
178
|
-
def parse_command
|
179
|
-
@options[:command] = get_command
|
180
|
-
|
181
|
-
if @options[:command].nil?
|
182
|
-
puts @parser
|
183
|
-
exit(false)
|
184
|
-
end
|
185
|
-
parser = @command_parsers[@options[:command]]
|
186
|
-
if parser.nil?
|
187
|
-
$stderr.puts "no such subcommand: #{@options[:command]}"
|
188
|
-
exit(false)
|
189
|
-
end
|
190
|
-
parser.parse!(@argv)
|
191
|
-
rescue OptionParser::InvalidOption => e
|
192
|
-
$stderr.puts e.message
|
193
|
-
exit(false)
|
194
|
-
end
|
195
|
-
private :parse_command
|
196
|
-
|
197
|
-
|
198
|
-
def get_command
|
199
|
-
commands = Hash.new {|h,k| k}
|
200
|
-
commands.merge!({
|
201
|
-
:up => :update,
|
202
|
-
:sv => :server,
|
203
|
-
:au => :auto,
|
204
|
-
})
|
205
|
-
|
206
|
-
command_name = @argv.shift.to_s.strip
|
207
|
-
return nil if command_name.empty?
|
208
|
-
return commands[command_name.to_sym]
|
209
|
-
end
|
210
|
-
private :get_command
|
211
|
-
|
212
|
-
def parse_command_options
|
213
|
-
if @options[:command] == :help
|
214
|
-
subcmd = @argv.shift
|
215
|
-
if subcmd.nil?
|
216
|
-
puts @parser
|
217
|
-
else
|
218
|
-
puts @command_parsers[subcmd.to_sym]
|
219
|
-
end
|
220
|
-
exit(true)
|
221
|
-
elsif @options[:command] == :update
|
222
|
-
@options[:path] = @argv.shift
|
223
|
-
@options[:path] ||= "."
|
224
|
-
elsif @options[:command] == :server
|
225
|
-
@options[:path] = @argv.shift
|
226
|
-
@options[:path] ||= "."
|
227
|
-
@options[:port] = get_port_number(8080)
|
228
|
-
elsif @options[:command] == :auto
|
229
|
-
@options[:path] = @argv.shift
|
230
|
-
@options[:path] ||= "."
|
231
|
-
@options[:port] = get_port_number(nil)
|
232
|
-
@options[:bell] ||= false
|
233
|
-
elsif @options[:command] == :import
|
234
|
-
@options[:from] = @argv.shift
|
235
|
-
@options[:from] ||= "default"
|
236
|
-
@options[:to] = @argv.shift
|
237
|
-
@options[:to] ||= "."
|
238
|
-
elsif @options[:command] == :export
|
239
|
-
@options[:path] = @argv.shift
|
240
|
-
@options[:path] ||= "."
|
241
|
-
@options[:out] = @argv.shift
|
242
|
-
elsif @options[:command] == :uri
|
243
|
-
@options[:path] = @argv.shift
|
244
|
-
@options[:path] ||= "."
|
245
|
-
elsif @options[:command] == :manifest
|
246
|
-
@options[:path] = @argv.shift
|
247
|
-
@options[:path] ||= "."
|
248
|
-
elsif @options[:command] == :clean
|
249
|
-
@options[:path] = @argv.shift
|
250
|
-
@options[:path] ||= "."
|
251
|
-
end
|
252
|
-
end
|
253
|
-
private :parse_command_options
|
254
|
-
|
255
|
-
def get_port_number(default)
|
256
|
-
return default if @argv.empty?
|
257
|
-
|
258
|
-
port = @argv.shift
|
259
|
-
if port.to_i == 0
|
260
|
-
$stderr.puts "illegal port number: #{port}"
|
261
|
-
exit(false)
|
262
|
-
end
|
263
|
-
return port.to_i
|
40
|
+
SmallCage::OptionsParser.new(argv).parse
|
264
41
|
end
|
265
|
-
private :get_port_number
|
266
42
|
end
|
@@ -1,13 +1,31 @@
|
|
1
1
|
module SmallCage::Commands
|
2
|
+
#
|
3
|
+
# 'smc auto' command
|
4
|
+
#
|
2
5
|
class Auto < SmallCage::Commands::Base
|
3
|
-
|
4
6
|
def initialize(opts)
|
5
7
|
super(opts)
|
6
8
|
@target = Pathname.new(opts[:path])
|
7
9
|
@port = opts[:port]
|
8
10
|
@sleep = 1
|
9
|
-
@
|
11
|
+
@timestamps = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_initial_timestamps
|
15
|
+
# load timestamps
|
16
|
+
modified_special_files
|
17
|
+
modified_files
|
18
|
+
|
19
|
+
# overwrite @timestamps using list.yml to recover last update state.
|
20
|
+
list = SmallCage::UpdateList.create(@loader.root, @target)
|
21
|
+
|
22
|
+
list.mtimes.each do |uri, mtime|
|
23
|
+
path = @loader.root + ".#{uri}"
|
24
|
+
mtime = Time.at(mtime)
|
25
|
+
@timestamps[path] = mtime
|
26
|
+
end
|
10
27
|
end
|
28
|
+
private :load_initial_timestamps
|
11
29
|
|
12
30
|
def execute
|
13
31
|
puts_banner
|
@@ -22,7 +40,12 @@ module SmallCage::Commands
|
|
22
40
|
while @update_loop
|
23
41
|
if first_loop
|
24
42
|
first_loop = false
|
25
|
-
|
43
|
+
if @opts[:fast]
|
44
|
+
load_initial_timestamps
|
45
|
+
update_modified_files
|
46
|
+
else
|
47
|
+
update_target
|
48
|
+
end
|
26
49
|
else
|
27
50
|
update_modified_files
|
28
51
|
end
|
@@ -35,17 +58,17 @@ module SmallCage::Commands
|
|
35
58
|
|
36
59
|
result = []
|
37
60
|
Dir.chdir(root) do
|
38
|
-
Dir.glob(
|
61
|
+
Dir.glob('_smc/{templates,filters,helpers}/*') do |f|
|
39
62
|
f = root + f
|
40
63
|
mtime = File.stat(f).mtime
|
41
|
-
if @
|
42
|
-
@
|
64
|
+
if @timestamps[f] != mtime
|
65
|
+
@timestamps[f] = mtime
|
43
66
|
result << f
|
44
67
|
end
|
45
68
|
end
|
46
69
|
end
|
47
70
|
|
48
|
-
|
71
|
+
result
|
49
72
|
end
|
50
73
|
private :modified_special_files
|
51
74
|
|
@@ -53,27 +76,27 @@ module SmallCage::Commands
|
|
53
76
|
result = []
|
54
77
|
@loader.each_smc_file do |f|
|
55
78
|
mtime = File.stat(f).mtime
|
56
|
-
if @
|
57
|
-
@
|
79
|
+
if @timestamps[f] != mtime
|
80
|
+
@timestamps[f] = mtime
|
58
81
|
result << f
|
59
82
|
end
|
60
83
|
end
|
61
|
-
|
84
|
+
result
|
62
85
|
end
|
63
86
|
private :modified_files
|
64
87
|
|
65
88
|
def update_target
|
66
|
-
# load
|
89
|
+
# load timestamps
|
67
90
|
modified_special_files
|
68
91
|
target_files = modified_files
|
69
92
|
|
70
|
-
runner = SmallCage::Runner.new(
|
93
|
+
runner = SmallCage::Runner.new(:path => @target, :quiet => @opts[:quiet])
|
71
94
|
begin
|
72
95
|
runner.update
|
73
96
|
rescue Exception => e
|
74
97
|
STDERR.puts e.to_s
|
75
98
|
STDERR.puts $@[0..4].join("\n")
|
76
|
-
STDERR.puts
|
99
|
+
STDERR.puts ':'
|
77
100
|
end
|
78
101
|
|
79
102
|
update_http_server(target_files)
|
@@ -88,22 +111,22 @@ module SmallCage::Commands
|
|
88
111
|
target_files = modified_files
|
89
112
|
else
|
90
113
|
# update root directory.
|
91
|
-
target_files = [@loader.root +
|
114
|
+
target_files = [@loader.root + './_dir.smc']
|
92
115
|
reload = true
|
93
116
|
end
|
94
117
|
|
95
118
|
return if target_files.empty?
|
96
119
|
target_files.each do |tf|
|
97
|
-
if tf.basename.to_s ==
|
98
|
-
runner = SmallCage::Runner.new(
|
120
|
+
if tf.basename.to_s == '_dir.smc'
|
121
|
+
runner = SmallCage::Runner.new(:path => tf.parent, :quiet => @opts[:quiet])
|
99
122
|
else
|
100
|
-
runner = SmallCage::Runner.new(
|
123
|
+
runner = SmallCage::Runner.new(:path => tf, :quiet => @opts[:quiet])
|
101
124
|
end
|
102
125
|
runner.update
|
103
126
|
end
|
104
127
|
|
105
128
|
if reload
|
106
|
-
@http_server.reload
|
129
|
+
@http_server.reload if @http_server
|
107
130
|
else
|
108
131
|
update_http_server(target_files)
|
109
132
|
end
|
@@ -112,7 +135,7 @@ module SmallCage::Commands
|
|
112
135
|
rescue Exception => e
|
113
136
|
STDERR.puts e.to_s
|
114
137
|
STDERR.puts $@[0..4].join("\n")
|
115
|
-
STDERR.puts
|
138
|
+
STDERR.puts ':'
|
116
139
|
puts_line
|
117
140
|
notify
|
118
141
|
notify
|
@@ -121,7 +144,7 @@ module SmallCage::Commands
|
|
121
144
|
|
122
145
|
def puts_banner
|
123
146
|
return if quiet?
|
124
|
-
puts
|
147
|
+
puts 'SmallCage Auto Update'
|
125
148
|
puts "http://localhost:#{@port}/_smc/auto" unless @port.nil?
|
126
149
|
puts
|
127
150
|
end
|
@@ -129,7 +152,7 @@ module SmallCage::Commands
|
|
129
152
|
|
130
153
|
def puts_line
|
131
154
|
return if quiet?
|
132
|
-
puts
|
155
|
+
puts '-' * 60
|
133
156
|
end
|
134
157
|
private :puts_line
|
135
158
|
|
@@ -141,7 +164,7 @@ module SmallCage::Commands
|
|
141
164
|
|
142
165
|
def update_http_server(target_files)
|
143
166
|
return unless @http_server
|
144
|
-
path = target_files.find {|p| p.basename.to_s !=
|
167
|
+
path = target_files.find { |p| p.basename.to_s != '_dir.smc' }
|
145
168
|
if path.nil?
|
146
169
|
dir = target_files.shift
|
147
170
|
dpath = SmallCage::DocumentPath.new(@loader.root, dir.parent)
|
@@ -158,7 +181,7 @@ module SmallCage::Commands
|
|
158
181
|
@http_server.shutdown unless @http_server.nil?
|
159
182
|
@update_loop = false
|
160
183
|
end
|
161
|
-
SmallCage::Application.add_signal_handler(
|
184
|
+
SmallCage::Application.add_signal_handler(%w{INT TERM}, shutdown_handler)
|
162
185
|
end
|
163
186
|
private :init_sig_handler
|
164
187
|
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module SmallCage::Commands
|
2
|
+
#
|
3
|
+
# smc commands base class
|
4
|
+
#
|
2
5
|
class Base
|
3
6
|
def self.execute(opts)
|
4
|
-
|
7
|
+
new(opts).execute
|
5
8
|
end
|
6
9
|
|
7
10
|
def initialize(opts)
|
@@ -12,7 +15,7 @@ module SmallCage::Commands
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def quiet?
|
15
|
-
|
18
|
+
@opts[:quiet]
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module SmallCage::Commands
|
2
|
+
#
|
3
|
+
# 'smc clean' command
|
4
|
+
#
|
2
5
|
class Clean
|
3
6
|
def self.execute(opts)
|
4
|
-
|
7
|
+
new(opts).execute
|
5
8
|
end
|
6
9
|
|
7
10
|
def initialize(opts)
|
@@ -13,9 +16,7 @@ module SmallCage::Commands
|
|
13
16
|
count = 0
|
14
17
|
|
15
18
|
target = Pathname.new(@opts[:path])
|
16
|
-
unless target.exist?
|
17
|
-
raise "target directory or file does not exist.: " + target.to_s
|
18
|
-
end
|
19
|
+
fail 'target directory or file does not exist.: ' + target.to_s unless target.exist?
|
19
20
|
|
20
21
|
loader = SmallCage::Loader.new(target)
|
21
22
|
root = loader.root
|
@@ -30,16 +31,16 @@ module SmallCage::Commands
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
tmpdir = root +
|
34
|
+
tmpdir = root + '_smc/tmp'
|
34
35
|
if tmpdir.exist?
|
35
36
|
FileUtils.rm_r(tmpdir)
|
36
|
-
puts
|
37
|
+
puts 'D /_smc/tmp' unless @opts[:quiet]
|
37
38
|
count += 1
|
38
39
|
end
|
39
40
|
|
40
41
|
elapsed = Time.now - start
|
41
|
-
puts "-- #{count} files. #{
|
42
|
-
" #{
|
42
|
+
puts "-- #{ count } files. #{ sprintf('%.3f', elapsed) } sec." +
|
43
|
+
" #{ sprintf('%.3f', count == 0 ? 0 : elapsed / count) } sec/file." unless @opts[:quiet]
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -2,40 +2,35 @@ module SmallCage::Commands
|
|
2
2
|
class Export < SmallCage::Commands::Base
|
3
3
|
def execute
|
4
4
|
target = Pathname.new(@opts[:path])
|
5
|
-
unless target.exist?
|
6
|
-
raise target.to_s + " does not exist."
|
7
|
-
end
|
5
|
+
fail target.to_s + ' does not exist.' unless target.exist?
|
8
6
|
|
9
7
|
loader = SmallCage::Loader.new(target)
|
10
8
|
root = loader.root
|
11
9
|
|
12
10
|
if @opts[:out].nil?
|
13
|
-
out = root + (
|
11
|
+
out = root + ('./_smc/tmp/export/' + Time.now.strftime('%Y%m%d%H%M%S'))
|
14
12
|
else
|
15
13
|
out = Pathname.new(@opts[:out])
|
16
14
|
end
|
17
|
-
if out.exist?
|
18
|
-
|
19
|
-
end
|
15
|
+
fail out.to_s + ' already exist.' if out.exist?
|
16
|
+
|
20
17
|
FileUtils.makedirs(out)
|
21
18
|
out = out.realpath
|
22
19
|
|
23
|
-
# TODO create empty directories
|
20
|
+
# TODO: create empty directories
|
24
21
|
loader.each_not_smc_file do |docpath|
|
25
22
|
dir = Pathname.new(docpath.uri).parent
|
26
|
-
outdir = out + (
|
23
|
+
outdir = out + ('.' + dir.to_s)
|
27
24
|
FileUtils.makedirs(outdir)
|
28
25
|
FileUtils.cp(docpath.path, outdir)
|
29
|
-
puts
|
26
|
+
puts 'A ' + docpath.uri unless quiet?
|
30
27
|
end
|
31
28
|
|
32
29
|
unless quiet?
|
33
|
-
puts
|
34
|
-
puts
|
30
|
+
puts ''
|
31
|
+
puts 'All contents exported to:'
|
35
32
|
puts " #{out.to_s}"
|
36
33
|
end
|
37
|
-
|
38
34
|
end
|
39
|
-
|
40
35
|
end
|
41
36
|
end
|