pidgin2adium 3.3.0 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -3
  3. data/.rspec +1 -0
  4. data/.simplecov +5 -0
  5. data/.travis.yml +12 -0
  6. data/Gemfile +6 -1
  7. data/LICENSE +17 -17
  8. data/NEWS.md +89 -0
  9. data/README.md +60 -0
  10. data/Rakefile +5 -23
  11. data/bin/pidgin2adium +19 -90
  12. data/lib/pidgin2adium.rb +4 -136
  13. data/lib/pidgin2adium/adium_chat_file_creator.rb +64 -0
  14. data/lib/pidgin2adium/file_finder.rb +23 -0
  15. data/lib/pidgin2adium/runner.rb +23 -0
  16. data/lib/pidgin2adium/version.rb +1 -1
  17. data/pidgin2adium.gemspec +25 -21
  18. data/spec/features/parse_pidgin_log_file_spec.rb +50 -0
  19. data/spec/fixtures/input/input.html +3 -0
  20. data/spec/fixtures/output.xml +5 -0
  21. data/spec/pidgin2adium/adium_chat_file_creator_spec.rb +89 -0
  22. data/spec/pidgin2adium/file_finder_spec.rb +63 -0
  23. data/spec/spec_helper.rb +17 -59
  24. metadata +96 -89
  25. data/.autotest +0 -28
  26. data/ChangeLog +0 -79
  27. data/Manifest.txt +0 -18
  28. data/README.rdoc +0 -122
  29. data/config/website.yml +0 -2
  30. data/ext/balance_tags_c/balance_tags_c.c +0 -198
  31. data/ext/balance_tags_c/extconf.rb +0 -4
  32. data/lib/pidgin2adium/log_converter.rb +0 -71
  33. data/lib/pidgin2adium/log_file.rb +0 -100
  34. data/lib/pidgin2adium/log_parser.rb +0 -2
  35. data/lib/pidgin2adium/message.rb +0 -2
  36. data/lib/pidgin2adium/messages/all.rb +0 -5
  37. data/lib/pidgin2adium/messages/auto_reply_message.rb +0 -11
  38. data/lib/pidgin2adium/messages/event.rb +0 -17
  39. data/lib/pidgin2adium/messages/message.rb +0 -39
  40. data/lib/pidgin2adium/messages/status_message.rb +0 -17
  41. data/lib/pidgin2adium/messages/xml_message.rb +0 -40
  42. data/lib/pidgin2adium/parsers/all.rb +0 -3
  43. data/lib/pidgin2adium/parsers/basic_parser.rb +0 -456
  44. data/lib/pidgin2adium/parsers/html_log_parser.rb +0 -125
  45. data/lib/pidgin2adium/parsers/text_log_parser.rb +0 -39
  46. data/spec/balance_tags_c_extn_spec.rb +0 -47
  47. data/spec/basic_parser_spec.rb +0 -219
  48. data/spec/html_log_parser_spec.rb +0 -150
  49. data/spec/log_converter_spec.rb +0 -48
  50. data/spec/log_file_spec.rb +0 -176
  51. data/spec/logfiles/2006-12-21.223606.txt +0 -3
  52. data/spec/logfiles/2008-01-15.071445-0500PST.htm +0 -5
  53. data/spec/logfiles/2008-01-15.071445-0500PST.html +0 -5
  54. data/spec/pidgin2adium_spec.rb +0 -252
  55. data/spec/spec.opts +0 -1
  56. data/spec/test-output/README.md +0 -1
  57. data/spec/test-output/html_log_output.xml +0 -6
  58. data/spec/test-output/text_log_output.xml +0 -4
  59. data/spec/text_log_parser_spec.rb +0 -42
  60. data/tasks/extconf.rake +0 -8
  61. data/tasks/extconf/balance_tags_c.rake +0 -47
