Class: Command::Send

Inherits:
CommandBase show all
Defined in:
lib/command/send.rb

Instance Attribute Summary

Attributes inherited from CommandBase

#stream_io

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBase

#disable_logging, #display_help!, execute!, #execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids

Constructor Details

#initializeSend

Returns a new instance of Send.



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
56
# File 'lib/command/send.rb', line 17

def initialize
  super("[<device>] [<target> ...] [options]")
  @opt.separator "\n  \u30FB<target>\u3067\u6307\u5B9A\u3057\u305F\u5C0F\u8AAC\u306E\u96FB\u5B50\u66F8\u7C4D\u30C7\u30FC\u30BF\u3092<device>\u3067\u6307\u5B9A\u3057\u305F\u7AEF\u672B\u306B\u9001\u4FE1\u3057\u307E\u3059\n  \u30FB<device>\u306B\u306F\u73FE\u5728 \#{Device::DEVICES.keys.join(\", \")} \u304C\u6307\u5B9A\u51FA\u6765\u307E\u3059\n  \u30FBnarou setting device=<device>\u3068\u3057\u3066\u304A\u3051\u3070\u3001<device>\u306E\u5165\u529B\u3092\u7701\u7565\u3067\u304D\u307E\u3059\n\u307E\u305F\u3001convert\u30B3\u30DE\u30F3\u30C9\u3067\u5909\u63DB\u6642\u306B(\u7AEF\u672B\u304CPC\u306B\u63A5\u7D9A\u3055\u308C\u3066\u3044\u308C\u3070)\u81EA\u52D5\u3067\u30C7\u30FC\u30BF\u3092\u9001\u4FE1\u3059\u308B\u3088\u3046\u306B\u306A\u308A\u307E\u3059\n  \u30FB\u9001\u4FE1\u6642\u306F\u30D5\u30A1\u30A4\u30EB\u306E\u30BF\u30A4\u30E0\u30B9\u30BF\u30F3\u30D7\u3092\u7AEF\u672B\u306E\u3082\u306E\u3068\u6BD4\u3079\u3066\u65B0\u3057\u3051\u308C\u3070\u9001\u4FE1\u3057\u307E\u3059\n  \u30FB<target>\u3092\u7701\u7565\u3057\u305F\u5834\u5408\u3001\u7BA1\u7406\u3057\u3066\u3044\u308B\u5C0F\u8AAC\u5168\u3066\u304C\u9001\u4FE1\u5BFE\u8C61\u306B\u306A\u308A\u307E\u3059\n  \u30FB<target>\u306Bhotentry\u3092\u6307\u5B9A\u3057\u305F\u5834\u5408\u3001\u6700\u65B0\u306Ehotnetry\u3092\u9001\u4FE1\u3057\u307E\u3059\n\n  Examples:\nnarou send kindle 6\nnarou send kobo 6\n\n# <device>\u306E\u7701\u7565\nnarou setting device=kindle\nnarou send 6\n\nnarou send      # \u7AEF\u672B\u306E\u30D5\u30A1\u30A4\u30EB\u3088\u308A\u65B0\u3057\u3044\u30D5\u30A1\u30A4\u30EB\u304C\u3042\u308C\u3070\u9001\u4FE1\nnarou send --without-freeze   # \u51CD\u7D50\u6E08\u306F\u5BFE\u8C61\u5916\u306B\nnarou s send.without-freeze=true   # \u5E38\u306B\u51CD\u7D50\u6E08\u307F\u3092\u5BFE\u8C61\u5916\u306B\u8A2D\u5B9A\n\n  Options:\n  EOS\n\n  @opt.on(\"-w\", \"--without-freeze\", \"\u9001\u4FE1\u6642\u306B\u51CD\u7D50\u3055\u308C\u305F\u5C0F\u8AAC\u306F\u5BFE\u8C61\u5916\u306B\u3059\u308B\") {\n    @options[\"without-freeze\"] = true\n  }\n  @opt.on(\"-f\", \"--force\", \"\u30BF\u30A4\u30E0\u30B9\u30BF\u30F3\u30D7\u3092\u6BD4\u8F03\u305B\u305A\u306B\u5FC5\u305A\u9001\u4FE1\u3059\u308B\") {\n    @options[\"force\"] = true\n  }\n  @opt.on(\"-b\", \"--backup-bookmark\", \"\u7AEF\u672B\u306E\u681E\u30C7\u30FC\u30BF\u3092\u624B\u52D5\u3067\u30D0\u30C3\u30AF\u30A2\u30C3\u30D7\u3059\u308B(KindlePW\u7CFB\u7528)\") {\n    @options[\"command-backup-bookmark\"] = true\n  }\n  @opt.on(\"-r\", \"--restore-bookmark\", \"\u681E\u30C7\u30FC\u30BF\u306E\u30D0\u30C3\u30AF\u30A2\u30C3\u30D7\u3092\u7AEF\u672B\u306B\u30B3\u30D4\u30FC\u3059\u308B(KindlePW\u7CFB\u7528)\") {\n    @options[\"command-restore-bookmark\"] = true\n  }\nend\n"

