2015-09-06 33 views
0

我正在通過Avdi Grimm的耙系列教程系列,我卡在Part 6。該調用Pandoc做工精細的任務,但口徑的ebook-convert命令返回一個狀態127:Calibre電子書轉換命令未找到

[email protected] rake_basics (master) $ rake 
pandoc -o ch1.html ch1.md 
pandoc -o ch2.html ch2.md 
pandoc -o ch3.html ch3.md 
pandoc -o subdir/appendix.html subdir/appendix.md 
pandoc -o ch4.html ch4.markdown 
cat ch1.html ch2.html ch3.html ch4.html > book.html 
ebook-convert book.html book.epub 
rake aborted! 
Command failed with status (127): [ebook-convert book.html book.epub...] 
/Users/andrekibbe/code/rake_basics/Rakefile:27:in `block in <top (required)>' 
/Users/andrekibbe/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval' 
/Users/andrekibbe/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>' 
Tasks: TOP => default => book.epub 

ebook-convert是在我的應用程序目錄的路徑:/Applications/calibre.app/Contents/MacOS/calibre,而我的Rake文件是/Users/andrekibbe/code/rake_basics

require "rake/clean" 

SOURCE_FILES = Rake::FileList.new("**/*.md", "**/*.markdown") do |fl| 
    fl.exclude("~*") 
    fl.exclude(/^scratch\//) 
    fl.exclude do |f| 
    `git ls-files #{f}`.empty? 
    end 
end 
CLEAN.include(SOURCE_FILES.ext(".html")) 

task default: ["book.epub", "book.mobi"] 
task html: SOURCE_FILES.ext(".html") 

rule ".html" => ->(f){source_for_html(f)} do |t| 
    sh "pandoc -o #{t.name} #{t.source}" 
end 

file "book.html" => SOURCE_FILES.ext(".html") do |t| 
    chapters = FileList["**/ch*.html"] 
    backmatter = FileList["backmatter/*.html"] 
    sh "cat #{chapters} #{backmatter} > #{t.name}" 
end 
CLEAN.include("book.html") 

file "book.epub" => "book.html" do |t| 
    sh "ebook-convert book.html #{t.name}" 
end 
CLOBBER.include("book.epub") 

file "book.mobi" => "book.epub" do |t| 
    sh "kindlegen book.epub -o #{t.name}" 
end 
CLOBBER.include("book.mobi") 

def source_for_html(html_file) 
    SOURCE_FILES.detect{|f| f.ext('') == html_file.ext('')} 
end 

有沒有辦法在Rakefile中需要Calibre工具,比如gem,還是使用絕對路徑或符號鏈接?我不認爲這是必要的,因爲在Avdi的代碼中沒有這樣的東西。或者我需要在其他地方安裝Calibre?

回答