|
@@ -40,45 +40,47 @@ type DepartmentGenerator struct {
|
|
|
logger *logger.JobLogger
|
|
|
}
|
|
|
|
|
|
-func (generator *DepartmentGenerator) generate(outputPath string, cloudPath string, funcMap template.FuncMap) {
|
|
|
+func (generator *DepartmentGenerator) generate(outputPath string, cloudPath string, funcMap template.FuncMap) ([]*orm.File, error) {
|
|
|
+ var files []*orm.File
|
|
|
+
|
|
|
tplFilename := filepath.Join(cloudPath, "template.md")
|
|
|
log.Printf("Downloading %s from the cloud...", tplFilename)
|
|
|
|
|
|
tplContent, err := generator.ncClient.Download(tplFilename)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
log.Println("Download completed.")
|
|
|
|
|
|
refFilename := filepath.Join(cloudPath, "reference.odt")
|
|
|
- log.Printf("Downloading %s from the cloud...", tplFilename)
|
|
|
+ log.Printf("Downloading %s from the cloud...", refFilename)
|
|
|
refContent, err := generator.ncClient.Download(refFilename)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
log.Println("Download completed.")
|
|
|
|
|
|
err = ioutil.WriteFile(filepath.Join(outputPath, "reference.odt"), refContent, 0777)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
tpl, err := tpl_util.LoadTextTemplateFromString(string(tplContent), funcMap)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
for _, department := range generator.Data.Departments {
|
|
|
filename := filepath.Join(outputPath, fmt.Sprintf("Dipartimento di %s", department.Name))
|
|
|
f, err := os.Create(filename + ".md")
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
defer f.Close()
|
|
|
|
|
|
err = tpl.Execute(f, department)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
odtFilename := fileutil.ReplaceExt(filename, "odt")
|
|
@@ -90,10 +92,14 @@ func (generator *DepartmentGenerator) generate(outputPath string, cloudPath stri
|
|
|
}
|
|
|
|
|
|
if err := libreoffice.Convert(filename+".odt", "pdf", "--outdir", outputPath); err != nil {
|
|
|
- log.Println(err)
|
|
|
+ return nil, err
|
|
|
}
|
|
|
+
|
|
|
+ files = append(files, &orm.File{Path: filepath.Base(filename) + ".pdf"})
|
|
|
}
|
|
|
|
|
|
+ return files, nil
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func NewDepartmentGenerator(config *generator.Config) *DepartmentGenerator {
|
|
@@ -174,12 +180,15 @@ func (generator *DepartmentGenerator) Run() {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
|
|
|
- generator.generate(outputPath, cloudPath, funcmap.FuncMap)
|
|
|
+ files, err := generator.generate(outputPath, cloudPath, funcmap.FuncMap)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
|
|
|
if generator.JobID > 0 {
|
|
|
job.End = time.Now()
|
|
|
|
|
|
- job.Files = append(job.Files, &orm.File{Path: "elenco_docenti.pdf"})
|
|
|
+ job.Files = append(job.Files, files...)
|
|
|
|
|
|
err = generator.kaClient.UpdateJob(job)
|
|
|
if err != nil {
|