Add maxresults argument to gam print printjobs/gam printjob fetch

This commit is contained in:
Ross Scroggs
2016-04-27 06:58:54 -07:00
parent 49d1845129
commit 289fda94df

View File

@ -2109,6 +2109,9 @@ PRINTJOB_DESCENDINGORDER_MAP = {
u'TITLE': u'TITLE_DESC',
}
PRINTJOBS_DEFAULT_JOB_LIMIT = 25
PRINTJOBS_DEFAULT_MAX_RESULTS = 100
def doPrintPrintJobs():
cp = buildGAPIObject(u'cloudprint')
job_attributes = [{}]
@ -2123,7 +2126,8 @@ def doPrintPrintJobs():
age = None
older_or_newer = None
offset = 0
jobLimit = 25
jobLimit = PRINTJOBS_DEFAULT_JOB_LIMIT
maxResults = PRINTJOBS_DEFAULT_MAX_RESULTS
i = 3
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace(u'_', u'')
@ -2181,6 +2185,9 @@ def doPrintPrintJobs():
elif myarg == u'limit':
jobLimit = max(0, int(sys.argv[i+1]))
i += 2
elif myarg == u'maxresults':
maxResults = min(1000, max(1, int(sys.argv[i+1])))
i += 2
else:
print u'ERROR: %s is not a valid argument for "gam print printjobs"' % sys.argv[i]
sys.exit(2)
@ -2188,9 +2195,12 @@ def doPrintPrintJobs():
sortorder = PRINTJOB_DESCENDINGORDER_MAP[sortorder]
jobCount = 0
while True:
limit = 25 if jobLimit == 0 else jobLimit-jobCount
if limit == 0:
break
if jobLimit == 0:
limit = maxResults
else:
limit = min(maxResults, jobLimit-jobCount)
if limit == 0:
break
result = callGAPI(cp.jobs(), u'list',
printerid=printerid, q=query, status=status, sortorder=sortorder,
owner=owner, offset=offset, limit=limit)
@ -2573,7 +2583,8 @@ def doPrintJobFetch():
age = None
older_or_newer = None
offset = 0
jobLimit = 25
jobLimit = PRINTJOBS_DEFAULT_JOB_LIMIT
maxResults = PRINTJOBS_DEFAULT_MAX_RESULTS
i = 4
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace(u'_', u'')
@ -2625,6 +2636,9 @@ def doPrintJobFetch():
elif myarg == u'limit':
jobLimit = max(0, int(sys.argv[i+1]))
i += 2
elif myarg == u'maxresults':
maxResults = min(1000, max(1, int(sys.argv[i+1])))
i += 2
else:
print u'ERROR: %s is not a valid argument for "gam printjobs fetch"' % sys.argv[i]
sys.exit(2)
@ -2634,9 +2648,12 @@ def doPrintJobFetch():
ssd = u'{"state": {"type": "DONE"}}'
jobCount = 0
while True:
limit = 25 if jobLimit == 0 else jobLimit-jobCount
if limit == 0:
break
if jobLimit == 0:
limit = maxResults
else:
limit = min(maxResults, jobLimit-jobCount)
if limit == 0:
break
result = callGAPI(cp.jobs(), u'list',
printerid=printerid, q=query, status=status, sortorder=sortorder,
owner=owner, offset=offset, limit=limit)
@ -2663,7 +2680,7 @@ def doPrintJobFetch():
fileName = u'%s-%s' % (fileName, jobid)
_, content = cp._http.request(uri=fileUrl, method='GET')
if writeFile(fileName, content, continueOnError=True):
# ticket = callGAPI(cp.jobs(), u'getticket', jobid=jobid, use_cjt=True)
# ticket = callGAPI(cp.jobs(), u'getticket', jobid=jobid, use_cjt=True)
result = callGAPI(cp.jobs(), u'update', jobid=jobid, semantic_state_diff=ssd)
checkCloudPrintResult(result)
print u'Printed job %s to %s' % (jobid, fileName)