Commit d6a173eb authored by Maxime Bombar's avatar Maxime Bombar

update service

parent fcb51e14
......@@ -8,6 +8,11 @@ from re2oapi import Re2oAPIClient
import subprocess
DEBUG = True
LOCATION = '/re2o/media/printings'
KEYWORD = 'printings'
config = ConfigParser()
config.read('config.ini')
......@@ -23,16 +28,26 @@ client_hostname = socket.gethostname().split('.', 1)[0]
def get_path(filefield):
"""
"""
return(filefield.split(client_hostname)[-1])
return(LOCATION + filefield.split(KEYWORD)[-1])
def HP_name(name):
"""
"""
if 'Top' in name:
return '1Staple%sAngled' % (name.replace('Top', ''))
else:
return '2Staples%s' % name
def send(filepath, filename, number, settings):
"""
"""
filename = filename.replace(' ', '_')
booklet = (settings['disposition'] == 'Booklet')
cmd = ['lp', '-d', 'MFPM880-1', '-t', filename, '-n', number]
cmd = ['lp', '-d', 'MFPM880-1', '-t', filename, '-n', str(number)]
cmd += ['-o', 'Collate=True']
......@@ -79,14 +94,18 @@ def send(filepath, filename, number, settings):
# Holes
if not booklet:
if not(perforation == 'None'):
cmd += ['-o', 'HPStaplerOptions=%s' % HP_name(perforation)]
cmd += ['-o', 'HPStaplerOptions=%s' % perforation]
# The End
cmd.append('--')
cmd.append(filepath)
if DEBUG:
print(cmd)
toprint = ''
for k in cmd:
toprint += k
toprint += ' '
print(toprint[:-1])
else:
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
......@@ -105,9 +124,13 @@ def extract(job):
opts = ['color', 'disposition', 'format', 'perforation', 'stapling']
options = {}
for opt in opts:
if not job[opt]:
options[opt] = job[opt]
options[opt] = job[opt]
filepath = get_path(job['file'])
filename = job[filename]
count = job[count]
filename = job['filename']
number = job['count']
return(filepath, filename, number, options)
for job in api_client.list("printer/jobs"):
filepath, filename, number, options = extract(job)
send(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