Structures output of the scores
This commit is contained in:
parent
f84ff44d47
commit
66fa2fd436
@ -46,14 +46,9 @@ func CompileDir(path string, opts *settings.Settings) {
|
|||||||
)
|
)
|
||||||
switch filepath.Ext(scores[i].Path) {
|
switch filepath.Ext(scores[i].Path) {
|
||||||
case ".ly":
|
case ".ly":
|
||||||
msg, err = Lilypond(scores[i].Path)
|
msg, err = Lilypond(&scores[i])
|
||||||
case ".pdf":
|
case ".pdf":
|
||||||
if helpers.Exists(scores[i].OutputPath) {
|
err = linkPDF(&scores[i])
|
||||||
os.Remove(scores[i].OutputPath)
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
err = os.Link(scores[i].Path, scores[i].OutputPath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,3 +103,15 @@ func generateScores() func(string, os.FileInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func linkPDF(s *settings.Score) (err error) {
|
||||||
|
err = helpers.ExistsOrCreate(filepath.Dir(s.OutputPath))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if helpers.Exists(s.OutputPath) {
|
||||||
|
os.Remove(s.OutputPath)
|
||||||
|
}
|
||||||
|
err = os.Link(s.Path, s.OutputPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/jjdekker/ponder/helpers"
|
"github.com/jjdekker/ponder/helpers"
|
||||||
@ -37,21 +37,21 @@ func PrepareLilypond(opts *settings.Settings) {
|
|||||||
}
|
}
|
||||||
lilypondArgs = append(lilypondArgs, "--loglevel=ERROR")
|
lilypondArgs = append(lilypondArgs, "--loglevel=ERROR")
|
||||||
lilypondArgs = append(lilypondArgs, "--pdf")
|
lilypondArgs = append(lilypondArgs, "--pdf")
|
||||||
|
|
||||||
lilypondArgs = append(lilypondArgs, "--output="+opts.OutputDir)
|
|
||||||
if !helpers.Exists(opts.OutputDir) {
|
|
||||||
log.WithFields(log.Fields{"path": opts.OutputDir}).Info("creating output directory")
|
|
||||||
err := os.MkdirAll(opts.OutputDir, os.ModePerm)
|
|
||||||
helpers.Check(err, "Could not create output directory")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lilypond runs the lilypond compiler on the given path
|
// Lilypond runs the lilypond compiler on the given path
|
||||||
// using the arguments prepared by the PrepareLilypond function
|
// using the arguments prepared by the PrepareLilypond function
|
||||||
func Lilypond(path string) (string, error) {
|
func Lilypond(s *settings.Score) (string, error) {
|
||||||
cmd := exec.Command(lilypondCmd, append(lilypondArgs, path)...)
|
args := append(lilypondArgs, "--output="+filepath.Dir(s.OutputPath))
|
||||||
|
err := helpers.ExistsOrCreate(filepath.Dir(s.OutputPath))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
args = append(args, s.Path)
|
||||||
|
|
||||||
|
cmd := exec.Command(lilypondCmd, args...)
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"path": path,
|
"path": s.Path,
|
||||||
"cmd": cmd,
|
"cmd": cmd,
|
||||||
}).Info("compiling file using lilypond")
|
}).Info("compiling file using lilypond")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
@ -55,6 +55,15 @@ func Exists(path string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExistsOrCreate will create a directory unless it already Exists
|
||||||
|
func ExistsOrCreate(path string) (err error) {
|
||||||
|
if !Exists(path) {
|
||||||
|
log.WithFields(log.Fields{"path": path}).Info("creating directory")
|
||||||
|
err = os.MkdirAll(path, os.ModePerm)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// LastModified returns the time the file on the path was last modified,
|
// LastModified returns the time the file on the path was last modified,
|
||||||
// if file lookup fails the current time is returned.
|
// if file lookup fails the current time is returned.
|
||||||
func LastModified(path string) time.Time {
|
func LastModified(path string) time.Time {
|
||||||
|
@ -141,7 +141,11 @@ func (s *Score) GenerateOutputPath(opts *Settings) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
file = file[:dot+1] + "pdf"
|
file = file[:dot+1] + "pdf"
|
||||||
s.OutputPath = filepath.Join(opts.OutputDir, file)
|
s.OutputPath = opts.OutputDir
|
||||||
|
if !opts.FlatOutputDir && len(s.Categories) > 0 {
|
||||||
|
s.OutputPath = filepath.Join(s.OutputPath, s.Categories[0])
|
||||||
|
}
|
||||||
|
s.OutputPath = filepath.Join(s.OutputPath, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scores aliases a slice of scores
|
// Scores aliases a slice of scores
|
||||||
|
@ -38,6 +38,7 @@ type Settings struct {
|
|||||||
BookScoreTempl string // Override for the partial book template placing scores
|
BookScoreTempl string // Override for the partial book template placing scores
|
||||||
LatexResources []string // Files to be copied to compile the book template
|
LatexResources []string // Files to be copied to compile the book template
|
||||||
KeepBookTemplate bool // Leave the LaTeX source for the book in the output directory
|
KeepBookTemplate bool // Leave the LaTeX source for the book in the output directory
|
||||||
|
FlatOutputDir bool // Keep all output file in a flat output directory
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromFile reads a settings file in json format and returns the Settings struct
|
// FromFile reads a settings file in json format and returns the Settings struct
|
||||||
|
Reference in New Issue
Block a user