From 25bb08b6ca58729455df005e62200aa54975d6f9 Mon Sep 17 00:00:00 2001 From: Marc Serrat Date: Wed, 15 Apr 2020 09:36:29 +0200 Subject: [PATCH] Changed the mechanism to detect operation that avoids limitation that version 1 had to be present --- VERSION | 2 +- apsconnectcli/apsconnect.py | 2 +- apsconnectcli/hub.py | 27 ++++++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 6cb37a8..3af035a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -19.1.3 +19.1.4 diff --git a/apsconnectcli/apsconnect.py b/apsconnectcli/apsconnect.py index a2e4600..3877093 100644 --- a/apsconnectcli/apsconnect.py +++ b/apsconnectcli/apsconnect.py @@ -80,7 +80,7 @@ def install_frontend(self, source, oauth_key, oauth_secret, backend_url, setting connection = hub.get_connections(package.product_id) print("Detected connection {} for this Hub and product {}".format(connection['id'], package.product_id)) - operation = hub.check_package_operation(package, experimental) + operation = hub.check_package_operation(package) update_rts = False if operation == "install": print("Importing connector {} version {}.{}".format(package.connector_id, diff --git a/apsconnectcli/hub.py b/apsconnectcli/hub.py index 4be2e26..ac3a903 100644 --- a/apsconnectcli/hub.py +++ b/apsconnectcli/hub.py @@ -178,24 +178,33 @@ def aps_devel_mode(self, disable=False): osaapi_raise_for_status(r) print("APS Development mode {}.".format('DISABLED' if disable else 'ENABLED')) - def check_package_operation(self, package, experimental): - url = '/aps/2/types?implementing({}/app)'.format(package.connector_id) + def check_package_operation(self, package): + app_id = self.get_application_id(package.connector_id) + if app_id is None: + print("INFO: package is not installed") + return "install" + app_instances = self.get_application_instances(int(app_id)) + if len(app_instances) == 0: + return "install" + url = '/aps/2/resources/{}'.format(app_instances[0]['application_resource_id']) r = self.aps.get(url) try: data = json.loads(r.content.decode('utf-8')) except ValueError: print("APSController provided non-json format") sys.exit(1) - if len(data) == 0: + if 'aps' not in data: print("INFO: package is not installed") return "install" latest = 0 - for type in data: - match = re.match(r'{}/app/(?P\d+)\.0'.format(package.connector_id), type['id']) - if match: - major = int(match.groupdict()['major']) - if int(latest) < major: - latest = major + match = re.match(r'{}/app/(?P\d+)\.0'.format( + package.connector_id), + data['aps']['type'] + ) + if match: + major = int(match.groupdict()['major']) + if int(latest) < major: + latest = major if int(latest) == int(package.version): return "createRTs" elif int(latest) > int(package.version):