Class: Saber::Task::Make

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

Overview

Usage


Task["make"].invoke(:make, ["bib", "a.epub", "b.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

#make(tracker_name, *files) ⇒ Object



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
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/saber/task/make.rb', line 14

def make(tracker_name, *files)
  Saber.ui.error! "You need set #{tracker_name}.announce_url in ~/.saberrc first" unless 
    Rc._has_key?("#{tracker_name}.announce_url")

  files.each { |file|
    torrent_file = "#{file}.torrent"

    if Pa.exists?(torrent_file) 
      if options["force"]
        Pa.rm torrent_file
      else
        Saber.ui.say "SKIP make: #{torrent_file} (torrent alreay exists. use --force to overwrite it.)"
        next
      end
    end

    if not Pa.exists?(file)
      Saber.ui.error "SKIP: can't find file to make -- #{file}"
      next
    end

    extra_options = Rc._fetch(["#{tracker_name}.mktorrent_options", "mktorrent_options"], "")
    cmd = "mktorrent -p #{extra_options} -a #{Rc[tracker_name].announce_url} #{file.shellescape} #{options['option']}"
    system cmd, show_cmd: "$"

    # cp tororent file
    if Rc._has_key?("make.watch")
      Pa.cp_f torrent_file, Rc.make.watch, show_cmd: "$"
    end

    if Rc._has_key?("make.remote_watch")
      Task["send"].invoke(:send1, [torrent_file, Rc.make.remote_watch]) 
    end

    # move torrent file
    if Rc._has_key?("make.dir")
      Pa.mv_f torrent_file, Rc.make.dir, show_cmd: "$"
    end

    Saber.ui.say ""
  }
end