Sha256: 1fb662d980fb6da9cc3747f3451802df1ad835beaccbacc0c1fc2db80e1068a2

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

require "shellwords"
require "tagen/core/kernel/shell"

module Saber
  module Task
    #
    # Usage
    # -----
    #
    #    Task["make"].invoke(:make, ["bib", "a.epub", "b.epub"])
    #    > create a.epub.torrent and send it to local and remote watch directory.
    #    > create b.epub.torrent ..
    #
    class Make < Base
      desc "make", "make"
      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: #{file} (torrent alreay exists. use -f to overwrite it.)"
              next
            end
          end

          system "mktorrent -p -a #{Rc[tracker_name].announce_url} #{file.shellescape}", show_cmd: true
          # cp tororent file to watch directory.
          Pa.cp_f torrent_file, Rc.p.watch, show_cmd: true if Rc.p._has_key?(:watch) 
          if Rc.p._has_key?(:remote_watch)
            require "saber/task/send"
            Task["send"].invoke(:send, [torrent_file, Rc.p.remote_watch]) 
          end
          Saber.ui.say ""
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
saber-1.1.1 lib/saber/task/make.rb
saber-1.1.0 lib/saber/task/make.rb
saber-1.0.2 lib/saber/task/make.rb
saber-1.0.1 lib/saber/task/make.rb
saber-1.0.0 lib/saber/task/make.rb