Skip to content
Permalink
Browse files

Submitting print job now works

  • Loading branch information
simoncadman committed Aug 17, 2012
1 parent f470328 commit a5e1335a961da215de4f36755d852a2320cbdc50
Showing with 23 additions and 18 deletions.
  1. +9 −3 cloudprintrequestor.py
  2. +14 −15 printer.py
@@ -27,10 +27,16 @@ def getAccount ( self ):
return self.account

def doRequest ( self, path, headers = None, data = None , boundary = None ):
# force useragent to CCP
if headers == None:
headers = {}
headers['user-agent'] = "CUPS Cloud Print"

url = '%s/%s' % (self.CLOUDPRINT_URL, path)
if data == None:
headers, response = self.request(url, "GET")
headers, response = self.request(url, "GET", headers=headers)
else:
headers, response = self.request(url, "GET", body=data, headers=headers)
print response
headers['Content-Length'] = str(len(data))
headers['Content-Type'] = 'multipart/form-data;boundary=%s' % boundary
headers, response = self.request(url, "POST", body=data, headers=headers)
return json.loads(response)
@@ -184,7 +184,7 @@ def encodeMultiPart(self, fields, files, file_type='application/xml'):
lines.append('') # blank line
return Printer.CRLF.join(lines)

def getCapabilities ( self, ccpid, cupsprintername ) :
def getCapabilities ( self, gcpid, cupsprintername ) :
# define mappings
itemmapping = {
'DefaultColorModel' : 'ns1:Colors',
@@ -206,7 +206,7 @@ def getCapabilities ( self, ccpid, cupsprintername ) :
for cupsprinter in cupsprinters:
if cupsprinters[cupsprinter]['printer-info'] == cupsprintername:
attrs = cups.PPD(connection.getPPD(cupsprinter)).attributes
printerdetails = self.getPrinterDetails(ccpid)
printerdetails = self.getPrinterDetails(gcpid)

for mapping in itemmapping:
cupsitem = mapping
@@ -252,22 +252,21 @@ def submitJob(self, printerid, jobtype, jobfile, jobname, printername ):
'jpeg': 'image/jpeg',
'png': 'image/png',
}
headers = {
'printerid' : printerid,
'title' : title,
'content' : content[jobtype],
'contentType' : content_type[jobtype],
'capabilities' : json.dumps( self.getCapabilities(printerid, printername ) )
}
headers = [
('printerid', printerid),
('title', title),
('content', content[jobtype]),
('contentType', content_type[jobtype]),
('capabilities', json.dumps( self.getCapabilities(printerid, printername) ) )
]
files = []
#if jobtype in ['pdf', 'jpeg', 'png']:
# edata = self.encodeMultiPart(headers, files, file_type=content_type[jobtype])
#else:
# edata = self.encodeMultiPart(headers, files)
edata = ""
if jobtype in ['pdf', 'jpeg', 'png']:
edata = self.encodeMultiPart(headers, files, file_type=content_type[jobtype])
else:
edata = self.encodeMultiPart(headers, files)

responseobj = self.requestor.doRequest( 'submit', headers, edata, self.BOUNDARY )
print responseobj
responseobj = self.requestor.doRequest( 'submit', None, edata, self.BOUNDARY )
try:
if responseobj['success'] == True:
return True

0 comments on commit a5e1335

Please sign in to comment.
You can’t perform that action at this time.