pidgin2adium 4.0.0.beta1 → 4.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a19269fc564ee7b96212824080a049dcc6fe3b8
4
- data.tar.gz: 5314c9de5efe136193a156a71cd09ce65cccd72b
3
+ metadata.gz: 11238761943e30b94a55fc7cef7580f57975eef4
4
+ data.tar.gz: 67eedc3c5478f8f8889521c78e2d098218d30de0
5
5
  SHA512:
6
- metadata.gz: 60269903641f9776950be83fa2fa99a0cf72c09d5826f30eaf0bc5c94e79678d5e8485d1a1bb450b53e93a1c18d8ff014be0e2863c164b2183f1a96e0f5d6cdd
7
- data.tar.gz: 3c52742c8416ca06cc4d2695c0e78b3c648e0bc43441bebe82b072e91dfb304e7c520d5fe5cce37c2821ba5bbc99da1300c83c4a4636810a18bc9da6b55437dd
6
+ metadata.gz: 3088e7518c59327ea9745d65b843a95e72fe84df3d4a295669aff4cd0f858fb77151184b93ec0b9ec8a6bc15165d37ce868d976582df5ac23adb2b316bdbf9fc
7
+ data.tar.gz: bde9956789c48e3b5503f335fedf090df15af49c7df0d9f7d3d9766012692ccc0079534d1b0a4dc01fdc58be72b92d3f543aa98ecd8a1c3673c275e131f7dc25
data/NEWS.md CHANGED
@@ -1,8 +1,14 @@
1
- ### HEAD (unreleased)
1
+ ### 4.0.0.beta2
2
+
3
+ * Extract `Pidgin2Adium::Cli`
4
+ * Fix bugs
5
+ * Print error and progress messages
6
+
7
+ ### 4.0.0.beta1
2
8
 
3
9
  * Massive refactoring
10
+ * Use Pipio gem to parse logs
4
11
  * Chat times respect time zones instead of assuming inputs are UTC
5
- * Remove C extension
6
12
  * Test against Travis
7
13
 
8
14
  ### 3.3.0 / 2011-10-16
@@ -1,38 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "pidgin2adium"
4
- require "optparse"
5
4
 
6
- options = {}
7
-
8
- parser = OptionParser.new do |parser|
9
- parser.banner = "Usage: #{File.basename($0)} -i PIDGIN_LOG_DIR"
10
-
11
- parser.on('-i', '--in IN_DIR', 'Directory where pidgin logs are stored') do |in_directory|
12
- options[:in_directory] = in_directory
13
- end
14
-
15
- parser.on('-a', '--aliases "gabebw,Gabe B-W"', "Your aliases from Pidgin") do |aliases|
16
- options[:aliases] = aliases.split(",")
17
- end
18
-
19
- parser.on("-v", "--version", "Show version information") do
20
- puts "Pidgin2Adium, version #{Pidgin2Adium::VERSION}"
21
- exit
22
- end
23
-
24
- parser.on_tail("-h", "--help", "Show this message") do
25
- puts parser
26
- exit
27
- end
28
- end
29
-
30
- parser.parse!
31
-
32
- if options[:in_directory] && options[:aliases]
33
- runner = Pidgin2Adium::Runner.new(options[:in_directory], option[:aliases])
34
- runner.run
35
- else
36
- STDERR.puts "Please provide -i/--in argument and -a/--aliases. Run with --help for more information"
37
- exit 1
38
- end
5
+ Pidgin2Adium::Cli.new(ARGV).parse_and_run
@@ -1,5 +1,11 @@
1
+ require 'fileutils'
2
+ require 'optparse'
3
+ require 'pathname'
4
+
1
5
  require 'pipio'
6
+
2
7
  require 'pidgin2adium/version'
8
+ require 'pidgin2adium/cli'
3
9
  require 'pidgin2adium/file_finder'
4
10
  require 'pidgin2adium/runner'
5
11
  require 'pidgin2adium/adium_chat_file_creator'
@@ -1,5 +1,3 @@
1
- require "pathname"
2
-
3
1
  module Pidgin2Adium
4
2
  class AdiumChatFileCreator
5
3
  def initialize(file_path, aliases, output_directory = Runner::ADIUM_LOG_DIRECTORY)
@@ -9,12 +7,17 @@ module Pidgin2Adium
9
7
  end
10
8
 
11
9
  def create
12
- create_containing_directory
13
- File.open(path, 'w') do |file|
14
- file.puts xml_prolog
15
- file.puts opening_chat_tag
16
- file.puts chat.to_s
17
- file.puts closing_chat_tag
10
+ if chat
11
+ create_containing_directory
12
+ File.open(path, 'w') do |file|
13
+ file.puts xml_prolog
14
+ file.puts opening_chat_tag
15
+ file.puts chat.to_s
16
+ file.puts closing_chat_tag
17
+ end
18
+ true
19
+ else
20
+ false
18
21
  end
19
22
  end
20
23
 
@@ -0,0 +1,48 @@
1
+ module Pidgin2Adium
2
+ class Cli
3
+ def initialize(args, stdout: STDOUT, stderr: STDERR)
4
+ @arguments = args
5
+ @stdout = stdout
6
+ @stderr = stderr
7
+ @options = {}
8
+ end
9
+
10
+ def parse_and_run
11
+ parser.parse!(@arguments)
12
+
13
+ if @options[:in_directory] && @options[:aliases]
14
+ runner = Runner.new(@options[:in_directory], @options[:aliases])
15
+ runner.run
16
+ else
17
+ @stderr.puts "Please provide -i/--in argument and -a/--aliases. Run with --help for more information"
18
+ exit 1
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def parser
25
+ @parser ||= OptionParser.new do |parser|
26
+ parser.banner = "Usage: #{File.basename($0)} -i PIDGIN_LOG_DIR"
27
+
28
+ parser.on('-i', '--in IN_DIR', 'Directory where pidgin logs are stored') do |in_directory|
29
+ @options[:in_directory] = in_directory
30
+ end
31
+
32
+ parser.on('-a', '--aliases "gabebw,Gabe B-W"', "Your aliases from Pidgin") do |aliases|
33
+ @options[:aliases] = aliases.split(",")
34
+ end
35
+
36
+ parser.on("-v", "--version", "Show version information") do
37
+ @stdout.puts "Pidgin2Adium, version #{Pidgin2Adium::VERSION}"
38
+ exit
39
+ end
40
+
41
+ parser.on_tail("-h", "--help", "Show this message") do
42
+ @stdout.puts parser
43
+ exit
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -10,7 +10,12 @@ module Pidgin2Adium
10
10
 
11
11
  def run
12
12
  files_to_parse.each do |file_path|
13
- AdiumChatFileCreator.new(file_path, @aliases, @output_directory).create
13
+ success = AdiumChatFileCreator.new(file_path, @aliases, @output_directory).create
14
+ if success
15
+ $stdout.print "."
16
+ else
17
+ $stderr.puts "\n!! Could not parse #{file_path}"
18
+ end
14
19
  end
15
20
  end
16
21
 
@@ -1,3 +1,3 @@
1
1
  module Pidgin2Adium
2
- VERSION = "4.0.0.beta1"
2
+ VERSION = "4.0.0.beta2"
3
3
  end
@@ -5,30 +5,84 @@ describe "Parse a Pidgin log file" do
5
5
  FileUtils.rm_rf(tmp_directory)
6
6
  end
7
7
 
8
- it "outputs to the correct file" do
8
+ context "with good input" do
9
+ before do
10
+ $stdout = StringIO.new
11
+ end
12
+
13
+ it "outputs to the correct file" do
14
+ runner = Pidgin2Adium::Runner.new(
15
+ path_containing_good_pidgin_logs,
16
+ ["Gabe B-W"],
17
+ output_path
18
+ )
19
+
20
+ runner.run
21
+
22
+ path = Dir["#{output_path}/**/*.xml"].first
23
+
24
+ expect(path).to eq File.join(
25
+ tmp_directory,
26
+ "AIM.jiggerificbug",
27
+ "them@gmail.com",
28
+ "them@gmail.com (2014-03-16T23:55:43#{tz_offset}).chatlog",
29
+ "them@gmail.com (2014-03-16T23:55:43#{tz_offset}).xml",
30
+ )
31
+ end
32
+
33
+ it "does not print an error message" do
34
+ $stderr = StringIO.new
35
+
36
+ runner = Pidgin2Adium::Runner.new(
37
+ path_containing_good_pidgin_logs,
38
+ ["Gabe B-W"],
39
+ output_path
40
+ )
41
+
42
+ runner.run
43
+
44
+ expect($stderr.string).to eq ""
45
+ end
46
+
47
+ it "prints a dot to stdout" do
48
+ $stdout = StringIO.new
49
+
50
+ runner = Pidgin2Adium::Runner.new(
51
+ path_containing_good_pidgin_logs,
52
+ ["Gabe B-W"],
53
+ output_path
54
+ )
55
+
56
+ runner.run
57
+
58
+ expect($stdout.string).to eq "."
59
+ end
60
+
61
+ end
62
+
63
+ it "prints an error message if the chat is unparseable" do
64
+ $stderr = StringIO.new
65
+
9
66
  runner = Pidgin2Adium::Runner.new(
10
- path_containing_pidgin_logs,
67
+ path_containing_bad_pidgin_logs,
11
68
  ["Gabe B-W"],
12
69
  output_path
13
70
  )
14
71
 
15
72
  runner.run
16
73
 
17
- path = Dir["#{output_path}/**/*.xml"].first
18
-
19
- expect(path).to eq File.join(
20
- tmp_directory,
21
- "AIM.jiggerificbug",
22
- "them@gmail.com",
23
- "them@gmail.com (2014-03-16T23:55:43#{tz_offset}).chatlog",
24
- "them@gmail.com (2014-03-16T23:55:43#{tz_offset}).xml",
25
- )
74
+ expect($stderr.string).to match /Could not parse.*bad_input\/bad.html/
26
75
  end
27
76
 
28
- def path_containing_pidgin_logs
77
+
78
+ def path_containing_good_pidgin_logs
29
79
  File.join(SPEC_ROOT, "fixtures", "input")
30
80
  end
31
81
 
82
+ def path_containing_bad_pidgin_logs
83
+ File.join(SPEC_ROOT, "fixtures", "bad_input")
84
+ end
85
+
32
86
  def output_path
33
87
  File.expand_path(File.join(SPEC_ROOT, "..", "tmp"))
34
88
  end
@@ -0,0 +1,3 @@
1
+ <h1>Conversation with chat1841285841606654112</h1>
2
+ <FONT SIZE="2">(02:54:06)</FONT> <B>Gabe entered the room.</B><BR>
3
+ <FONT SIZE="2">(02:54:06)</FONT> <B>the other one entered the room.</B><BR>
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Pidgin2Adium::Cli do
4
+ context "#parse" do
5
+ it "passes in_directory and aliases to a Runner" do
6
+ runner = double("runner", run: nil)
7
+ allow(Pidgin2Adium::Runner).to receive(:new).and_return(runner)
8
+
9
+ argv = %w(--in home --aliases gabe,me)
10
+ cli = Pidgin2Adium::Cli.new(argv)
11
+ cli.parse_and_run
12
+
13
+ expect(Pidgin2Adium::Runner).to have_received(:new).with(
14
+ "home", %w(gabe me)
15
+ )
16
+ expect(runner).to have_received(:run)
17
+ end
18
+
19
+ it "prints to stderr if --in is missing" do
20
+ stderr = StringIO.new
21
+
22
+ cli = Pidgin2Adium::Cli.new(%w(-a hello), stderr: stderr)
23
+
24
+ rescuing_from_exit { cli.parse_and_run }
25
+
26
+ expect(stderr.string).to include "Please provide"
27
+ end
28
+
29
+ it "prints to stderr if --aliases is missing" do
30
+ stderr = StringIO.new
31
+
32
+ cli = Pidgin2Adium::Cli.new(%w(--in home), stderr: stderr)
33
+
34
+ rescuing_from_exit { cli.parse_and_run }
35
+
36
+ expect(stderr.string).to include "Please provide"
37
+ end
38
+
39
+ it "prints its version" do
40
+ stdout = StringIO.new
41
+
42
+ cli = Pidgin2Adium::Cli.new(%w(-v), stdout: stdout)
43
+
44
+ rescuing_from_exit { cli.parse_and_run }
45
+
46
+ expect(stdout.string).to eq "Pidgin2Adium, version #{Pidgin2Adium::VERSION}\n"
47
+ end
48
+
49
+ def rescuing_from_exit
50
+ begin
51
+ yield
52
+ rescue SystemExit
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pidgin2adium
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta1
4
+ version: 4.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Berke-Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pipio
@@ -99,14 +99,17 @@ files:
99
99
  - bin/pidgin2adium
100
100
  - lib/pidgin2adium.rb
101
101
  - lib/pidgin2adium/adium_chat_file_creator.rb
102
+ - lib/pidgin2adium/cli.rb
102
103
  - lib/pidgin2adium/file_finder.rb
103
104
  - lib/pidgin2adium/runner.rb
104
105
  - lib/pidgin2adium/version.rb
105
106
  - pidgin2adium.gemspec
106
107
  - spec/features/parse_pidgin_log_file_spec.rb
108
+ - spec/fixtures/bad_input/bad.html
107
109
  - spec/fixtures/input/input.html
108
110
  - spec/fixtures/output.xml
109
111
  - spec/pidgin2adium/adium_chat_file_creator_spec.rb
112
+ - spec/pidgin2adium/cli_spec.rb
110
113
  - spec/pidgin2adium/file_finder_spec.rb
111
114
  - spec/spec_helper.rb
112
115
  homepage: https://github.com/gabebw/pidgin2adium
@@ -135,8 +138,10 @@ specification_version: 4
135
138
  summary: A fast, easy way to convert Pidgin (gaim) logs to the Adium format.
136
139
  test_files:
137
140
  - spec/features/parse_pidgin_log_file_spec.rb
141
+ - spec/fixtures/bad_input/bad.html
138
142
  - spec/fixtures/input/input.html
139
143
  - spec/fixtures/output.xml
140
144
  - spec/pidgin2adium/adium_chat_file_creator_spec.rb
145
+ - spec/pidgin2adium/cli_spec.rb
141
146
  - spec/pidgin2adium/file_finder_spec.rb
142
147
  - spec/spec_helper.rb