notes-structured-text-strip-bodies 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/VERSION +1 -1
- data/bin/notes_structured_text_strip_bodies +19 -11
- data/lib/notes_structured_text_strip_bodies.rb +14 -5
- data/spec/notes_structured_text_strip_bodies_spec.rb +30 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
= notes-structured-text-strip-bodies
|
2
2
|
|
3
|
-
|
3
|
+
A command-line tool for remove body text from Lotus Notes Structured Text Exports
|
4
|
+
|
5
|
+
notes_structured_text_strip_bodies <output_dir> <input_file> [<input_file>*]
|
6
|
+
|
7
|
+
= Install
|
8
|
+
|
9
|
+
gem install notes-structured-text-strip-bodies
|
4
10
|
|
5
11
|
== Contributing to notes-structured-text-strip-bodies
|
6
12
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -4,28 +4,36 @@ require 'notes_structured_text_strip_bodies'
|
|
4
4
|
require 'optparse'
|
5
5
|
require 'logger'
|
6
6
|
|
7
|
-
options={}
|
7
|
+
options={:verbose=>true}
|
8
8
|
|
9
9
|
USAGE = "Usage: #{File.basename(__FILE__)} <output_dir> <input_files> [<input_file>]* "
|
10
10
|
|
11
11
|
OptionParser.new do |opts|
|
12
12
|
opts.banner = "Usage: #{File.basename(__FILE__)} <output_dir> <input_files> [<input_file>]* "
|
13
13
|
|
14
|
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
14
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely (default: true)") do |v|
|
15
15
|
options[:verbose] = v
|
16
16
|
end
|
17
17
|
end.parse!
|
18
18
|
|
19
|
-
raise USAGE if ARGV.length<2
|
20
|
-
|
21
|
-
output_dir = ARGV[0]
|
22
|
-
input_files = ARGV[1..-1]
|
23
|
-
raise "<output_dir>: #{output_dir} must be a directory\n#{USAGE}" if !File.directory?(output_dir)
|
24
|
-
|
25
19
|
NotesStructuredTextStripBodies.logger = Logger.new($stderr)
|
26
20
|
if options[:verbose]
|
27
|
-
NotesStructuredTextStripBodies.logger.level=Logger::DEBUG
|
28
|
-
else
|
29
21
|
NotesStructuredTextStripBodies.logger.level=Logger::INFO
|
22
|
+
else
|
23
|
+
NotesStructuredTextStripBodies.logger.level=Logger::WARN
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
raise "insufficient arguments" if ARGV.length<2
|
28
|
+
|
29
|
+
output_dir = ARGV[0]
|
30
|
+
input_files = ARGV[1..-1]
|
31
|
+
|
32
|
+
NotesStructuredTextStripBodies.strip_files(output_dir, input_files, options)
|
33
|
+
NotesStructuredTextStripBodies.log{|logger| logger.info("complete")}
|
34
|
+
rescue Exception=>e
|
35
|
+
NotesStructuredTextStripBodies.log{|logger| logger.error(e)}
|
36
|
+
NotesStructuredTextStripBodies.log{|logger| logger.info(USAGE)}
|
37
|
+
exit(1)
|
30
38
|
end
|
31
|
-
|
39
|
+
exit(0)
|
@@ -10,10 +10,19 @@ module NotesStructuredTextStripBodies
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def strip_files(output_dir, input_files, options={})
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
raise "<output_dir>: #{output_dir} must be a directory" if !File.directory?(output_dir)
|
14
|
+
|
15
|
+
log{|logger| logger.info("stripping to output directory: '#{output_dir}'")}
|
16
|
+
|
17
|
+
[*input_files].each do |input_file_glob|
|
18
|
+
log{|logger| logger.info("processing glob: '#{input_file_glob}'")}
|
19
|
+
|
20
|
+
glob_matches = Dir[input_file_glob]
|
21
|
+
log{|logger| logger.warn("no files match glob: '#{input_file_glob}'")} if glob_matches.empty?
|
22
|
+
|
23
|
+
glob_matches.each do |input_file|
|
24
|
+
strip_file(output_dir, input_file)
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
@@ -22,7 +31,7 @@ module NotesStructuredTextStripBodies
|
|
22
31
|
raise "<input_file>: #{input_file} does not exist or is not a regular file" if !File.file?(input_file)
|
23
32
|
File.open(input_file, "r") do |input|
|
24
33
|
File.open(output_file, "w") do |output|
|
25
|
-
log{|logger| logger.
|
34
|
+
log{|logger| logger.info("stripping: '#{input_file}' => '#{output_file}'")}
|
26
35
|
strip(output, input)
|
27
36
|
end
|
28
37
|
end
|
@@ -5,17 +5,44 @@ describe NotesStructuredTextStripBodies do
|
|
5
5
|
describe "strip_files" do
|
6
6
|
it "should call strip_file once per input_file with one input file" do
|
7
7
|
output_dir = Object.new
|
8
|
+
stub(File).directory?(output_dir){true}
|
9
|
+
|
10
|
+
input_file_glob = Object.new
|
8
11
|
input_file = Object.new
|
12
|
+
|
13
|
+
stub(Dir).[](input_file_glob){[input_file]}
|
9
14
|
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_file)
|
10
|
-
NotesStructuredTextStripBodies.strip_files(output_dir,
|
15
|
+
NotesStructuredTextStripBodies.strip_files(output_dir, input_file_glob)
|
11
16
|
end
|
12
17
|
|
13
18
|
it "should call strip_file once per input_file with multiple input files" do
|
14
19
|
output_dir = Object.new
|
20
|
+
stub(File).directory?(output_dir){true}
|
21
|
+
|
22
|
+
input_file_globs = [Object.new, Object.new]
|
15
23
|
input_files = [Object.new, Object.new]
|
24
|
+
stub(Dir).[](input_file_globs[0]){[input_files[0]]}
|
25
|
+
stub(Dir).[](input_file_globs[1]){[input_files[1]]}
|
26
|
+
|
27
|
+
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_files[0])
|
28
|
+
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_files[1])
|
29
|
+
NotesStructuredTextStripBodies.strip_files(output_dir, input_file_globs)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should expand globs in the input_files" do
|
33
|
+
output_dir = Object.new
|
34
|
+
stub(File).directory?(output_dir){true}
|
35
|
+
|
36
|
+
input_file_globs = [Object.new, Object.new]
|
37
|
+
input_files = [Object.new, Object.new, Object.new, Object.new]
|
38
|
+
stub(Dir).[](input_file_globs[0]){[input_files[0], input_files[1]]}
|
39
|
+
stub(Dir).[](input_file_globs[1]){[input_files[2], input_files[3]]}
|
40
|
+
|
16
41
|
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_files[0])
|
17
42
|
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_files[1])
|
18
|
-
NotesStructuredTextStripBodies.
|
43
|
+
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_files[2])
|
44
|
+
mock(NotesStructuredTextStripBodies).strip_file(output_dir, input_files[3])
|
45
|
+
NotesStructuredTextStripBodies.strip_files(output_dir, input_file_globs)
|
19
46
|
end
|
20
47
|
end
|
21
48
|
|
@@ -23,6 +50,7 @@ describe NotesStructuredTextStripBodies do
|
|
23
50
|
it "should open a new output file for writing, the input file for reading and call strip" do
|
24
51
|
output_dir = "/foo/bar"
|
25
52
|
input_file = "baz/boo.txt"
|
53
|
+
mock(File).file?("baz/boo.txt"){true}
|
26
54
|
|
27
55
|
logdev = Object.new
|
28
56
|
stub(NotesStructuredTextStripBodies).logdev{logdev}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notes-structured-text-strip-bodies
|
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
|
- mccraigmccraig
|