Class: Saber::CLI
Instance Method Summary collapse
- #chd ⇒ Object
- #clean ⇒ Object
- #client ⇒ Object
- #drb_add(ids_str, label = "") ⇒ Object
- #fetch(*names) ⇒ Object
- #find_uploads(page) ⇒ Object
- #generate(type, *files) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #make(*files) ⇒ Object
- #send1(*names) ⇒ Object
- #server ⇒ Object
- #upload(format0, *files) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/saber/cli.rb', line 14 def initialize(*) super self. = self..dup Saber.ui = if ["log"] then require "logger" UI::Logger.new(::Logger.new(["log"])) else the_shell = (["no-color"] ? Thor::Shell::Basic.new : shell) UI::Shell.new(the_shell) end Saber.ui.debug! if ["verbose"] # Initialize environment in first time unless Rc.p.home.exists? Pa.mkdir Rc.p.home Pa.mkdir "#{Rc.p.home}/templates" Pa.mkdir "#{Rc.p.home}/database" end end |
Instance Method Details
#chd ⇒ Object
111 112 113 114 115 |
# File 'lib/saber/cli.rb', line 111 def chd require "saber/task/chd" Task["chd"].invoke(:chd, [], ) end |
#clean ⇒ Object
37 38 39 40 41 |
# File 'lib/saber/cli.rb', line 37 def clean require "saber/task/clean" Task["clean"].invoke(:clean, [], ) end |
#client ⇒ Object
49 50 51 |
# File 'lib/saber/cli.rb', line 49 def client AutoFetcher::Client.start end |
#drb_add(ids_str, label = "") ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/saber/cli.rb', line 54 def drb_add(ids_str, label="") return if label != "saber" require "drb" require "retort" Retort::Service.configure { |c| c.url = Rc.scgi_server } names = ids_str.split(",").map{|v| Retort::Torrent.action("name", v)} AutoFetcher::DRbClient.new.add(*names) end |
#fetch(*names) ⇒ Object
89 90 91 |
# File 'lib/saber/cli.rb', line 89 def fetch(*names) Fetcher.new.add_names(*names) end |
#find_uploads(page) ⇒ Object
118 119 120 121 122 |
# File 'lib/saber/cli.rb', line 118 def find_uploads(page) require "saber/task/find_uploads" Task["find_uploads"].invoke(:find_uploads, [page], ) end |
#generate(type, *files) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/saber/cli.rb', line 79 def generate(type, *files) require "saber/task/generate" files = File.read(["file"]).split(/\n+/).map{|v| v.strip} if ["file"] files = files.map{|v| name, isbn = v.split(":"); [*wrap_file(name), isbn]} Task["generate"].invoke(:generate, [type, *files], ) end |
#make(*files) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/saber/cli.rb', line 103 def make(*files) require "saber/task/make" files = File.read(["file"]).split(/\n+/).map{|v| v.strip.split(":")[0] } if ["file"] Task["make"].invoke(:make, [["tracker"] || ENV["SABER_TRACKER"], *files], ) end |
#send1(*names) ⇒ Object
94 95 96 97 98 |
# File 'lib/saber/cli.rb', line 94 def send1(*names) require "saber/task/send" Task["send"].invoke(:send1, names, ) end |
#server ⇒ Object
44 45 46 |
# File 'lib/saber/cli.rb', line 44 def server AutoFetcher::Server.start end |
#upload(format0, *files) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/saber/cli.rb', line 68 def upload(format0, *files) require "saber/task/upload" format = format0.downcase Saber.ui.error! "Don't support this format -- #{format0}" unless Rc.book_exts.include?(".#{format}") files = files.map{|v| v.dup} # unfrozen string. Task["upload"].invoke(:upload, [["tracker"] || ENV["SABER_TRACKER"], format, *wrap_file(*files)], ) end |