From 7100a6942fb25d5dfdeaaf76a78abc9dc91cef54 Mon Sep 17 00:00:00 2001 From: agahhulusi Date: Thu, 8 Dec 2022 10:55:10 +0300 Subject: [PATCH] check package version bug fixed --- src/plugins/package-manager/check_package.py | 57 +++++++++++--------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/plugins/package-manager/check_package.py b/src/plugins/package-manager/check_package.py index a8ad1ae..31c4a0a 100644 --- a/src/plugins/package-manager/check_package.py +++ b/src/plugins/package-manager/check_package.py @@ -21,36 +21,45 @@ class CheckPackage(AbstractPlugin): package_version = str((self.data)['packageVersion']) dn = self.Ahenk.dn() res = {} + + result_message = "Paket yüklü" if dn is None: dn = " " + res["package_name"] = package_name + res["dn"] = dn result_code, result, p_err = self.execute('dpkg -s {} | grep Version'.format(package_name)) data = result.split(': ') - self.logger.debug(data) - - if data[0] == 'Version': # Package is installed - if package_version is None or len(package_version) == 0: - result = 1 - res['version'] = data[1] - elif data[1] is not None and (package_version + '\n') in data[ - 1]: # Package version is the same with wanted version + if data: + if data[0] == 'Version' : # Package is installed + if package_version is None or len(package_version) == 0: + self.logger.debug(package_version) + result = 1 + result_message = "Paket yüklü" + res['version'] = data[1] + res["res"] = result + elif package_version is not None and str((package_version + '\n')) == str(data[1]): # Package version is the same with wanted version + result = 1 + result_message = "Paket yüklü" + res['version'] = data[1] + res["res"] = result + else: + self.logger.debug(package_version) + result = 2 + result_message = "Paket farklı veriyonla yüklü" + res['version'] = data[1] + res["res"] = result + else: # Package is not installed result = 0 - res['version'] = data[1] - else: - result = 2 - res['version'] = data[1] - else: # Package is not installed - result = 'Paket yüklü değil' - res['version'] = '' + result_message = "Paket yüklü değil" + res['version'] = '' + res["res"] = result - res["dn"] = dn - res["res"] = result - - self.logger.debug("Result is: - {}".format(result)) - self.context.create_response(code=self.message_code.TASK_PROCESSED.value, - message='{0} - {1}'.format(package_name, result), - data=json.dumps(res), - content_type=self.get_content_type().APPLICATION_JSON.value) - self.logger.debug("Package Info has sent") + self.logger.debug("Result is: - {}".format(result_message)) + self.context.create_response(code=self.message_code.TASK_PROCESSED.value, + message='{0} - {1}'.format(package_name, result_message), + data=json.dumps(res), + content_type=self.get_content_type().APPLICATION_JSON.value) + self.logger.debug("Package Info has sent") except Exception as e: self.logger.debug(str(e)) self.context.create_response(code=self.message_code.TASK_ERROR.value,