2015-09-06 64 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?

回答