Sha256: c3a484bedfe7acb38496b74c9c5d97b654dc293ecffc75c31aa7ee40ad427846
Contents?: true
Size: 1.07 KB
Versions: 2
Compression:
Stored size: 1.07 KB
Contents
require "xmlrpc/client" require "net/ssh" module Saber class Downloader def initialize @aria2 = XMLRPC::Client.new2(Rc.aria2.rpc) end def aria2_add(uris, o={}, &blk) @aria2.call("aria2.addUri", uris, o, &blk) end def add(*files) files.each { |file| uri = "#{Rc.server.ftp}/#{file}" $log.debug "::add_url:: #{uri}" gid = aria2_add([uri], :dir => Pa.dir2("#{Rc.p.download}/#{file}")) Saber.ui.say "DOWNLOAD #{gid}:: #{uri}" } end def add_names(*names) files = retrive_files(*names) add(*files) end private def retrive_files(*names) files = [] Net::SSH.start(Rc.server.host, Rc.server.user) do |s| name = "'#{names.join("' '")}'" cmd = "cd #{Rc.server.download.p} && find #{name} -type f" rst = s.exec!(cmd) if rst =~ /^find: `|^cd:cd:/ raise Error, rst elsif rst.nil? raise Error, "remote `#{name}' is an empty directory." end files = rst.split("\n") end files end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
saber-0.0.6 | lib/saber/downloader.rb |
saber-0.0.4 | lib/saber/downloader.rb |