@@ -0,0 +1,64 @@
1
+ require "pathname"
2
+
3
+ module Pidgin2Adium
4
+ class AdiumChatFileCreator
5
+ def initialize(file_path, aliases, output_directory = Runner::ADIUM_LOG_DIRECTORY)
6
+ @file_path = file_path
7
+ @aliases = aliases
8
+ @output_directory = Pathname.new(output_directory.to_s)
9
+ end
10
+
11
+ 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
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def create_containing_directory
24
+ FileUtils.mkdir_p(File.dirname(path))
25
+ end
26
+
27
+ def path
28
+ @output_directory.join(
29
+ "#{normalized_service}.#{chat.my_screen_name}",
30
+ chat.their_screen_name,
31
+ "#{chat.their_screen_name} (#{formatted_start_time}).chatlog",
32
+ "#{chat.their_screen_name} (#{formatted_start_time}).xml"
33
+ )
34
+ end
35
+
36
+ def xml_prolog
37
+ %(<?xml version="1.0" encoding="UTF-8" ?>)
38
+ end
39
+
40
+ def opening_chat_tag
41
+ %(<chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="#{chat.my_screen_name}" service="#{normalized_service}" adiumversion="1.5.9">)
42
+ end
43
+
44
+ def closing_chat_tag
45
+ "</chat>"
46
+ end
47
+
48
+ def formatted_start_time
49
+ chat.start_time.xmlschema.sub(/:00$/, "00")
50
+ end
51
+
52
+ def normalized_service
53
+ if chat.service == "aim"
54
+ "AIM"
55
+ else
56
+ chat.service
57
+ end
58
+ end
59
+
60
+ def chat
61
+ @chat ||= Pipio.parse(@file_path, @aliases)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ module Pidgin2Adium
2
+ class FileFinder
3
+ EXTENSIONS = %w(html htm txt)
4
+
5
+ def initialize(directory)
6
+ @directory = File.expand_path(directory)
7
+ end
8
+
9
+ def find
10
+ Dir[glob]
11
+ end
12
+
13
+ private
14
+
15
+ def glob
16
+ File.join(@directory, "**/*.{#{comma_separated_extensions}}")
17
+ end
18
+
19
+ def comma_separated_extensions
20
+ EXTENSIONS.join(",")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Pidgin2Adium
2
+ class Runner
3
+ ADIUM_LOG_DIRECTORY = Pathname.new(File.expand_path('~/Library/Application Support/Adium 2.0/Users/Default/Logs/'))
4
+
5
+ def initialize(path_to_input_directory, aliases, output_directory = ADIUM_LOG_DIRECTORY)
6
+ @path_to_input_directory = path_to_input_directory
7
+ @aliases = aliases
8
+ @output_directory = output_directory
9
+ end
10
+
11
+ def run
12
+ files_to_parse.each do |file_path|
13
+ AdiumChatFileCreator.new(file_path, @aliases, @output_directory).create
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def files_to_parse
20
+ FileFinder.new(@path_to_input_directory).find
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Pidgin2Adium
2
- VERSION = "3.3.0"
2
+ VERSION = "4.0.0.beta1"
3
3
  end
data/pidgin2adium.gemspec CHANGED
@@ -1,25 +1,29 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "pidgin2adium/version"
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = "pidgin2adium"
7
- s.date = "2011-10-16"
8
- s.version = Pidgin2Adium::VERSION
9
- s.platform = Gem::Platform::RUBY
10
- s.authors = ["Gabe Berke-Williams"]
11
- s.email = "gbw@brandeis.edu"
12
- s.description = "Pidgin2Adium is a fast, easy way to convert Pidgin (formerly gaim) logs to the Adium format."
13
- s.summary = "Pidgin2Adium is a fast, easy way to convert Pidgin (formerly gaim) logs to the Adium format"
14
- s.extensions = ["ext/balance_tags_c/extconf.rb"]
15
- s.extra_rdoc_files = ["ChangeLog", "LICENSE", "README.rdoc" ]
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.homepage = "http://github.com/gabebw/pidgin2adium"
20
- s.require_paths = ["lib"]
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pidgin2adium"
8
+ spec.version = Pidgin2Adium::VERSION
9
+ spec.authors = ["Gabe Berke-Williams"]
10
+ spec.email = "gabe@thoughtbot.com"
11
+ spec.description = "A fast, easy way to convert Pidgin (gaim) logs to the Adium format."
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/gabebw/pidgin2adium"
14
+ spec.license = "MIT"
21
15
 
