Commit fcb51e14 authored by Maxime Bombar's avatar Maxime Bombar

Format options for HP Printer

parent 3459ba22
#!/usr/bin/env python3
#-*- mode: utf-8 -*-
from configparser import ConfigParser
import socket
from re2oapi import Re2oAPIClient
import subprocess
config = ConfigParser()
config.read('config.ini')
......@@ -13,3 +18,96 @@ api_username = config.get('Re2o', 'username')
api_client = Re2oAPIClient(api_hostname, api_username, api_password)
client_hostname = socket.gethostname().split('.', 1)[0]
def get_path(filefield):
"""
"""
return(filefield.split(client_hostname)[-1])
def send(filepath, filename, number, settings):
"""
"""
booklet = (settings['disposition'] == 'Booklet')
cmd = ['lp', '-d', 'MFPM880-1', '-t', filename, '-n', number]
cmd += ['-o', 'Collate=True']
if settings['format'] == 'A3':
cmd += ['-o', 'pdf-expand',
'-o', 'pdf-paper=841x1190'
]
cmd += ['-o', 'PageSize=%s' % settings['format']]
# Resize (avoid deadlock)
cmd += ['-o', 'fit-to-page']
# Default : print in color
if settings['color'] == 'Greyscale':
cmd += ['-o', 'HPColorAsGray=True',
'-o', 'ColorModel=Grayscale']
if booklet:
cmd += ['-o', 'number-up=2']
# Manage disposition
if not (settings['disposition'] == 'OneSided'):
if booklet:
cmd += ['-o', 'sides=two-sided-short-edge']
else:
cmd += ['-o', 'sides=two-sided-long-edge']
else:
cmd += ['-o', 'sides=one-sided']
# Staples
stapling = settings['stapling']
if booklet:
cmd += ['-o', 'HPStaplerOptions=FoldStitch']
elif not (stapling == 'None'):
cmd += ['-o', 'HPStaplerOptions=%s' % HP_name(stapling)]
perforation = settings['perforation']
# Holes
if not booklet:
if not(perforation == 'None'):
cmd += ['-o', 'HPStaplerOptions=%s' % HP_name(perforation)]
# The End
cmd.append('--')
cmd.append(filepath)
if DEBUG:
print(cmd)
else:
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err:
print(
"Erreur lors de l'envoi du fichier %s à l'imprimante.\n"
"Code de retour: %s, Sortie:\n%s",
filename, err.returncode, err.output.decode()
)
print(err)
def extract(job):
"""
"""
opts = ['color', 'disposition', 'format', 'perforation', 'stapling']
options = {}
for opt in opts:
if not job[opt]:
options[opt] = job[opt]
filepath = get_path(job['file'])
filename = job[filename]
count = job[count]
return(filepath, filename, number, options)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment