Module: Narou

Extended by:
Memoist
Defined in:
lib/web/settingmessages.rb,
lib/input.rb,
lib/narou.rb,
lib/logger.rb,
lib/narou/api.rb,
lib/web/pushserver.rb,
lib/web/streaminginput.rb

Overview

Copyright 2013 whiteleaf. All rights reserved.

Defined Under Namespace

Modules: Eventable, Input, LoggerModule, ServerHelpers Classes: API, AppServer, Logger, LoggerError, PushServer, StreamingLogger, Worker

Constant Summary collapse

LOCAL_SETTING_DIR =
".narou"
GLOBAL_SETTING_DIR =
".narousetting"
AOZORAEPUB3_JAR_NAME =
"AozoraEpub3.jar"
AOZORAEPUB3_DIR =
"AozoraEpub3"
PRESET_DIR =
"preset"
MISC_DIR =
"misc"
EXIT_ERROR_CODE =
127
SETTING_VARIABLES_WEBUI_MESSAGES =

WEB UI > 環境設定画面で表示する各項目の説明 ここになければ元々の説明が表示される

{
  "convert.multi-device" => "複数の端末用に同時に変換する。deviceよりも優先される。\n端末名をカンマ区切りで入力(" + Device::DEVICES.keys.join(", ") + ")\nただのEPUBを出力したい場合はepubを指定",
  "device" => "変換、送信対象の端末(" + Device::DEVICES.keys.join(", ") + ")",
  "difftool" => "Diffで使うツールのパスを指定する\n※WEB UIでは使われません"
}
@@is_web =
false

Class Method Summary collapse

Class Method Details

.alias_to_id(target) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/narou.rb', line 83

def alias_to_id(target)
  aliases = Inventory.load("alias", :local)
  if aliases[target]
    return aliases[target]
  end
  target
end

.already_init?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/narou.rb', line 72

def already_init?
  !!get_root_dir
end

.aozoraepub3_directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/narou.rb', line 105

def aozoraepub3_directory?(path)
  File.exist?(create_aozoraepub3_jar_path(path))
end

.create_aozoraepub3_jar_path(*paths) ⇒ Object



101
102
103
# File 'lib/narou.rb', line 101

def create_aozoraepub3_jar_path(*paths)
  File.expand_path(File.join(*paths, AOZORAEPUB3_JAR_NAME))
end

.create_novel_filename(novel_data, ext = "") ⇒ Object



134
135
136
137
138
139
# File 'lib/narou.rb', line 134

def create_novel_filename(novel_data, ext = "")
  author, title = %w(author title).map { |k|
    Helper.replace_filename_special_chars(novel_data[k], true)
  }
  "[#{author}] #{title}#{ext}"
end

.get_aozoraepub3_pathObject

AozoraEpub3 の実行ファイル(.jar)のフルパス取得 検索順序

  1. グローバルセッティング (global_setting aozoraepub3dir)

  2. 小説保存ディレクトリ(Narou.get_root_dir) 直下の AozoraEpub3

  3. スクリプト保存ディレクトリ(Narou.get_script_dir) 直下の AozoraEpub3



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/narou.rb', line 116

def get_aozoraepub3_path
  global_setting_aozora_path = Inventory.load("global_setting", :global)["aozoraepub3dir"]
  if global_setting_aozora_path
    aozora_jar_path = create_aozoraepub3_jar_path(global_setting_aozora_path)
    if File.exist?(aozora_jar_path)
      return aozora_jar_path
    end
  end
  [Narou.get_root_dir, Narou.get_script_dir].each do |dir|
    aozora_jar_path = create_aozoraepub3_jar_path(dir, AOZORAEPUB3_DIR)
    if File.exist?(aozora_jar_path)
      return aozora_jar_path
    end
  end
  nil
end

.get_device(device_name = nil) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/narou.rb', line 159

def get_device(device_name = nil)
  device_name = Inventory.load("local_setting", :local)["device"] unless device_name
  if device_name && Device.exists?(device_name)
    return Device.create(device_name)
  end
  nil
end

.get_ebook_file_path(target, ext) ⇒ Object



145
146
147
148
149
150
# File 'lib/narou.rb', line 145

def get_ebook_file_path(target, ext)
  data = Downloader.get_data_by_target(target)
  return nil unless data
  dir = Downloader.get_novel_data_dir_by_target(target)
  File.join(dir, create_novel_filename(data, ext))
end

.get_global_setting_dirObject



58
59
60
61
62
63
64
# File 'lib/narou.rb', line 58

def get_global_setting_dir
  global_setting_dir = File.expand_path(File.join("~", GLOBAL_SETTING_DIR))
  unless File.exist?(global_setting_dir)
    FileUtils.mkdir(global_setting_dir)
  end
  global_setting_dir
end

.get_local_setting_dirObject



48
49
50
51
52
53
54
55
# File 'lib/narou.rb', line 48

def get_local_setting_dir
  local_setting_dir = nil
  root_dir = get_root_dir
  if root_dir
    local_setting_dir = File.join(root_dir, LOCAL_SETTING_DIR)
  end
  local_setting_dir
end

.get_misc_dirObject



152
153
154
# File 'lib/narou.rb', line 152

def get_misc_dir
  File.join(get_root_dir, MISC_DIR)
end

.get_mobi_path(target) ⇒ Object



141
142
143
# File 'lib/narou.rb', line 141

def get_mobi_path(target)
  get_ebook_file_path(target, ".mobi")
end

.get_preset_dirObject



96
97
98
# File 'lib/narou.rb', line 96

def get_preset_dir
  File.expand_path(File.join(get_script_dir, PRESET_DIR))
end

.get_root_dirObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/narou.rb', line 29

def get_root_dir
  root_dir = nil
  path = File.expand_path(File.dirname("."))
  drive_letter = ""
  if Helper.os_windows?
    path.gsub!(/^[a-z]:/i, "")
    drive_letter = $&
  end
  while path != ""
    if File.directory?("#{drive_letter}#{path}/#{LOCAL_SETTING_DIR}")
      root_dir = drive_letter + path
      break
    end
    path.gsub!(%r!/[^/]*$!, "")
  end
  root_dir
end

.get_script_dirObject



67
68
69
# File 'lib/narou.rb', line 67

def get_script_dir
  File.expand_path(File.join(File.dirname(__FILE__), ".."))
end

.initObject



76
77
78
79
80
81
# File 'lib/narou.rb', line 76

def init
  return nil if already_init?
  FileUtils.mkdir(LOCAL_SETTING_DIR)
  puts LOCAL_SETTING_DIR + "/ を作成しました"
  Database.init
end

.novel_frozen?(target) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
# File 'lib/narou.rb', line 91

def novel_frozen?(target)
  id = Downloader.get_id_by_target(target) or return false
  Inventory.load("freeze", :local).include?(id)
end

.web=(bool) ⇒ Object



167
168
169
# File 'lib/narou.rb', line 167

def web=(bool)
  @@is_web = bool
end

.web?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/narou.rb', line 171

def web?
  @@is_web
end