Class: Saber::Task::Upload

Inherits:
Base
  • Object
show all
Defined in:
lib/saber/task/upload.rb

Overview

Usage

Task["upload"].invoke(:upload, ["site", "Hello.epub"])

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize, invoke

Constructor Details

This class inherits a constructor from Saber::Task::Base

Instance Method Details

#upload(tracker_name, format, *files) ⇒ Object

Parameters:

  • tracker_name (String)
  • file (String)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/saber/task/upload.rb', line 11

def upload(tracker_name, format, *files)
  filemap = {}    # {file => torrent_file}

  files.each{|file|
    torrent_file = [
      "#{file}.#{format}.torrent", 
      "#{tracker_name}/#{file}.#{format}.torrent", 
      "#{file}.torrent", 
      "#{tracker_name}/#{file}.torrent"
    ].find {|v| Pa.exists?(v)}

    torrent_file ||= Pa.directory?(file) ? "#{file}.torrent" : "#{file}.#{format}.torrent"
    filemap[file] = torrent_file
  }

  # make torrent if torrent_file not exists.
  filemap.each { |file, torrent_file|
    if not Pa.exists?(torrent_file)

      if not Pa.exists?(file)
        Saber.ui.error "SKIP: Can't find torrent_file nor file -- #{file}" 
        filemap.delete(file)
        next
      end

      Saber.ui.say "Can't find torrent_file, begin to make it. -- #{torrent_file}"
      Task["make"].invoke(:make, [tracker_name, file])
    end
  }

  tracker = Tracker2[tracker_name].new(options)
  #tracker.login
  tracker.upload(format, filemap, {add: options["add"]})
end