leecher 0.2.3 → 1.0.0
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.
- data/.gitignore +5 -4
- data/.travis.yml +2 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +48 -0
- data/README +58 -0
- data/Rakefile +5 -7
- data/bin/leecher +2 -265
- data/bin/leecher-aria2-event-hook +12 -0
- data/config/amqp.example.yml +28 -0
- data/config/arguments.rb +12 -0
- data/config/aria2.example.yml +6 -0
- data/config/boot.rb +64 -0
- data/config/environment.rb +22 -0
- data/config/environments/development.rb +2 -0
- data/config/environments/production.rb +5 -0
- data/config/environments/test.rb +2 -0
- data/config/gheed.example.yml +2 -0
- data/config/leecher.example.yml +1 -0
- data/config/post-daemonize/readme +5 -0
- data/config/pre-daemonize/amqp.rb +6 -0
- data/config/pre-daemonize/json.rb +3 -0
- data/config/pre-daemonize/readme +12 -0
- data/config/pre-daemonize/safely.rb +13 -0
- data/leecher.gemspec +13 -4
- data/lib/leecher.rb +24 -2
- data/lib/leecher/aria2/client.rb +65 -0
- data/lib/leecher/client.rb +31 -211
- data/lib/leecher/gheed/client.rb +35 -0
- data/lib/leecher/metalink_queue.rb +68 -0
- data/lib/leecher/version.rb +1 -1
- data/libexec/leecher-daemon.rb +34 -0
- data/script/console +4 -0
- data/script/destroy +4 -0
- data/script/generate +4 -0
- data/spec/aria2/client_spec.rb +26 -0
- data/spec/client_spec.rb +42 -83
- data/spec/metalink_queue_spec.rb +25 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +0 -2
- data/tasks/rspec.rake +6 -0
- metadata +134 -90
- data/config/aria2.conf +0 -15
- data/config/client.yml +0 -32
- data/lib/leecher/log.rb +0 -91
- data/lib/leecher/shellout.rb +0 -27
- data/spec/shellout_spec.rb +0 -26
data/config/aria2.conf
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
dir=<%= aria2_dir %>
|
2
|
-
log=/tmp/aria.log
|
3
|
-
check-integrity=true
|
4
|
-
max-connection-per-server=<%= aria2_connections %>
|
5
|
-
min-split-size=1M
|
6
|
-
follow-torrent=mem
|
7
|
-
max-overall-upload-limit=30K
|
8
|
-
follow-metalink=mem
|
9
|
-
metalink-servers=<%= aria2_connections %>
|
10
|
-
rpc-listen-all=false
|
11
|
-
rpc-listen-port=<%= aria2_rpc_port %>
|
12
|
-
rpc-passwd=<%= aria2_rpc_password %>
|
13
|
-
rpc-user=<%= aria2_rpc_user %>
|
14
|
-
allow-piece-length-change=true
|
15
|
-
save-session=<%= File.join(config_dirname, "session.aria2") %>
|
data/config/client.yml
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
:username: <%= username %>
|
2
|
-
:password: <%= password %>
|
3
|
-
:metalink_queue_name: metalink
|
4
|
-
:log:
|
5
|
-
:level: :info
|
6
|
-
:filename: <%= File.join(config_dirname, "leecher.log") %>
|
7
|
-
:bunny_opts:
|
8
|
-
:host: <%= host %>
|
9
|
-
:port: 5672
|
10
|
-
:vhost: /
|
11
|
-
:user: <%= username %>
|
12
|
-
:pass: <%= password %>
|
13
|
-
:ssl: false
|
14
|
-
:verify_ssl: false
|
15
|
-
:logfile: <%= File.join(config_dirname, "bunny.log") %>
|
16
|
-
:logging: false
|
17
|
-
:frame_max: 131072
|
18
|
-
:channel_max: 0
|
19
|
-
:heartbeat: 300
|
20
|
-
:connect_timeout: 5
|
21
|
-
:aria2_opts:
|
22
|
-
:config: <%= File.join(config_dirname, "aria2.conf") %>
|
23
|
-
:bin: <%= aria2_bin %>
|
24
|
-
:args: [-D, --enable-rpc]
|
25
|
-
:user: <%= aria2_rpc_user %>
|
26
|
-
:password: <%= aria2_rpc_password %>
|
27
|
-
:port: <%= aria2_rpc_port %>
|
28
|
-
:daemon:
|
29
|
-
:chdir: <%= File.join(config_dirname) %>
|
30
|
-
:umask: 0000
|
31
|
-
:stdout: <%= File.join(config_dirname, "stdout") %>
|
32
|
-
:stderr: <%= File.join(config_dirname, "stderr") %>
|
data/lib/leecher/log.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
module Leecher
|
2
|
-
|
3
|
-
class Log
|
4
|
-
|
5
|
-
require "time"
|
6
|
-
|
7
|
-
LEVELS = {
|
8
|
-
:debug => 0,
|
9
|
-
:warn => 1,
|
10
|
-
:info => 2,
|
11
|
-
:error => 3,
|
12
|
-
:fatal => 4,
|
13
|
-
}
|
14
|
-
|
15
|
-
attr_accessor :log_fn
|
16
|
-
attr_reader :level
|
17
|
-
|
18
|
-
def initialize(level = :debug,
|
19
|
-
log_fn = nil)
|
20
|
-
self.level = level
|
21
|
-
self.log_fn = log_fn
|
22
|
-
open_log_fd()
|
23
|
-
end
|
24
|
-
|
25
|
-
def open_log_fd
|
26
|
-
@log_fd.close() if @log_fd and not @log_fd.closed?
|
27
|
-
if self.log_fn
|
28
|
-
@log_fd = File.open(self.log_fn, "a")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def close_log_fd
|
33
|
-
if @log_fd and not @log_fd.closed?
|
34
|
-
@log_fd.flush()
|
35
|
-
@log_fd.close()
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
LEVELS.each_key do |level|
|
40
|
-
define_method(level) do |message|
|
41
|
-
write_to_log(level, message)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def level=(level)
|
46
|
-
@level = level
|
47
|
-
@_enum_level = LEVELS[level]
|
48
|
-
end
|
49
|
-
|
50
|
-
def write_to_log(level, message)
|
51
|
-
if LEVELS[level] >= @_enum_level
|
52
|
-
do_write_to_log(level, message)
|
53
|
-
else
|
54
|
-
# Toss it
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def do_write_to_log(level, message)
|
59
|
-
iso8601_timestr = Time.now.iso8601()
|
60
|
-
log_for_humans(iso8601_timestr, level, message)
|
61
|
-
|
62
|
-
if @log_fd and not @log_fd.closed?
|
63
|
-
@log_fd.puts("%s %s %s" % [iso8601_timestr, level.to_s.upcase, message])
|
64
|
-
@log_fd.flush()
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Map the log level (LOG_LEVEL_*) to an array containing
|
69
|
-
# [human_name:String, colour:String(ANSI escape sequence)]
|
70
|
-
ANSI_RED = "\033[0;31m"
|
71
|
-
ANSI_RED_INVERTED = "\033[7;31m"
|
72
|
-
ANSI_BROWN = "\033[0;33m"
|
73
|
-
ANSI_MAGENTA = "\033[0;35m"
|
74
|
-
ANSI_GREEN = "\033[0;32m"
|
75
|
-
ANSI_BOLD_WHITE = "\033[0;37m"
|
76
|
-
ANSI_NORMAL = "\033[0m"
|
77
|
-
HUMAN_LOG_LEVELS = {
|
78
|
-
:fatal => ["FATAL", ANSI_RED_INVERTED],
|
79
|
-
:error => ["ERROR", ANSI_RED],
|
80
|
-
:info => ["INFO", ANSI_GREEN],
|
81
|
-
:warn => ["WARN", ANSI_MAGENTA],
|
82
|
-
:debug => ["DEBUG", ANSI_BROWN],
|
83
|
-
}
|
84
|
-
def log_for_humans(iso8601_timestr, log_level, log_msg)
|
85
|
-
level_str, level_colour = HUMAN_LOG_LEVELS[log_level]
|
86
|
-
STDOUT.puts("#{ANSI_BOLD_WHITE}#{iso8601_timestr}#{ANSI_NORMAL} "\
|
87
|
-
"#{level_colour}#{"%5.5s" % level_str}#{ANSI_NORMAL} #{log_msg}")
|
88
|
-
STDOUT.flush()
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/lib/leecher/shellout.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Leecher
|
2
|
-
module Shellout
|
3
|
-
|
4
|
-
# FIXME: probably want to implement timeouts here..
|
5
|
-
def shellout(cmd, stdin = nil, stdout = nil, stderr = nil)
|
6
|
-
child_pid, child_status = nil
|
7
|
-
child_pid = Kernel.fork()
|
8
|
-
|
9
|
-
if child_pid
|
10
|
-
# Parent process executes this
|
11
|
-
child_pid, child_status = Process.waitpid2(child_pid)
|
12
|
-
else
|
13
|
-
Process.setsid()
|
14
|
-
STDIN.reopen(stdin || "/dev/null")
|
15
|
-
STDOUT.reopen(stdout || "/dev/null")
|
16
|
-
STDERR.reopen(stderr || "/dev/null")
|
17
|
-
3.upto(256) { |fd| IO.new(fd).close rescue nil }
|
18
|
-
|
19
|
-
Kernel.exec(cmd)
|
20
|
-
# Never reached.
|
21
|
-
Kernel.exit!
|
22
|
-
end
|
23
|
-
|
24
|
-
child_status
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/spec/shellout_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'leecher/shellout'
|
4
|
-
|
5
|
-
include Leecher::Shellout
|
6
|
-
|
7
|
-
describe Leecher::Shellout do
|
8
|
-
it "should return 0 for true" do
|
9
|
-
shellout("/bin/true").success?.should be_true
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return 1 for false" do
|
13
|
-
shellout("/bin/false").success?.should be_false
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should work with pipes" do
|
17
|
-
stdin_rd, stdin_wr = IO.pipe()
|
18
|
-
stdout_rd, stdout_wr = IO.pipe()
|
19
|
-
stdin_wr.puts("foo")
|
20
|
-
stdin_wr.close()
|
21
|
-
child_status = shellout("cat", stdin_rd, stdout_wr)
|
22
|
-
stdout_wr.close()
|
23
|
-
stdout_rd.gets().should == "foo\n"
|
24
|
-
stdout_rd.close()
|
25
|
-
end
|
26
|
-
end
|