Ahenk/usr/share/ahenk/plugins/package-manager/package_archive.py
2020-04-06 18:13:10 +03:00

44 lines
2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: Cemre ALPSOY <cemre.alpsoy@agem.com.tr>
from base.plugin.abstract_plugin import AbstractPlugin
class PackageArchive(AbstractPlugin):
def __init__(self, data, context):
super(AbstractPlugin, self).__init__()
self.data = data
self.context = context
self.logger = self.get_logger()
self.message_code = self.get_message_code()
def handle_task(self):
self.logger.debug('Handling Package Archive Task')
try:
resultMessage = ''
package_name = str((self.data)['packageName'])
package_version = str((self.data)['packageVersion'])
self.logger.debug("Installing new package... {0}".format(package_name))
result_code, p_result, p_err = self.install_with_apt_get(package_name, package_version)
if result_code == 0:
resultMessage += 'Paket başarıyla kuruldu - {0}={1}'.format(package_name, package_version)
self.logger.debug(resultMessage)
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message=resultMessage)
else:
self.logger.debug(resultMessage)
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='Önceki paket sürümü kurulumunda beklenmedik hata!',
content_type=self.get_content_type().APPLICATION_JSON.value)
except Exception as e:
self.logger.debug(str(e))
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='Önceki paket sürümü kurulumunda beklenmedik hata!',
content_type=self.get_content_type().APPLICATION_JSON.value)
def handle_task(task, context):
plugin = PackageArchive(task, context)
plugin.handle_task()