22
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
23
- s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
24
- end
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
25
22
 
23
+ spec.add_dependency("pipio", "~> 0.0.2")
24
+
25
+ spec.add_development_dependency("rspec", "~> 3.0")
26
+ spec.add_development_dependency("rake")
27
+ spec.add_development_dependency("simplecov")
28
+ spec.add_development_dependency("fakefs")
29
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe "Parse a Pidgin log file" do
4
+ before do
5
+ FileUtils.rm_rf(tmp_directory)
6
+ end
7
+
8
+ it "outputs to the correct file" do
9
+ runner = Pidgin2Adium::Runner.new(
10
+ path_containing_pidgin_logs,
11
+ ["Gabe B-W"],
12
+ output_path
13
+ )
14
+
15
+ runner.run
16
+
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
+ )
26
+ end
27
+
28
+ def path_containing_pidgin_logs
29
+ File.join(SPEC_ROOT, "fixtures", "input")
30
+ end
31
+
32
+ def output_path
33
+ File.expand_path(File.join(SPEC_ROOT, "..", "tmp"))
34
+ end
35
+
36
+ def path_to_output_fixture
37
+ File.join(SPEC_ROOT, "fixtures", "output.xml")
38
+ end
39
+
40
+ def tz_offset
41
+ Time.now.strftime("%z").sub(":", "")
42
+ end
43
+
44
+ def tmp_directory
45
+ File.join(
46
+ File.dirname(SPEC_ROOT),
47
+ "tmp"
48
+ )
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ <head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with them@gmail.com at 3/16/2014 11:55:43 PM on jiggerificbug (aim)</title></head><h3>Conversation with them@gmail.com at 3/16/2014 11:55:43 PM on jiggerificbug (aim)</h3>
2
+ <font color="#A82F2F"><font size="2">(2014-03-16 23:55:48)</font> <b>Some Rando:</b></font> <span style='background: #ffffff;'><span style='font-weight: bold;'><span style='color: #ff8000;'>Hi</span></span></span><br/>
3
+ <font color="#16569E"><font size="2">(2014-03-15 23:55:50)</font> <b>Gabe B-W:</b></font> <span style='color: #000000;'>Hi back</span><br/>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="jiggerificbug" service="AIM" adiumversion="1.5.9">
3
+ <message sender="them@gmail.com" time="2014-03-16T23:55:48-0400" alias="Some Rando"><div><span style="font-family: Helvetica; font-size: 12pt;">Hi</span></div></message>
4
+ <message sender="jiggerificbug" time="2014-03-16T23:55:50-0400"><div><span style="font-family: Helvetica; font-size: 12pt;">Hi back</span></div></message>
5
+ </chat>
@@ -0,0 +1,89 @@
1
+ require "spec_helper"
2
+
3
+ describe Pidgin2Adium::AdiumChatFileCreator do
4
+ unless on_travis_ci?
5
+ include FakeFS::SpecHelpers
6
+ end
7
+
8
+ it "creates a file in the correct place" do
9
+ chat = stub_chat
10
+
11
+ chat_file_creator = Pidgin2Adium::AdiumChatFileCreator.new(path_to_file, %w(gabe))
12
+ chat_file_creator.create
13
+
14
+ expect(File.exist?(path_for(chat))).to be true
15
+ end
16
+
17
+ it "writes the correct prolog" do
18
+ create_file
19
+
20
+ expect(file_contents.first).to eq %(<?xml version="1.0" encoding="UTF-8" ?>\n)
21
+ end
22
+
23
+ it "writes the correct opening <chat> tag" do
24
+ create_file
25
+
26
+ second_line = file_contents[1]
27
+
28
+ expect(second_line).to eq(
29
+ %(<chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="#{chat.my_screen_name}" service="AIM" adiumversion="1.5.9">\n)
30
+ )
31
+ end
32
+
33
+ it "calls to_s on each message and puts it in the file" do
34
+ create_file
35
+
36
+ lines = file_contents[2, chat.messages.size]
37
+
38
+ expect(lines.map(&:chomp)).to eq(chat.messages.map(&:to_s))
39
+ end
40
+
41
+ it "includes a closing </chat> tag" do
42
+ create_file
43
+
44
+ last_line = file_contents.last
45
+
46
+ expect(last_line.chomp).to eq("</chat>")
47
+ end
48
+
49
+ def stub_chat(new_chat = chat)
50
+ allow(Pipio).to receive(:parse).and_return(new_chat)
51
+ new_chat
52
+ end
53
+
54
+ def chat
55
+ time = Time.now
56
+ messages = [:a, 1, 3]
57
+ double(
58
+ my_screen_name: "me",
59
+ their_screen_name: "them",
60
+ start_time: time,
61
+ service: "aim",
62
+ messages: messages,
63
+ to_s: messages.map(&:to_s).join("\n")
64
+ )
65
+ end
66
+
67
+ def file_contents
68
+ File.readlines(path_for(chat))
69
+ end
70
+
71
+ def create_file
72
+ chat = stub_chat
73
+ chat_file_creator = Pidgin2Adium::AdiumChatFileCreator.new(path_to_file, %w(gabe))
74
+ chat_file_creator.create
75
+ end
76
+
77
+ def path_for(chat)
78
+ Pidgin2Adium::Runner::ADIUM_LOG_DIRECTORY.join(
79
+ "AIM.#{chat.my_screen_name}",
80
+ chat.their_screen_name,
81
+ "#{chat.their_screen_name} (#{xmlschema_for(chat)}).chatlog",
82
+ "#{chat.their_screen_name} (#{xmlschema_for(chat)}).xml"
83
+ ).to_s
84
+ end
85
+
86
+ def xmlschema_for(chat)
87
+ chat.start_time.xmlschema.sub(/:00$/, "00")
88
+ end
89
+ end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ describe Pidgin2Adium::FileFinder do
4
+ if on_travis_ci?
5
+ before do
6
+ FileUtils.rm_rf(expanded_directory)
7
+ end
8
+ else
9
+ include FakeFS::SpecHelpers
10
+ end
11
+
12
+ before do
13
+ FileUtils.mkdir_p(expanded_directory_with_username)
14
+ end
15
+
16
+ it "finds .html files" do
17
+ create_file_with_extension("html")
18
+
19
+ file_finder = Pidgin2Adium::FileFinder.new(unexpanded_directory)
20
+
21
+ expect(file_finder.find).to eq ["#{expanded_directory_with_username}/in.html"]
22
+ end
23
+
24
+ it "finds .htm files" do
25
+ create_file_with_extension("htm")
26
+
27
+ file_finder = Pidgin2Adium::FileFinder.new(unexpanded_directory)
28
+
29
+ expect(file_finder.find).to eq ["#{expanded_directory_with_username}/in.htm"]
30
+ end
31
+
32
+ it "finds .txt files" do
33
+ create_file_with_extension("txt")
34
+
35
+ file_finder = Pidgin2Adium::FileFinder.new(unexpanded_directory)
36
+
37
+ expect(file_finder.find).to eq ["#{expanded_directory_with_username}/in.txt"]
38
+ end
39
+
40
+ it "does not find files with other extensions" do
41
+ create_file_with_extension("bad")
42
+
43
+ file_finder = Pidgin2Adium::FileFinder.new(unexpanded_directory)
44
+
45
+ expect(file_finder.find).to eq []
46
+ end
47
+
48
+ def unexpanded_directory
49
+ "~/input-logs/"
50
+ end
51
+
52
+ def expanded_directory_with_username
53
+ File.join(expanded_directory, "gabebw")
54
+ end
55
+
56
+ def expanded_directory
57
+ File.expand_path(unexpanded_directory)
58
+ end
59
+
60
+ def create_file_with_extension(extension)
61
+ FileUtils.touch(File.join(expanded_directory_with_username, "in.#{extension}"))
62
+ end
63
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,71 +1,29 @@
1
- require 'fileutils'
1
+ require 'simplecov'
2
2
 
3
- # Pidgin2Adium.oops and Pidgin2Adium.warn both use warn() to output errors.
4
- # Setting $-w (the warning level) to nil suppresses them, which makes for
5
- # much prettier test output.
6
- $-w=nil # OMGHAX
3
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
7
5
 
8
- # Wrap it in a lambda so that we can pass it to Spork.prefork, if spork is installed.
9
- prefork_block = lambda do
10
- # Loading more in this block will cause your tests to run faster. However,
11
- # if you change any configuration or code from libraries loaded here, you'll
12
- # need to restart spork for it take effect.
6
+ require 'pidgin2adium'
7
+ require "fakefs/spec_helpers"
13
8
 
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext', 'balance_tags_c'))
9
+ Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
17
10
 
18
- require 'pidgin2adium'
19
- require 'time' # for Time.zone_offset
11
+ SPEC_ROOT = File.dirname(__FILE__)
20
12
 
21
- rspec_configure_block = lambda do |config|
22
- config.before(:all) do
23
- @current_dir = File.dirname(__FILE__)
24
- @aliases = %w{gabebw gabeb-w gbw me}.join(',')
25
- # -7 => "-0700"
26
- @current_tz_offset = sprintf("%+03d00", Time.zone_offset(Time.new.zone) / 3600)
27
-
28
- @logfile_path = File.join(@current_dir, "logfiles/")
29
- @text_logfile_path = "#{@logfile_path}/2006-12-21.223606.txt"
30
- @htm_logfile_path = "#{@logfile_path}/2008-01-15.071445-0500PST.htm"
31
- @html_logfile_path = "#{@logfile_path}/2008-01-15.071445-0500PST.html"
32
-
33
- @nonexistent_output_dir = File.join(@current_dir, "nonexistent_output_dir/")
34
- @output_dir = File.join(@current_dir, "output-dir/")
35
- FileUtils.rm_r(@nonexistent_output_dir, :force => true)
36
- end
13
+ RSpec.configure do |config|
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = :expect
16
+ end
37
17
 
