diff --git a/lpmn_client/src/console.py b/lpmn_client/src/console.py index 0b1108ad1f3823a9e20b230e51977e5397d0d948..811c706b9f49ebfdf2218874721aefc3e3cd4933 100644 --- a/lpmn_client/src/console.py +++ b/lpmn_client/src/console.py @@ -7,6 +7,8 @@ import os import readline import sys +import yaml + from lpmn_client.src.requester import Requester @@ -15,6 +17,7 @@ class Console(cmd.Cmd, object): def __init__(self, email=None): """Initializes the Console class instance.""" + super().__init__() self.intro = ( "Welcome to the LPMN console. Type help or ? to list commands.\n" ) @@ -40,7 +43,12 @@ class Console(cmd.Cmd, object): self.cmdqueue = [] self.stdout = sys.stdout self.last_upload = [] - readline.set_completer_delims(" \t\n") + with open("lpmn_services.yaml", "r") as f: + try: + self.services = yaml.safe_load(f) + except yaml.YAMLError as exc: + print(exc) + readline.set_completer_delims(" |\t\n") def do_upload(self, args: str): """Uploads a file. @@ -140,6 +148,44 @@ class Console(cmd.Cmd, object): print("Progress file not found") return + def do_services(self, arg): + """Service information display.""" + if arg in self.services.keys(): + service = self.services[arg] + print("Description:") + print(service["description"]) + print("\n") + + if service["params"] != "None": + print("Available parameters:") + self.columnize(["name", "default", "type", "optional"], 80) + print("=" * 40) + for key, value in service["params"].items(): + self.columnize( + [ + key, + value["default"], + value["type"], + value["optional"], + ], + 80, + ) + print("\t", value["description"]) + print("\n") + + if service["next"] != "None": + print("Next in pipeline:") + print("=" * 40) + self.columnize(list(service["next"]), 80) + print("\n") + + return + else: + print("Available LPMN services:") + print("=" * 40) + self.columnize(list(self.services.keys()), 80) + print("\n") + def complete_upload(self, text, line, start, end): """Autocomplete for upload.""" return self._complete_path(text) @@ -148,6 +194,23 @@ class Console(cmd.Cmd, object): """Autocomplete for download.""" return self._complete_path(text) + def complete_lpmn(self, text, line, start, end): + """Autocomplete for lpmn.""" + commands = line.replace("lpmn ", "").split("|") + try: + return [ + x + for x in self.services.keys() + if x.startswith(text) + and x in self.services[commands[-2]]["next"] + ] + except (KeyError, IndexError): + return [x for x in self.services.keys() if x.startswith(text)] + + def complete_services(self, text, line, start, end): + """Autocomplete for service help.""" + return [x for x in self.services.keys() if x.startswith(text)] + def do_exit(self, s): """Exit the application.""" print("\n") diff --git a/lpmn_client/src/requester.py b/lpmn_client/src/requester.py index 3c5187dd0e5c48ab78e828f618dc49af11449121..3a5751deb7093f0c8184496711c388cd1f51f76d 100644 --- a/lpmn_client/src/requester.py +++ b/lpmn_client/src/requester.py @@ -214,3 +214,8 @@ class Requester(object): os.remove("progress.tmp") except FileNotFoundError: return + + def _sync_lpmn_complete(self, url): + req = requests.get(url).content.decode("utf-8") + with open("lpmn_services.yaml", "wt") as f: + f.write(req) diff --git a/lpmn_services.yaml b/lpmn_services.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7bf8f5d15d4f76d858e3d46bcd0ca1bfc0185e51 --- /dev/null +++ b/lpmn_services.yaml @@ -0,0 +1,49 @@ +any2txt: + description: "Changes file format to .txt." + next: + - service1 + - service2 + params: None + +service1: + description: "Service1 description." + next: + - service3 + params: + param1: + default: "true" + type: "bool" + optional: "False" + description: "Param1 description." + param2: + default: "test" + type: "str" + optional: "True" + description: "Param2 description." + param3: + default: "false" + type: "bool" + optional: "True" + description: "Param3 description." + +service2: + description: "Service1 description." + next: + - service3 + params: + param1: + default: "true" + type: "bool" + optional: "False" + description: "Param1 description." + param2: + default: "test" + type: "str" + optional: "True" + description: "Param2 description." + + +service3: + description: "Service3 description." + next: None + params: None \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 663bd1f6a2ae02f29df59fb4963c17934034f731..fda30757b52e142e5b55bb62b8f81808fbe4bb33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -requests \ No newline at end of file +requests +pyyaml \ No newline at end of file diff --git a/setup.py b/setup.py index fd45954c964018306fa137f2334a943196082a1e..acaa2fd43f6ce902c192bd9824b4fbc63df91ea1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="lpmn_client", - version="1.2.3", + version="1.3.0", author="Szymon Ciombor", author_email="Szymon.Ciombor@pwr.edu.pl", description="CLI Client for writing LPMN queries.", @@ -15,6 +15,6 @@ setuptools.setup( python_requires=">=3.6", zip_safe=True, entry_points={"console_scripts": ["lpmn_client=lpmn_client.__main__:main"]}, - install_requires=["requests"], + install_requires=["requests", "pyyaml"], package_data={"lpmn_client": ["config.ini"]}, ) diff --git a/tox.ini b/tox.ini index fee2d442ae8810371da27596a9ad56b4875294a5..8a47cb45edf5798056b2baa4f6d5640c1369d4b4 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ skipsdist = True deps = pytest requests + pyyaml commands = pytest [testenv:pep8]