class PrinterController:
    def __init__(self):
        from cups import Connection
        self.connect = Connection()

    def scan(self):
        printers = self.connect.getPrinters()
        for printer in printers:
            print(printer, printers[printer]["device-uri"])

    def set_printer(self):
        return list(self.connect.getPrinters())

    def print(self, printer, filename, title=None, *args, **kwargs):
        if not title:
            title = ""
        self.connect.printFile(printer, filename, title, kwargs)
Beispiel #2
0
class PublishController(object):
    def __init__(self):
        self.conn = Connection()
        self.printers = self.conn.getPrinters()
        self.check_printer_status()
        self.job_id = None

    def check_printer_status(self):
        is_selphy = []
        for printer in self.printers:
            is_selphy.append(printer == CONST["PRINTER_NAME"])
        if any(is_selphy):
            print("printer {} is available.".format(CONST["PRINTER_NAME"]))
            return True
        else:
            print("Printer {} is missing.".format(CONST["PRINTER_NAME"]))
            return False

    def start_print(self):
        self.conn.enablePrinter(CONST["PRINTER_NAME"])
        self.job_id = self.conn.printFile(
            CONST["PRINTER_NAME"],
            "ramdisk/polaroid.jpg",
            "{event}-{date}".format(
                event=CONST["EVENT_NAME"],
                date=datetime.now().strftime("%Y%m%d_%H-%M")),
            {},
        )
        self.save_image()

    def check_print_done(self):
        if self.conn.getJobs().get(self.job_id, None) is not None:
            print("Still printing...")
            return False
        return True

    def save_image(self):
        filepath = "events/{event_name}/{date_time}.jpg".format(
            event_name=CONST["EVENT_NAME"],
            date_time=format_time(datetime.now(), True))
        """ create folder """
        if not os.path.exists(os.path.dirname(filepath)):
            try:
                os.makedirs(os.path.dirname(filepath))
            except OSError as exc:  # Guard against race condition
                if exc.errno != errno.EEXIST:
                    raise

        image = Image.open("ramdisk/polaroid.jpg")
        image.save(filepath)
Beispiel #3
0
    def update(self):
        """Get the latest data from CUPS."""
        from cups import Connection

        conn = Connection(host=self._host, port=self._port)
        self.printers = conn.getPrinters()
Beispiel #4
0
jobs_id = conn.getJobs("all",True).keys()

if len(jobs_id) == 0 :
	print
	print "non hai stampato alcuna pagina questo mese"
	print
	exit(0)

#get job attributes	
jobs_attr = []
for i in jobs_id :
	jobs_attr.append( conn.getJobAttributes(i))

#get printers
printers = conn.getPrinters()

#what we are going to print
printers_records = {}

#initialize the dict
#	it's not the py way but works
for i in printers :
	printers_records[i] = []

#parse our jobs_attr and build records
for i in jobs_attr :
	if debug : print i
	#assign printer
	for j in printers :
		if j in i["job-printer-uri"].split("/") :
Beispiel #5
0
jobs_id = conn.getJobs("all", True).keys()

if len(jobs_id) == 0:
    print
    print "non hai stampato alcuna pagina questo mese"
    print
    exit(0)

#get job attributes
jobs_attr = []
for i in jobs_id:
    jobs_attr.append(conn.getJobAttributes(i))

#get printers
printers = conn.getPrinters()

#what we are going to print
printers_records = {}

#initialize the dict
#	it's not the py way but works
for i in printers:
    printers_records[i] = []

#parse our jobs_attr and build records
for i in jobs_attr:
    if debug: print i
    #assign printer
    for j in printers:
        if j in i["job-printer-uri"].split("/"):