func (s *server) processIncoming(conn *printserver.ServerConn, msg *stomp.Message) error { var job tickets.BinaryJob if err := proto.Unmarshal(msg.Body, &job); err != nil { log.Printf("Received malformed job: %s", err) return err } sourceName := fmt.Sprintf("%s-%s.ps", time.Now().Format("2006-01-02T15-04-05"), job.GetJobId()) sourceFullName := filepath.Join(s.Workdir, sourceName) if buf, err := job.Data.Bytes(); err == nil { if err = ioutil.WriteFile(sourceFullName, buf, os.ModePerm); err != nil { log.Printf("Error writing file: %s", err) return err } } else { log.Printf("Error getting buffer: %s", err) return err } log.Printf("Sending job %s to printer %s", job.GetJobId(), job.GetPrinter()) if tools.DryRun() { log.Printf("Would run: %s\n", s.Gsprint, "-printer", job.GetPrinter(), sourceFullName) return nil } cmd := exec.Command(s.Gsprint, "-printer", job.GetPrinter(), sourceFullName) cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr if err := cmd.Run(); err != nil { log.Printf("Error printing: %s", err) return err } return nil }
func (s *server) processIncoming(conn *printserver.ServerConn, msg *stomp.Message) error { var job tickets.BinaryJob if err := proto.Unmarshal(msg.Body, &job); err != nil { log4go.Error("Received malformed job: %s", err) return err } jobDir := filepath.Join(s.Workdir, job.GetJobId()) os.MkdirAll(jobDir, os.ModePerm) // err? sourceName := fmt.Sprintf("%s.tex", job.GetJobId()) buf, err := job.GetData().Bytes() if err != nil { return err } if err = ioutil.WriteFile(filepath.Join(jobDir, sourceName), buf, os.ModePerm); err != nil { return err } cmd := exec.Command("latex", "-interaction=batchmode", sourceName) cmd.Dir, cmd.Stdin, cmd.Stdout, cmd.Stderr = jobDir, os.Stdin, os.Stdout, os.Stderr if err = cmd.Run(); err != nil { log.Printf("Latex error: %s\n", err) return nil } cmd = exec.Command("latex", "-interaction=batchmode", sourceName) cmd.Dir, cmd.Stdin, cmd.Stdout, cmd.Stderr = jobDir, os.Stdin, os.Stdout, os.Stderr if err = cmd.Run(); err != nil { log.Printf("Latex error: %s\n", err) return nil } dviName := fmt.Sprintf("%s.dvi", job.GetJobId()) cmd = exec.Command("dvips", "-t", "a4", dviName) cmd.Dir, cmd.Stdin, cmd.Stdout, cmd.Stderr = jobDir, os.Stdin, os.Stdout, os.Stderr if err = cmd.Run(); err != nil { log.Printf("Dvips error: %s\n", err) return nil } psName := fmt.Sprintf("%s.ps", job.GetJobId()) content, err := ioutil.ReadFile(filepath.Join(jobDir, psName)) if err != nil { log.Printf("Where's my file? %s\n", err) return nil } cBlob, err := tickets.NewBlob(content) if err != nil { return err } result := tickets.BinaryJob{ JobId: job.JobId, Printer: job.Printer, Data: cBlob, } content, err = proto.Marshal(&result) if err != nil { return err } return conn.Send(&result) }