Commit 29cea398 authored by Vitaly Buka's avatar Vitaly Buka

Merge pull request #104 from jacobmarble/job-title

Make GCP job id prefix to job title optional.
parents 149c605a 627c5341
......@@ -129,15 +129,16 @@ var (
// Interface between Go and the CUPS API.
type CUPS struct {
cc *cupsCore
pc *ppdCache
infoToDisplayName bool
displayNamePrefix string
printerAttributes []string
systemTags map[string]string
cc *cupsCore
pc *ppdCache
infoToDisplayName bool
prefixJobIDToJobTitle bool
displayNamePrefix string
printerAttributes []string
systemTags map[string]string
}
func NewCUPS(infoToDisplayName bool, displayNamePrefix string, printerAttributes []string, maxConnections uint, connectTimeout time.Duration) (*CUPS, error) {
func NewCUPS(infoToDisplayName, prefixJobIDToJobTitle bool, displayNamePrefix string, printerAttributes []string, maxConnections uint, connectTimeout time.Duration) (*CUPS, error) {
if err := checkPrinterAttributes(printerAttributes); err != nil {
return nil, err
}
......@@ -406,12 +407,16 @@ func convertJobState(cupsState int32) cdd.PrintJobStateDiff {
// Print sends a new print job to the specified printer. The job ID
// is returned.
func (c *CUPS) Print(printername, filename, title, user string, ticket *cdd.CloudJobTicket) (uint32, error) {
func (c *CUPS) Print(printername, filename, title, user, gcpJobID string, ticket *cdd.CloudJobTicket) (uint32, error) {
pn := C.CString(printername)
defer C.free(unsafe.Pointer(pn))
fn := C.CString(filename)
defer C.free(unsafe.Pointer(fn))
var t *C.char
if c.prefixJobIDToJobTitle {
title = fmt.Sprintf("gcp:%s %s", gcpJobID, title)
}
if len(title) > 255 {
t = C.CString(title[:255])
} else {
......@@ -433,12 +438,12 @@ func (c *CUPS) Print(printername, filename, title, user string, ticket *cdd.Clou
u := C.CString(user)
defer C.free(unsafe.Pointer(u))
jobID, err := c.cc.printFile(u, pn, fn, t, numOptions, o)
cupsJobID, err := c.cc.printFile(u, pn, fn, t, numOptions, o)
if err != nil {
return 0, err
}
return uint32(jobID), nil
return uint32(cupsJobID), nil
}
// convertIPPDateToTime converts an RFC 2579 date to a time.Time object.
......
......@@ -121,6 +121,10 @@ func updateConfigFile() {
if err != nil {
panic(err)
}
if configFilename == "" {
fmt.Println("Could not find a config file to update")
return
}
// Same config in []byte format.
configRaw, err := ioutil.ReadFile(configFilename)
......
......@@ -63,6 +63,9 @@ var (
copyPrinterInfoToDisplayNameFlag = flag.String(
"copy-printer-info-to-display-name", "",
"Whether to copy the CUPS printer's printer-info attribute to the GCP printer's defaultDisplayName")
prefixJobIDToJobTitleFlag = flag.String(
"prefix-job-id-to-job-title", "",
"Whether to add the job ID to the beginning of the job title")
displayNamePrefixFlag = flag.String(
"display-name-prefix", "",
"Prefix to add to GCP printer's defaultDisplayName")
......@@ -390,6 +393,7 @@ func createConfigFile(xmppJID, robotRefreshToken, userRefreshToken, shareScope,
flagToBool(cupsJobFullUsernameFlag, lib.DefaultConfig.CUPSJobFullUsername),
flagToBool(cupsIgnoreRawPrintersFlag, lib.DefaultConfig.CUPSIgnoreRawPrinters),
flagToBool(copyPrinterInfoToDisplayNameFlag, lib.DefaultConfig.CopyPrinterInfoToDisplayName),
flagToBool(prefixJobIDToJobTitleFlag, lib.DefaultConfig.PrefixJobIDToJobTitle),
flagToString(displayNamePrefixFlag, lib.DefaultConfig.DisplayNamePrefix),
flagToString(monitorSocketFilenameFlag, lib.DefaultConfig.MonitorSocketFilename),
flagToString(gcpBaseURLFlag, lib.DefaultConfig.GCPBaseURL),
......
......@@ -91,8 +91,9 @@ func main() {
defer x.Quit()
}
c, err := cups.NewCUPS(config.CopyPrinterInfoToDisplayName, config.DisplayNamePrefix,
config.CUPSPrinterAttributes, config.CUPSMaxConnections, cupsConnectTimeout)
c, err := cups.NewCUPS(config.CopyPrinterInfoToDisplayName, config.PrefixJobIDToJobTitle,
config.DisplayNamePrefix, config.CUPSPrinterAttributes, config.CUPSMaxConnections,
cupsConnectTimeout)
if err != nil {
glog.Fatal(err)
}
......
......@@ -630,12 +630,10 @@ func (gcp *GoogleCloudPrint) processJob(job *Job, printer *lib.Printer, reportJo
return
}
jobTitle := fmt.Sprintf("gcp:%s %s", job.GCPJobID, job.Title)
gcp.jobs <- &lib.Job{
CUPSPrinterName: printer.Name,
Filename: filename,
Title: jobTitle,
Title: job.Title,
User: job.OwnerID,
JobID: job.GCPJobID,
Ticket: ticket,
......
......@@ -85,6 +85,9 @@ type Config struct {
// Whether to copy the CUPS printer's printer-info attribute to the GCP printer's defaultDisplayName.
CopyPrinterInfoToDisplayName bool `json:"copy_printer_info_to_display_name"`
// Whether to add the job ID to the beginning of the job title. Useful for debugging.
PrefixJobIDToJobTitle bool `json:"prefix_job_id_to_job_title"`
// Prefix for all GCP printers hosted by this connector.
DisplayNamePrefix string `json:"display_name_prefix"`
......@@ -172,6 +175,7 @@ var DefaultConfig = Config{
CUPSJobFullUsername: false,
CUPSIgnoreRawPrinters: true,
CopyPrinterInfoToDisplayName: true,
PrefixJobIDToJobTitle: false,
DisplayNamePrefix: "",
MonitorSocketFilename: "/tmp/cups-connector-monitor.sock",
GCPBaseURL: "https://www.google.com/cloudprint/",
......
......@@ -395,7 +395,7 @@ func (pm *PrinterManager) printJob(cupsPrinterName, filename, title, user, jobID
printer.CUPSJobSemaphore.Acquire()
defer printer.CUPSJobSemaphore.Release()
cupsJobID, err := pm.cups.Print(printer.Name, filename, title, user, ticket)
cupsJobID, err := pm.cups.Print(printer.Name, filename, title, user, jobID, ticket)
if err != nil {
pm.incrementJobsProcessed(false)
glog.Errorf("Failed to send job %s to CUPS: %s", jobID, err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment