ucallback 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ -fs
3
+ -Ilib
4
+ -Ispec
5
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ucallback.gemspec
4
+ gemspec
@@ -0,0 +1,64 @@
1
+ # µCallback
2
+
3
+ ## What is µCallback?
4
+
5
+ µCallback makes it possible to call a script or application when a BitTorrent download finishes.
6
+
7
+ It has support both [Transmission](http://www.transmissionbt.com/) and [µTorrent](http://user.utorrent.com/), even though Transmission already supports it.
8
+
9
+ ## How to use
10
+
11
+ ### Installation
12
+
13
+ [sudo] gem install ucallback
14
+
15
+ ### An example - The *synchronous* version
16
+
17
+ This example listen for µTorrent downloads. When a download finishes, the block is being called with the name of the downloaded item.
18
+
19
+ So if you downloaded *House.S07E11.HDTV.XviD-LOL.avi* the `item` variable would be set to just that value.
20
+
21
+ #!/usr/bin/env ruby
22
+
23
+ require 'rubygems'
24
+ require 'ucallback'
25
+
26
+ Ucallback.listen('uTorrent') do |item|
27
+ # Do something with the information
28
+ end
29
+
30
+ ### A background example - The *asynchronous* version
31
+
32
+ The previous example runs as an synchronous script, but what if you what to run it in the background?
33
+
34
+ The [daemonize](http://daemons.rubyforge.org/) gem fixes this for us. It daemonizes the current thread so we can run it in the background.
35
+
36
+ Don't forget to install `daemonize` using `[sudo] gem install daemons`
37
+
38
+ #!/usr/bin/env ruby
39
+
40
+ require 'rubygems'
41
+ require 'ucallback'
42
+ require 'daemons'
43
+
44
+ Daemons.daemonize
45
+
46
+ Ucallback.listen('Transmission') do |item|
47
+ # Do something with the information
48
+ end
49
+
50
+ Save the code above to a file, run `chmod +x the_file_you_just_created` on it and you should be able to start it using `the_file_you_just_created`.
51
+
52
+ ## How to help
53
+
54
+ - Start by copying the project or make your own branch.
55
+ - Navigate to the root path of the project and run `bundle`.
56
+ - Start by running all tests using rspec, `rspec spec/ucallback_spec.rb`.
57
+ - Implement your own code, write some tests, commit and do a pull request.
58
+
59
+ ## Requirements
60
+
61
+ µCallback is tested on OS X 10.6.6 using Ruby 1.8.7.
62
+ With µTorrent [beta 1.1](http://user.utorrent.com/downloads/mac).
63
+
64
+ **µCallback only works with µTorrent versions that supports [Growl](http://growl.info/) messages.**
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This should not be used in production, it's only for testing
3
+ # This file is being called from the spec file
4
+
5
+ $:.push File.expand_path("../../lib", __FILE__)
6
+
7
+ require 'rubygems'
8
+ require 'ucallback'
9
+
10
+ Ucallback.listen(ARGV[1]) do |item|
11
+ system "echo '#{item}' >> #{ARGV[0]}"
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'fsevent'
3
+
4
+ class Ucallback < FSEvent
5
+ def self.listen(application = 'uTorrent', &block)
6
+ this = self.new(application, block)
7
+ this.latency = 0.0
8
+ this.watch_directories this.log_dir
9
+ this.start
10
+ end
11
+
12
+ def initialize(application, block)
13
+ @block = block
14
+ @application = application
15
+ @last_line = get_last_line
16
+ end
17
+
18
+ def on_change(directories)
19
+ last_line = get_last_line
20
+ # If the last line is equal to this one
21
+ # Is means that the file that was changes isn't system.log
22
+ return if @last_line == last_line or last_line.empty? ; @last_line = last_line
23
+
24
+ @block.call($1) if last_line =~ /#{self.matcher}/i
25
+ end
26
+
27
+ def log_dir
28
+ "/private/var/log/"
29
+ # "/tmp/temp_system" # Only for testing
30
+ end
31
+
32
+ def log_file
33
+ "#{self.log_dir}/system.log"
34
+ end
35
+
36
+ def get_last_line
37
+ %x{tail -n 1 #{log_file}}
38
+ end
39
+
40
+ def matcher
41
+ "#{@application}: Download complete \((.*?)\) - Priority"
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Ucallback
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,90 @@
1
+ Feb 8 23:49:55 linus-oleanders-macbook com.mysql.mysqld[26208]: 110208 23:49:55 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
2
+ Feb 8 23:49:55 linus-oleanders-macbook com.mysql.mysqld[26208]: 110208 23:49:55 mysqld_safe A mysqld process already exists
3
+ Feb 8 23:49:55 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26208]): Exited with exit code: 1
4
+ Feb 8 23:49:55 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
5
+ Feb 8 23:49:58 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: Handling SIGTERM in renderer.
6
+ Feb 8 23:49:58 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: Wrote signal to shutdown pipe.
7
+ Feb 8 23:49:59 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
8
+ Feb 8 23:50:00 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: Handling SIGTERM in renderer.
9
+ Feb 8 23:50:00 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: Wrote signal to shutdown pipe.
10
+ Feb 8 23:50:01 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26238]): Exited with exit code: 100
11
+ Feb 8 23:50:01 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
12
+ Feb 8 23:50:04 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
13
+ Feb 8 23:50:05 linus-oleanders-macbook com.mysql.mysqld[26241]: 110208 23:50:05 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
14
+ Feb 8 23:50:05 linus-oleanders-macbook com.mysql.mysqld[26241]: 110208 23:50:05 mysqld_safe A mysqld process already exists
15
+ Feb 8 23:50:05 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26241]): Exited with exit code: 1
16
+ Feb 8 23:50:05 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
17
+ Feb 8 23:50:09 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
18
+ Feb 8 23:50:11 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26273]): Exited with exit code: 100
19
+ Feb 8 23:50:11 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
20
+ Feb 8 23:50:14 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
21
+ Feb 8 23:50:15 linus-oleanders-macbook com.mysql.mysqld[26277]: 110208 23:50:15 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
22
+ Feb 8 23:50:15 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: objc[26276]: Class CrApplication is implemented in both /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Helper.app/Contents/MacOS/../../../Google Chrome Framework.framework/Google Chrome Framework and /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Framework.framework/Internet Plug-Ins/PDF.plugin/Contents/MacOS/PDF. One of the two will be used. Which one is undefined.
23
+ Feb 8 23:50:15 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: objc[26276]: Class NoOp is implemented in both /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Helper.app/Contents/MacOS/../../../Google Chrome Framework.framework/Google Chrome Framework and /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Framework.framework/Internet Plug-Ins/PDF.plugin/Contents/MacOS/PDF. One of the two will be used. Which one is undefined.
24
+ Feb 8 23:50:15 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: objc[26276]: Class TaskOperation is implemented in both /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Helper.app/Contents/MacOS/../../../Google Chrome Framework.framework/Google Chrome Framework and /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Framework.framework/Internet Plug-Ins/PDF.plugin/Contents/MacOS/PDF. One of the two will be used. Which one is undefined.
25
+ Feb 8 23:50:15 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: objc[26276]: Class WorkerPoolObjC is implemented in both /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Helper.app/Contents/MacOS/../../../Google Chrome Framework.framework/Google Chrome Framework and /Applications/Google Chrome.app/Contents/Versions/9.0.597.84/Google Chrome Framework.framework/Internet Plug-Ins/PDF.plugin/Contents/MacOS/PDF. One of the two will be used. Which one is undefined.
26
+ Feb 8 23:50:15 linus-oleanders-macbook com.mysql.mysqld[26277]: 110208 23:50:15 mysqld_safe A mysqld process already exists
27
+ Feb 8 23:50:15 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26277]): Exited with exit code: 1
28
+ Feb 8 23:50:15 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
29
+ Feb 8 23:50:19 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
30
+ Feb 8 23:50:21 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26307]): Exited with exit code: 100
31
+ Feb 8 23:50:21 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
32
+ Feb 8 23:50:24 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
33
+ Feb 8 23:50:25 linus-oleanders-macbook com.mysql.mysqld[26310]: 110208 23:50:25 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
34
+ Feb 8 23:50:26 linus-oleanders-macbook com.mysql.mysqld[26310]: 110208 23:50:26 mysqld_safe A mysqld process already exists
35
+ Feb 8 23:50:26 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26310]): Exited with exit code: 1
36
+ Feb 8 23:50:26 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
37
+ Feb 8 23:50:26 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: Handling SIGTERM in renderer.
38
+ Feb 8 23:50:26 linus-oleanders-macbook [0x0-0x347347].com.google.Chrome[66312]: Wrote signal to shutdown pipe.
39
+ Feb 8 23:50:29 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
40
+ Feb 8 23:50:31 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26340]): Exited with exit code: 100
41
+ Feb 8 23:50:31 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
42
+ Feb 8 23:50:34 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
43
+ Feb 8 23:50:36 linus-oleanders-macbook com.mysql.mysqld[26343]: 110208 23:50:36 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
44
+ Feb 8 23:50:36 linus-oleanders-macbook com.mysql.mysqld[26343]: 110208 23:50:36 mysqld_safe A mysqld process already exists
45
+ Feb 8 23:50:36 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26343]): Exited with exit code: 1
46
+ Feb 8 23:50:36 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
47
+ Feb 8 23:50:39 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
48
+ Feb 8 23:50:42 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26373]): Exited with exit code: 100
49
+ Feb 8 23:50:42 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
50
+ Feb 8 23:50:44 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
51
+ Feb 8 23:50:46 linus-oleanders-macbook com.mysql.mysqld[26376]: 110208 23:50:46 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
52
+ Feb 8 23:50:46 linus-oleanders-macbook com.mysql.mysqld[26376]: 110208 23:50:46 mysqld_safe A mysqld process already exists
53
+ Feb 8 23:50:46 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26376]): Exited with exit code: 1
54
+ Feb 8 23:50:46 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
55
+ Feb 8 23:50:49 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
56
+ Feb 8 23:50:52 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26406]): Exited with exit code: 100
57
+ Feb 8 23:50:52 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
58
+ Feb 8 23:50:54 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
59
+ Feb 8 23:50:56 linus-oleanders-macbook com.mysql.mysqld[26409]: 110208 23:50:56 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
60
+ Feb 8 23:50:56 linus-oleanders-macbook com.mysql.mysqld[26409]: 110208 23:50:56 mysqld_safe A mysqld process already exists
61
+ Feb 8 23:50:56 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26409]): Exited with exit code: 1
62
+ Feb 8 23:50:56 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
63
+ Feb 8 23:50:59 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
64
+ Feb 8 23:51:02 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26439]): Exited with exit code: 100
65
+ Feb 8 23:51:02 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
66
+ Feb 8 23:51:04 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
67
+ Feb 8 23:51:06 linus-oleanders-macbook com.mysql.mysqld[26442]: 110208 23:51:06 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
68
+ Feb 8 23:51:06 linus-oleanders-macbook com.mysql.mysqld[26442]: 110208 23:51:06 mysqld_safe A mysqld process already exists
69
+ Feb 8 23:51:06 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26442]): Exited with exit code: 1
70
+ Feb 8 23:51:06 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
71
+ Feb 8 23:51:09 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
72
+ Feb 8 23:51:12 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26472]): Exited with exit code: 100
73
+ Feb 8 23:51:12 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
74
+ Feb 8 23:51:14 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
75
+ Feb 8 23:51:16 linus-oleanders-macbook com.mysql.mysqld[26475]: 110208 23:51:16 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
76
+ Feb 8 23:51:16 linus-oleanders-macbook com.mysql.mysqld[26475]: 110208 23:51:16 mysqld_safe A mysqld process already exists
77
+ Feb 8 23:51:16 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26475]): Exited with exit code: 1
78
+ Feb 8 23:51:16 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
79
+ Feb 8 23:51:19 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
80
+ Feb 8 23:51:22 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26505]): Exited with exit code: 100
81
+ Feb 8 23:51:22 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
82
+ Feb 8 23:51:24 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
83
+ Feb 8 23:51:26 linus-oleanders-macbook com.mysql.mysqld[26508]: 110208 23:51:26 mysqld_safe Logging to '/Users/linus/Developer/var/mysql/linus-oleanders-macbook.local.err'.
84
+ Feb 8 23:51:26 linus-oleanders-macbook com.mysql.mysqld[26508]: 110208 23:51:26 mysqld_safe A mysqld process already exists
85
+ Feb 8 23:51:26 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld[26508]): Exited with exit code: 1
86
+ Feb 8 23:51:26 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (com.mysql.mysqld): Throttling respawn: Will start in 10 seconds
87
+ Feb 8 23:51:29 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
88
+ Feb 8 23:51:32 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod[26538]): Exited with exit code: 100
89
+ Feb 8 23:51:32 linus-oleanders-macbook com.apple.launchd.peruser.501[153] (org.mongodb.mongod): Throttling respawn: Will start in 10 seconds
90
+ Feb 8 23:51:34 linus-oleanders-macbook [0x0-0x3c03c].org.tynsoe.geektool3[540]: tail: /Users/linus/Desktop/Inwite/log/development.log: No such file or directory
@@ -0,0 +1,9 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'rspec'
4
+ require 'digest/md5'
5
+ require 'ucallback'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec
9
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "a test" do
4
+ it "should not freeze" do
5
+ sleep 5
6
+ true.should be_true
7
+ end
8
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ def write(application = 'uTorrent')
3
+ system "echo '2011-02-09 01.56.09 GrowlHelperApp[533] #{application}: Download complete (House.S07E11.HDTV.XviD-LOL.avi) - Priority 0' >> /tmp/temp_system/system.log"
4
+ end
5
+
6
+ describe Ucallback do
7
+ before(:all) do
8
+ @log_file = File.expand_path(File.dirname(__FILE__) + "/data/system.log")
9
+ @bin = File.expand_path(File.dirname(__FILE__) + "../../bin/ucallback")
10
+ end
11
+
12
+ before(:each) do
13
+ random = Digest::MD5.hexdigest(Time.now.to_s)
14
+ @folder = "/tmp/#{random}"
15
+ @file = "#{@folder}/#{random}"
16
+ @tmp_log_file = "#{@folder}/system.log"
17
+
18
+ %x{mkdir -p /tmp/temp_system && rm -r /tmp/temp_system && mkdir -p /tmp/temp_system && mkdir -p #{@folder} && cp #{@log_file} /tmp/temp_system}
19
+
20
+ @loop = 0
21
+ end
22
+
23
+ it "should not see a message if the same already exists" do
24
+ system "sleep 3 && #{@bin} #{@file} uTorrent &"
25
+ write; sleep 6; write
26
+ loop do
27
+ sleep 0.2
28
+ @loop += 1
29
+ break if system "test -e #{@file}" or @loop == 10 # Breaks if the file exists
30
+ end
31
+
32
+ system("test -e #{@file}").should be_false
33
+ end
34
+
35
+ it "should know when a message is being passed" do
36
+ system "sleep 3 && #{@bin} #{@file} uTorrent &"
37
+ sleep 6; write
38
+
39
+ loop do
40
+ sleep 0.2
41
+ @loop += 1
42
+ break if system "test -e #{@file}" or @loop == 10 # Breaks if the file exists
43
+ end
44
+
45
+ File.read(@file).should match(/House\.S07E11\.HDTV\.XviD-LOL\.avi/)
46
+ end
47
+
48
+ it "should know when a message is being passed, using Transmission" do
49
+ system "sleep 3 && #{@bin} #{@file} Transmission &"
50
+ sleep 6; write("Transmission")
51
+
52
+ loop do
53
+ sleep 0.2
54
+ @loop += 1
55
+ break if system "test -e #{@file}" or @loop == 10 # Breaks if the file exists
56
+ end
57
+
58
+ File.read(@file).should match(/House\.S07E11\.HDTV\.XviD-LOL\.avi/)
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ucallback/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ucallback"
7
+ s.version = Ucallback::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Linus Oleander"]
10
+ s.email = ["linus@oleander.nu"]
11
+ s.homepage = ""
12
+ s.summary = %q{Makes it possible to call a script when a download finishes, using uTorrent or Transmission as a bittorrent client}
13
+ s.description = %q{The missing link between uTorrent and the console in OS X}
14
+
15
+ s.rubyforge_project = "ucallback"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('ruby-fsevent')
23
+ s.add_development_dependency('rspec')
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ucallback
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Linus Oleander
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-09 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ruby-fsevent
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: The missing link between uTorrent and the console in OS X
50
+ email:
51
+ - linus@oleander.nu
52
+ executables:
53
+ - ucallback
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - .rspec
61
+ - Gemfile
62
+ - README.markdown
63
+ - Rakefile
64
+ - bin/ucallback
65
+ - lib/ucallback.rb
66
+ - lib/ucallback/version.rb
67
+ - spec/data/system.log
68
+ - spec/spec_helper.rb
69
+ - spec/test.rb
70
+ - spec/ucallback_spec.rb
71
+ - ucallback.gemspec
72
+ has_rdoc: true
73
+ homepage: ""
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project: ucallback
102
+ rubygems_version: 1.5.0
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Makes it possible to call a script when a download finishes, using uTorrent or Transmission as a bittorrent client
106
+ test_files:
107
+ - spec/data/system.log
108
+ - spec/spec_helper.rb
109
+ - spec/test.rb
110
+ - spec/ucallback_spec.rb