From 6654aa63e97ac9d01eeb4ea21aaac58f1400043b Mon Sep 17 00:00:00 2001 From: "mine.dogan" Date: Tue, 14 Jun 2016 17:52:11 +0300 Subject: [PATCH] bug fix --- opt/ahenk/plugins/conky/main.py | 5 +++ opt/ahenk/plugins/conky/policy.py | 62 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 opt/ahenk/plugins/conky/main.py create mode 100644 opt/ahenk/plugins/conky/policy.py diff --git a/opt/ahenk/plugins/conky/main.py b/opt/ahenk/plugins/conky/main.py new file mode 100644 index 0000000..54fac23 --- /dev/null +++ b/opt/ahenk/plugins/conky/main.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +def info(): + return None \ No newline at end of file diff --git a/opt/ahenk/plugins/conky/policy.py b/opt/ahenk/plugins/conky/policy.py new file mode 100644 index 0000000..51b89f6 --- /dev/null +++ b/opt/ahenk/plugins/conky/policy.py @@ -0,0 +1,62 @@ +# !/usr/bin/python +# -*- coding: utf-8 -*- + + +import json + +from base.plugin.abstract_plugin import AbstractPlugin + + +class Conky(AbstractPlugin): + def __init__(self, data, context): + super(Conky, self).__init__() + self.data = data + self.context = context + self.logger = self.get_logger() + self.conky_config_file = '/etc/conky/conky.conf' + self.start_command = "su - {} -c 'conky'" + self.logger.debug('[Conky] Parameters were initialized.') + + def handle_policy(self): + try: + + try: + if self.is_installed('conky') is False: + self.logger.info('[Conky] Could not found Conky. It will be installed') + self.logger.debug('[Conky] Conky installing with using apt-get') + self.install_with_apt_get('conky') + self.logger.info('[Conky] Could installed') + + self.logger.debug('[Conky] Some processes found which names are conky. They will be killed.') + self.execute('killall -9 conky') + except: + self.logger.error('[Conky] Conky install-kill problem.') + raise + + self.create_file('/tmp/conky.conf') + self.logger.debug('[Conky] Temp file was created.') + + self.write_file('/tmp/conky.conf', json.loads(self.data)['message']) + self.logger.debug('[Conky] Temp file was filled by context.') + + self.copy_file('/tmp/conky.conf', '/etc/conky/conky.conf') + self.logger.debug('[Conky] Configurated conf file.') + self.logger.debug('[Conky] Running Conky...') + + if self.context.get('username') != None: + self.execute(self.start_command.format(self.context.get('username')), result=False) + self.logger.debug('[Conky] Creating response.') + self.context.create_response(code=self.get_message_code().POLICY_PROCESSED.value, message='Conky policy executed successfully') + else: + raise Exception('Username: None') + + except Exception as e: + self.logger.error('[Conky] A problem occurred while handling Conky policy. Error Message: {}'.format(str(e))) + self.context.create_response(code=self.get_message_code().POLICY_ERROR.value, message='A problem occurred while handling Conky policy') + + +def handle_policy(profile_data, context): + print('[Conky] Handling...') + plugin = Conky(profile_data, context) + plugin.handle_policy() + print('[Conky] Executed.')