Class Method Details

.oneline_helpObject



13
14
15
# File 'lib/command/send.rb', line 13

def self.oneline_help
  "変換したEPUB/MOBIを電子書籍端末に送信します"
end

Instance Method Details

#execute(argv) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/command/send.rb', line 65

def execute(argv)
  super
  device = get_device(argv)
  unless device
    stream_io.error "      \u30C7\u30D0\u30A4\u30B9\u540D\u304C\u6307\u5B9A\u3055\u308C\u3066\u3044\u306A\u3044\u304B\u3001\u9593\u9055\u3063\u3066\u3044\u307E\u3059\u3002\n      narou setting device=\u30C7\u30D0\u30A4\u30B9\u540D \u3067\u6307\u5B9A\u51FA\u6765\u307E\u3059\u3002\n      \u6307\u5B9A\u51FA\u6765\u308B\u30C7\u30D0\u30A4\u30B9\u540D\uFF1A\#{Device::DEVICES.keys.join(\", \")}\n    ERR\n    exit Narou::EXIT_ERROR_CODE\n  end\n  unless device.physical_support?\n    stream_io.error \"\#{device.display_name} \u3078\u306E\u76F4\u63A5\u9001\u4FE1\u306F\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093\"\n    exit Narou::EXIT_ERROR_CODE\n  end\n  unless device.connecting?\n    stream_io.error \"\#{device.display_name} \u304C\u63A5\u7D9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\"\n    exit Narou::EXIT_ERROR_CODE\n  end\n\n  @options[\"hotentry\"] = Inventory.load(\"local_setting\")[\"hotentry\"]\n  send_all = false\n  titles = {}\n  if argv.empty?\n    send_all = true\n    Database.instance.each do |id, data|\n      argv << id\n      titles[id] = data[\"title\"]\n    end\n    if @options[\"hotentry\"]\n      argv << \"hotentry\"\n      titles[\"hotentry\"] = \"hotentry\"\n    end\n  end\n\n  case\n  when @options[\"command-backup-bookmark\"]\n    process_backup_bookmark(device)\n    exit\n  when @options[\"command-restore-bookmark\"]\n    process_restore_bookmark(device)\n    exit\n  end\n\n  tagname_to_ids(argv)\n  argv.each do |target|\n    # WEB UI \u4F7F\u7528\u6642\u306F\u3001send.without-freeze \u3092\u8A2D\u5B9A\u3057\u3066\u4F7F\u3046\u3053\u3068\u3092\u60F3\u5B9A\u3057\u3066\u3044\u3066\u3001\n    # \u30B3\u30DE\u30F3\u30C9\u306E\u3088\u3046\u306B\u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u4ED8\u3051\u305F\u308A\u5916\u3057\u305F\u308A\u3059\u308B\u306E\u304C\u5BB9\u6613\u3067\u306F\u306A\u3044\u305F\u3081\u3001\n    # \u500B\u5225\u9001\u4FE1\u6642\u306F\u30AA\u30D7\u30B7\u30E7\u30F3\u306B\u95A2\u308F\u3089\u305A\u51CD\u7D50\u6E08\u307F\u3067\u3082\u9001\u4FE1\u51FA\u6765\u308B\u3088\u3046\u306B\u3059\u308B\n    if @options[\"without-freeze\"] && Narou.novel_frozen?(target) &&\n       (!Narou.web? || (Narou.web? && send_all))\n      next\n    end\n    if target == \"hotentry\"\n      ebook_paths = [Update.get_newest_hotentry_file_path(device)]\n    else\n      ebook_paths = Narou.get_ebook_file_paths(target, device.ebook_file_ext)\n    end\n    unless ebook_paths[0]\n      stream_io.error \"\#{target} \u306F\u5B58\u5728\u3057\u307E\u305B\u3093\"\n      next\n    end\n    unless File.exist?(ebook_paths[0])\n      stream_io.error \"\u307E\u3060\u30D5\u30A1\u30A4\u30EB(\#{File.basename(ebook_paths[0])})\u304C\u7121\u3044\u3088\u3046\u3067\u3059\" unless send_all\n      next\n    end\n\n    # TODO: should check all items in ebook_paths\n    if !@options[\"force\"] && !device.ebook_file_old?(ebook_paths[0])\n      next\n    end\n    display_target =\n      if target == \"hotentry\"\n        target\n      else\n        \"ID:\#{target}\u3000\#{TermColorLight.escape(titles[target])}\"\n      end\n    stream_io.puts \"<bold><green>\#{display_target}</green></bold>\".termcolor\n\n    stream_io.print \"\#{device.name}\u3078\u9001\u4FE1\u3057\u3066\u3044\u307E\u3059\"\n    ebook_paths.each do |ebook_path|\n      exit_copy = false\n      copy_to_path = nil\n      Thread.abort_on_exception = true\n      Thread.new do\n        copy_to_path = device.copy_to_documents(ebook_path)\n        exit_copy = true\n      end\n      until exit_copy\n        stream_io.print \".\"\n        sleep(0.5)\n      end\n      stream_io.puts\n      if copy_to_path\n        stream_io.puts copy_to_path + \" \u3078\u30B3\u30D4\u30FC\u3057\u307E\u3057\u305F\"\n      else\n        stream_io.error \"\#{device.name}\u304C\u898B\u3064\u304B\u3089\u306A\u304B\u3063\u305F\u305F\u3081\u30B3\u30D4\u30FC\u51FA\u6765\u307E\u305B\u3093\u3067\u3057\u305F\"\n        exit Narou::EXIT_ERROR_CODE # next \u3057\u3066\u3082\u6B21\u3082\u5931\u6557\u3059\u308B\u3068\u5206\u304B\u308A\u304D\u3063\u3066\u3044\u308B\u305F\u3081\u3053\u3053\u3067\u7D42\u4E86\u3059\u308B\n      end\n    end\n  end\n  if send_all && @options[\"backup-bookmark\"]\n    process_backup_bookmark(device)\n  end\nrescue Device::SendFailure, Interrupt\n  stream_io.puts \"\u9001\u4FE1\u3092\u4E2D\u65AD\u3057\u307E\u3057\u305F\"\n  exit Narou::EXIT_INTERRUPT\nend\n"

#get_device(argv) ⇒ Object



58
59
60
61
62
63
# File 'lib/command/send.rb', line 58

def get_device(argv)
  if argv.first && Device.exists?(argv.first)
    return Narou.get_device(argv.shift)
  end
  Narou.get_device
end

#process_backup_bookmark(device) ⇒ Object



174
175
176
177
178
179
180
181
182
183
# File 'lib/command/send.rb', line 174

def process_backup_bookmark(device)
  device.extend(device.get_hook_module)
  unless device.respond_to?(:backup_bookmark)
    stream_io.error "ご利用の端末での栞データのバックアップは対応していません"
    return
  end
  if device.backup_bookmark > 0
    stream_io.puts "端末の栞データをバックアップしました"
  end
end

#process_restore_bookmark(device) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/command/send.rb', line 185

def process_restore_bookmark(device)
  device.extend(device.get_hook_module)
  unless device.respond_to?(:restore_bookmark)
    stream_io.error "ご利用の端末での栞データのバックアップは対応していません"
    return
  end
  if device.restore_bookmark > 0
    stream_io.puts "栞データを端末にコピーしました"
  else
    stream_io.puts "栞データが無いようです"
  end
end