Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pyipptool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def _get_filename_for_content(content):
"""
file_ = None
delete = False
if content is colander.null:
return content, delete
if isinstance(content, file):
# regular file
file_ = content
Expand Down Expand Up @@ -468,7 +470,10 @@ def cups_add_modify_printer(self,
printer_state_message=colander.null,
requesting_user_name_allowed=colander.null,
requesting_user_name_denied=colander.null,
printer_is_shared=colander.null):
printer_is_shared=colander.null,
ppd_content=colander.null,
):
filename, delete = _get_filename_for_content(ppd_content)
kw = {'operation_attributes_tag':
{'printer_uri': printer_uri},
'printer_attributes_tag':
Expand All @@ -486,11 +491,16 @@ def cups_add_modify_printer(self,
'printer_state_message': printer_state_message,
'requesting_user_name_allowed ': requesting_user_name_allowed,
'requesting_user_name_denied': requesting_user_name_denied,
'printer_is_shared': printer_is_shared}}
'printer_is_shared': printer_is_shared,
'file': filename}}

request = pretty_printer(cups_add_modify_printer_form.render(kw))
response = yield self._call_ipptool(request)
raise Return(response)
try:
response = yield self._call_ipptool(request)
raise Return(response)
finally:
if delete:
os.unlink(filename)

@pyipptool_coroutine
def cups_add_modify_class(self,
Expand Down
3 changes: 3 additions & 0 deletions pyipptool/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class PrinterAttributesGroup(colander.Schema):
ppd_name = colander.SchemaNode(Name(), widget=IPPAttributeWidget())
member_uris = colander.SchemaNode(Uri(), widget=IPPAttributeWidget())

# Always last
file = colander.SchemaNode(colander.String(), widget=IPPFileWidget())


class BaseIPPSchema(colander.Schema):
name = colander.SchemaNode(colander.String(), widget=IPPNameWidget())
Expand Down
2 changes: 2 additions & 0 deletions pyipptool/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def serialize(self, field, cstruct=None, readonly=False):

class IPPFileWidget(Widget):
def serialize(self, field, cstruct=None, readonly=False):
if cstruct is colander.null:
return ''
if not isinstance(cstruct, basestring):
raise ValueError('Wrong value provided for field {!r}'.format(
field.name))
Expand Down
28 changes: 28 additions & 0 deletions tests/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ def test_cups_add_modify_printer(_call_ipptool):
assert request == expected_request, request


@mock.patch.object(pyipptool.wrapper, '_call_ipptool')
def test_cups_add_modify_printer_with_ppd(_call_ipptool):
from pyipptool import cups_add_modify_printer
_call_ipptool.return_value = {'Tests': [{}]}
with tempfile.NamedTemporaryFile('rb') as tmp:
cups_add_modify_printer(
printer_uri='https://localhost:631/classes/PUBLIC-PDF',
device_uri='cups-pdf:/',
printer_is_shared=False,
ppd_content=tmp,
)
request = _call_ipptool._mock_mock_calls[0][1][-1]
expected_request = textwrap.dedent("""
{
NAME "CUPS Add Modify Printer"
OPERATION "CUPS-Add-Modify-Printer"
GROUP operation-attributes-tag
ATTR charset attributes-charset utf-8
ATTR language attributes-natural-language en
ATTR uri printer-uri https://localhost:631/classes/PUBLIC-PDF
GROUP printer-attributes-tag
ATTR boolean printer-is-shared 0
ATTR uri device-uri cups-pdf:/
FILE %s
}""" % tmp.name).strip()
assert request == expected_request, request


@mock.patch.object(pyipptool.wrapper, '_call_ipptool')
def test_get_job_attributes_with_job_id(_call_ipptool):
from pyipptool import get_job_attributes
Expand Down