Skip to content
Snippets Groups Projects
Commit f26b97ef authored by Robert Habermann's avatar Robert Habermann
Browse files

add store attachment feature to cli

parent f17468ab
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
import os
import stat
import click
import tempfile
from pyotrs.version import __version__
from pyotrs.lib import Client
......@@ -73,6 +74,10 @@ def cli(config_file=None):
help='include Articles')
@click.option('--attachments', is_flag=True,
help='include Article Attachments')
@click.option('--store-attachments', is_flag=True,
help='store Article Attachments to /tmp/<ticket_id>')
@click.option('--store-path', type=click.STRING,
help='where to store Attachments (default: /tmp/pyotrs_<random_str>')
@click.option('-t', '--ticket-id', type=click.INT, prompt=True,
envvar='PYOTRS_TICKET_ID',
help='Ticket ID')
......@@ -87,7 +92,8 @@ def cli(config_file=None):
help='Base URL')
@cli.command(name="get")
def get(baseurl=None, username=None, password=None, ticket_id=None,
articles=False, attachments=False,
articles=False,
attachments=False, store_attachments=False, store_path=None,
https_verify=True, ca_cert_bundle=None):
"""PyOTRS get command"""
click.secho("Connecting to %s as %s.." % (baseurl, username))
......@@ -103,5 +109,19 @@ def get(baseurl=None, username=None, password=None, ticket_id=None,
click.secho("State: \t\t%s" % ticket.field_get("State"))
click.secho("Priority: \t%s" % ticket.field_get("Priority"))
click.secho("\nFull Ticket:")
print(ticket.to_dct())
if store_attachments:
if store_path:
store_path = store_path
if not os.path.exists(store_path):
os.makedirs(store_path)
else:
store_path = tempfile.mkdtemp(prefix="pyotrs_")
click.secho("\nstoring attachments to: %s" % store_path)
for article in ticket.articles:
for attachment in article.attachments:
attachment.save_to_dir(folder=store_path)
click.secho("%s stored." % attachment)
# click.secho("\nFull Ticket:")
# print(ticket.to_dct())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment