sinatra-torrent 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -44,7 +44,7 @@ If a torrent takes longer than 1 second to generate on-the-fly, it'll be added t
44
44
 
45
45
  # This line is optional, 'downloads' is the default
46
46
  # If you've used `set :download_directory, 'files'` in your sinatra app, you need to do:
47
- Sinatra::Torrent::DOWNLOAD_DIRECTORY = 'files'
47
+ Sinatra::Torrent.downloads_directory = 'files'
48
48
 
49
49
  # The rest of your Rakefile
50
50
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -14,7 +14,7 @@ module Sinatra
14
14
  # Putting the annouce URL of a tracker in here will use that tracker rather than the inbuilt one
15
15
  app.set :external_tracker, nil
16
16
  # Directory which holds all the files which will be provided as torrents
17
- app.set :downloads_directory, File.join(File.dirname(__FILE__),Sinatra::Torrent::DOWNLOADS_DIRECTORY)
17
+ app.set :downloads_directory, File.join(File.dirname(__FILE__),Sinatra::Torrent.downloads_directory)
18
18
  # Mount point for the downloads directory
19
19
  app.set :downloads_mount, 'downloads'
20
20
  # Mount point for the torrents directory
@@ -39,14 +39,14 @@ module Sinatra
39
39
  filename = File.join(options.downloads_directory, rel_location)
40
40
  halt(404, "That file doesn't exist! #{filename}") unless File.exists?(filename)
41
41
 
42
- if !(d = options.database_adapter.torrent_by_path_and_timestamp(filename,File.mtime(filename)))
43
-
42
+ if !(d = options.database_adapter.torrent_by_path_and_timestamp(rel_location,File.mtime(filename)))
43
+ p d
44
44
  begin
45
45
  Timeout::timeout(1) do
46
46
  d = Sinatra::Torrent.create(filename)
47
47
  end
48
48
  rescue Timeout::Error
49
- eta = options.database_adapter.add_hashjob(filename)
49
+ eta = options.database_adapter.add_hashjob(rel_location)
50
50
 
51
51
  begin
52
52
  wait = case (eta/60).floor
@@ -64,7 +64,7 @@ module Sinatra
64
64
  halt(503,"This torrent is taking too long to build, we're running it in the background. Please try again in #{wait}.")
65
65
  end
66
66
 
67
- options.database_adapter.store_torrent(filename,File.mtime(filename),d['metadata'],d['infohash'])
67
+ options.database_adapter.store_torrent(rel_location,File.mtime(filename),d['metadata'],d['infohash'])
68
68
  end
69
69
 
70
70
  # These are options which could change between database retrievals
@@ -9,7 +9,7 @@ namespace :hash do
9
9
 
10
10
  task :add do
11
11
  ARGV[1..-1].each do |rel_location|
12
- if (File.exists?(File.join(Sinatra::Torrent::DOWNLOADS_DIRECTORY,rel_location)))
12
+ if (File.exists?(File.join(Sinatra::Torrent.downloads_directory,rel_location)))
13
13
  torrent_db.add_hashjob(rel_location)
14
14
  $stdout.puts "added to queue: #{rel_location}"
15
15
  else
@@ -22,13 +22,13 @@ namespace :hash do
22
22
  completed = 0
23
23
  failed = 0
24
24
 
25
- Dir[File.join(Sinatra::Torrent::DOWNLOADS_DIRECTORY,'**')].each do |filename|
26
- rel_location = filename[Sinatra::Torrent::DOWNLOADS_DIRECTORY.length+1..-1]
25
+ Dir[File.join(Sinatra::Torrent.downloads_directory,'**')].each do |filename|
26
+ rel_location = filename[Sinatra::Torrent.downloads_directory.length+1..-1]
27
27
 
28
28
  begin
29
29
  if !torrent_db.torrent_by_path_and_timestamp(rel_location,File.mtime(filename))
30
30
  d = Sinatra::Torrent.create(filename)
31
-
31
+
32
32
  torrent_db.store_torrent(rel_location,File.mtime(filename),d['metadata'],d['infohash'])
33
33
 
34
34
  torrent_db.remove_hashjob(rel_location)
@@ -53,7 +53,7 @@ namespace :hash do
53
53
  failed = 0
54
54
 
55
55
  torrent_db.list_hashjobs.each do |rel_location|
56
- filename = File.join(Sinatra::Torrent::DOWNLOADS_DIRECTORY,rel_location)
56
+ filename = File.join(Sinatra::Torrent.downloads_directory,rel_location)
57
57
  begin
58
58
  if torrent_db.torrent_by_path_and_timestamp(rel_location,File.mtime(filename))
59
59
  torrent_db.remove_hashjob(rel_location)
@@ -4,7 +4,20 @@ require 'bencode'
4
4
 
5
5
  module Sinatra
6
6
  module Torrent
7
- DOWNLOADS_DIRECTORY = 'downloads'
7
+ @@downloads_directory = 'downloads'
8
+
9
+ def self.downloads_directory=(d)
10
+ if File.directory?(d)
11
+ @@downloads_directory = d
12
+ else
13
+ # TODO: ERR error
14
+ raise RuntimeError, "The downloads directory doesn't exist"
15
+ end
16
+ end
17
+
18
+ def self.downloads_directory
19
+ @@downloads_directory
20
+ end
8
21
 
9
22
  def self.create(filename)
10
23
  d = {
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-torrent}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["JP Hastings-Spital"]
12
- s.date = %q{2011-02-09}
12
+ s.date = %q{2011-02-10}
13
13
  s.description = %q{An extension to Sinatra which will allow you to run a webseeded torrent tracker of files in the folder you specify.}
14
14
  s.email = %q{jphastings@gmail.com}
15
15
  s.files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-torrent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - JP Hastings-Spital
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-09 00:00:00 +00:00
18
+ date: 2011-02-10 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency