Sha256: e06c25fb7514ffdc14cf4f903638a9d015d5fd2978739cfbd95a3cb40d8a04e2

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

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

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

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

          system "mktorrent -p -a #{Rc[tracker_name].announce_url} #{file.shellescape} #{options['option']}", show_cmd: true

          # 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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saber-1.2.3 lib/saber/task/make.rb
saber-1.2.2 lib/saber/task/make.rb
saber-1.2.1 lib/saber/task/make.rb
saber-1.2.0 lib/saber/task/make.rb