import cups import time def print_file filename title None cupshost lo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import cups
import time
def print_file(filename, title=None, cupshost='localhost'):
if title is None:
title = 'REST printer job %d' % int(time.time())
c = cups.Connection(host=cupshost)
printer = c.getDefault()
if printer is None:
raise RuntimeError("No default CUPS printer on host %s" % host)
job_id = c.printFile(printer, filename, title, {'landscape': landscape})
return "%s@%s-%d" % (printer, cupshost, job_id)
def cli(args):
filename = args[0]
print print_file(filename)
if __name__ == "__main__":
import sys
cli(sys.argv[1:])