Пример #1
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)
Пример #2
0
 def __init__(self, config, printer):
     self.config = config
     self.c = Connection()
     self.p = printer
     self.mailer = Mailer(config.config.mail)
     self.db = Database(config.config.db)
     self._initQueues()
class PrinterAdapter(AbstractPrinterAdapter):
    """Provides the basic functionality of wrapping
    the printer and allowing data to be printed.
    """

    def __init__(self, printer_name):
        """Initializes the adapter"""
        self._printer_name = printer_name
        self._connection = Connection()

    def print_data(self, data_file_str, title_str, options):
        """Prints the given data with the given
        information.

        @param data_file_str: str representing the
        file to be printed.

        @param title_str: str representing the title
        that the printer job should be associated
        with.

        @param options: dict of options that the
        should be associated with the printer job.

        @return: bool value representing if the
        printer was successful in scheduling the
        job.
        """
        value = self._connection.printFile(self._printer_name, data_file_str,
                                           title_str, options)
        return value > 0
Пример #4
0
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)
Пример #5
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()
Пример #6
0
import os

from cups import Connection
from cups_notify import Subscriber

cups = Connection()
notifier = Subscriber(cups)

printer = os.getenv('PRINTER')
 def __init__(self, printer_name):
     """Initializes the adapter"""
     self._printer_name = printer_name
     self._connection = Connection()
Пример #8
0
 def __init__(self):
     from cups import Connection
     self.connect = Connection()
Пример #9
0
#debug = True

#getopt //tnxs jacopogh
try: params = getopt.getopt(argv[1:],'h')
except getopt.GetoptError:
	print 'Wrong parameter'
	Usage()

#help mode (-h)
if "-h" in str(params[0]): Usage()

#get today
t_today = datetime.today()

#our connection
conn = Connection()

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
Пример #10
0
#getopt //tnxs jacopogh
try:
    params = getopt.getopt(argv[1:], 'h')
except getopt.GetoptError:
    print 'Wrong parameter'
    Usage()

#help mode (-h)
if "-h" in str(params[0]): Usage()

#get today
t_today = datetime.today()

#our connection
conn = Connection()

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
Пример #11
0
 def __init__(self):
     self.conn = Connection()
     self.printers = self.conn.getPrinters()
     self.check_printer_status()
     self.job_id = None