38
- config.after(:all) do
39
- # Clean up.
40
- FileUtils.rm_r(@nonexistent_output_dir, :force => true)
41
- FileUtils.rm_r(@output_dir, :force => true)
42
- end
18
+ def path_to_file
19
+ File.join(path_to_directory, "gabebw", "in.html")
43
20
  end
44
21
 
45
- begin
46
- # RSpec 2
47
- gem 'rspec', '>= 2.0.0.beta.18'
48
- require 'rspec'
49
- RSpec.configure(&rspec_configure_block)
50
- rescue Gem::LoadError
51
- # RSpec 1
52
- gem 'rspec', '~> 1.3'
53
- require 'spec'
54
- require 'spec/autorun'
55
- Spec::Runner.configure(&rspec_configure_block)
22
+ def path_to_directory
23
+ File.expand_path("./in-logs/")
56
24
  end
57
- end
58
25
 
59
- begin
60
- require 'rubygems'
61
- require 'spork'
62
- Spork.prefork(&prefork_block)
63
- Spork.each_run do
64
- # This code will be run each time you run your specs.
26
+ def on_travis_ci?
27
+ ENV['TRAVIS']
65
28
  end
66
- rescue LoadError
67
- puts 'To make the tests run faster, run "sudo gem install spork" then run "spork"'
68
- puts 'from the base pidgin2adium directory.'
69
- # Spork isn't installed.
70
- prefork_block.call
71
29
  end