本文整理汇总了Python中cups.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python cups.Connection方法的具体用法?Python cups.Connection怎么用?Python cups.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cups
的用法示例。
在下文中一共展示了cups.Connection方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: default_get
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def default_get(self, cr, uid, fields, context=None):
printers_obj = self.pool.get('aeroo.printers')
data = super(aeroo_printer_installer, self).default_get(cr, uid, fields, context=context)
conn = cups.Connection()
printers = conn.getPrinters()
installed_ids = printers_obj.search(cr, 1, ['|',('active','=',False),('active','=',True)], context=context)
printers_installed = printers_obj.read(cr, uid, installed_ids, context=context)
new_printers = list(set(printers.keys()).difference(set(map(lambda p: p['code'], printers_installed))))
data['printer_ids'] = []
for p in printers_installed:
p_temp = p.copy()
del p_temp['id']
del p_temp['group_ids']
del p_temp['active']
p_temp['state'] = 'connected'
data['printer_ids'].append(p_temp)
for new_p in new_printers:
note = '\n'.join(map(lambda key: "%s: %s" % (key, printers[new_p][key]), printers[new_p]))
p_temp = {'name':printers[new_p]['printer-info'],'code':new_p,'state':'new','note':note}
data['printer_ids'].append(p_temp)
data.update(data)
return data
示例2: __init__
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def __init__(self, page_size, print_pdf=False):
self._conn = cups.Connection() if cups else None
if print_pdf:
logging.error('Printing to PDF not supported with pycups')
self._conn = None
if os.access('/dev/shm', os.W_OK):
self._tmp_filename = '/dev/shm/print.jpg'
else:
self._tmp_filename = '/tmp/print.jpg'
logging.debug('Storing temp files to "{}"'.format(self._tmp_filename))
if self._conn is not None:
self._printer = self._conn.getDefault()
logging.info('Using printer "%s"', self._printer)
示例3: __init__
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def __init__(self, name='default', max_pages=-1, counters=None):
self._conn = cups.Connection() if cups else None
self._notifier = Subscriber(self._conn) if cups else None
self.name = None
self.max_pages = max_pages
self.count = counters
if not cups:
LOGGER.warning("No printer found (pycups or pycups-notify not installed)")
return # CUPS is not installed
if not name or name.lower() == 'default':
self.name = self._conn.getDefault()
if not self.name and self._conn.getPrinters():
self.name = list(self._conn.getPrinters().keys())[0] # Take first one
elif name in self._conn.getPrinters():
self.name = name
if not self.name:
if name.lower() == 'default':
LOGGER.warning("No printer configured in CUPS (see http://localhost:631)")
else:
LOGGER.warning("No printer named '%s' in CUPS (see http://localhost:631)", name)
else:
LOGGER.info("Connected to printer '%s'", self.name)
示例4: __init__
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def __init__(self, physical_only=False):
self.connection = cups.Connection()
self.printers = []
prn_dict = self.connection.getPrinters()
for item in prn_dict.keys():
try:
prn = CUPS_Printer(self.connection, item, prn_dict[item])
self.printers.append(prn)
except Exception:
LOG.exception('Cannot add printer %s due to:', item)
if not physical_only:
self.printers.append(PDF_Printer())
self.default_printer = self.connection.getDefault()
示例5: get_prn_info
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def get_prn_info(self):
return ((_('Driver:'), self.get_driver_name()),
(_('Connection'), self.get_connection()))
示例6: report_to_printer
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def report_to_printer(self, cr, uid, ids, report_id, printer, context={}):
context['active_ids'] = ids
report = self.pool.get('ir.actions.report.xml').browse(cr, uid, report_id, context=context)
data = {'model': report.model, 'id': context['active_ids'][0], 'report_type': 'aeroo'}
res = netsvc.Service._services['report.%s' % report.report_name].create(cr, uid, context['active_ids'], data, context=context)
if res[1] in SUPPORTED_PRINT_FORMAT:
with NamedTemporaryFile(suffix='', prefix='aeroo-print-', delete=False) as temp_file:
temp_file.write(res[0])
conn = cups.Connection()
return conn.printFile(printer, temp_file.name, 'Aeroo Print', {'copies': report.copies > 0 and str(report.copies) or '1'})
else:
raise osv.except_osv(_('Warning!'), _('Unsupported report format "%s". Is not possible direct print to printer.') % res[1])
return False
示例7: to_print
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def to_print(self, cr, uid, ids, context={}):
this = self.browse(cr, uid, ids[0], context=context)
report_xml = self.pool.get('ir.actions.report.xml').browse(cr, uid, context['report_action_id'])
self.check_report(report_xml.report_name)
if this.printer:
data = {'model': report_xml.model, 'id': this.print_ids[0], 'report_type': 'aeroo'}
res = netsvc.Service._services['report.%s' % report_xml.report_name].create(cr, uid, this.print_ids, data, context=context)
if res[1] in SUPPORTED_PRINT_FORMAT:
with NamedTemporaryFile(suffix='', prefix='aeroo-print-', delete=False) as temp_file:
temp_file.write(res[0])
conn = cups.Connection()
conn.printFile(this.printer, temp_file.name, 'Aeroo Print', {'copies': this.copies > 0 and str(this.copies) or '1'})
return {
'type': 'ir.actions.act_window_close'
}
print_ids = []
if this.copies<=0:
print_ids = this.print_ids
else:
while(this.copies):
print_ids.extend(this.print_ids)
this.copies -= 1
if report_xml.out_format.id != this.out_format:
report_xml.write({'out_format':this.out_format}, context=context)
if self.check_if_deferred(report_xml, this.print_ids):
return this.write({'state':'confirm','message':_("This process may take too long for interactive processing. \
It is advisable to defer the process in background. \
Do you want to start a deferred process?"),'print_ids':print_ids}, context=context)
data = {'model':report_xml.model, 'ids':print_ids, 'id':context['active_id'], 'report_type': 'aeroo'}
context['aeroo_dont_print_to_pinter'] = True
return {
'type': 'ir.actions.report.xml',
'report_name': report_xml.report_name,
'datas': data,
'context':context
}
示例8: _get_state
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def _get_state(self, cr, uid, ids, name, args, context={}):
res = {}
conn = cups.Connection()
printers = conn.getPrinters()
for p in self.browse(cr, uid, ids, context=context):
state = printers.get(p.code, {}).get('printer-state')
res[p.id] = state and str(state) or state
return res
示例9: refresh
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def refresh(self, cr, uid, ids, context={}):
conn = cups.Connection()
printers = conn.getPrinters()
for r in self.browse(cr, uid, ids, context=context):
data = printers.get(r.code)
if not data:
raise osv.except_osv(_('Error!'), _('Printer "%s" not found!') % r.code)
note = '\n'.join(map(lambda key: "%s: %s" % (key, data[key]), data))
r.write({'note':note}, context=context)
return True
示例10: _get_connection
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def _get_connection(self, host: Optional[str] = None):
# noinspection PyPackageRequirements
import cups
connection = cups.Connection(host=host or self.host)
return connection
示例11: printPic
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def printPic(fileName):
addPreviewOverlay(100,200,55,"printing...")
conn = cups.Connection()
printers = conn.getPrinters()
default_printer = printers.keys()[0]
cups.setUser('pi')
conn.printFile (default_printer, fileName, "boothy", {'fit-to-page':'True'})
logging.info("Print job successfully created.");
#merges the 4 images
示例12: print_image
# 需要导入模块: import cups [as 别名]
# 或者: from cups import Connection [as 别名]
def print_image(fileName=''):
print_image_logger = logging.getLogger('rpi_utils.print_image')
print_image_logger.info("Attempting to run a print job ...")
# now generate the print image
generated_image = generate_print_image(image_selected=fileName)
print_image_logger.info("Generated Print Image: %s" % generated_image)
# for now just test the underlying function only
#return
fileName = generated_image
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = ""
for printer in printers:
print_image_logger.info(printer, printers[printer]["device-uri"])
if config.__PRINTER_TYPE__ in printer.lower():
printer_name = printer
#printer_name=list(printers.keys())[1]
#fileName = "PollyResponse.txt"
#fileName = "../assets/stock/Simone-Biles.jpg"
print_image_logger.info("The Printer Chosen: %s , The Image Chosen is in path: %s" % \
(printer_name, fileName))
print_image_logger.info("Triggering the print job now for %s ..." % fileName)
conn.printFile(printer_name, fileName, " ", {})
print_image_logger.info("Completed the print job!")
return