log fixed and py files name changed according to PEP8 standart

This commit is contained in:
Volkan Şahin 2016-08-24 18:05:54 +03:00
parent 2cc5cc9950
commit 1d4429949f
34 changed files with 183 additions and 136 deletions

View file

@ -1,4 +1,8 @@
from base.Scope import Scope
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
from base.scope import Scope
from base.util.util import Util
from base.system.system import System
@ -18,7 +22,7 @@ class Agreement:
self.logger.debug('[Agreement] Requested updated agreement contract from lider.')
def check_agreement(self, username):
self.logger.debug('[Agreement] Checking agreement for user {}.'.format(username))
self.logger.debug('[Agreement] Checking agreement for user {0}.'.format(username))
contract_id = self.get_current_contract_id()
if contract_id is None:
self.logger.debug('[Agreement] There is no any contract in database.')
@ -66,23 +70,23 @@ class Agreement:
pout = str(p_out).replace('\n', '')
if pout != 'Error':
if pout == 'Y':
self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username))
self.logger.debug('[Agreement] Agreement was accepted by {0}.'.format(username))
self.db_service.update('agreement', self.db_service.get_cols('agreement'),
[contract_id, username, Util.timestamp(), 'Y'])
elif pout == 'N':
self.db_service.update('agreement', self.db_service.get_cols('agreement'),
[contract_id, username, Util.timestamp(), 'N'])
self.logger.debug(
'[Agreement] Agreement was ignored by {}. Session will be closed'.format(username))
'[Agreement] Agreement was ignored by {0}. Session will be closed'.format(username))
else:
self.logger.error(
'[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout)))
'[Agreement] A problem occurred while executing ask.py. Error Message: {0}'.format(str(pout)))
Util.delete_file(agreement_path)
else:
self.logger.error(
'[Agreement] A problem occurred while executing ask.py (Probably argument fault). Error Message: {}'.format(
'[Agreement] A problem occurred while executing ask.py (Probably argument fault). Error Message: {0}'.format(
str(pout)))
except Exception as e:
self.logger.error(
'[Agreement] A Problem occurred while displaying agreement. Error Message: {}'.format(str(e)))
'[Agreement] A Problem occurred while displaying agreement. Error Message: {0}'.format(str(e)))

View file

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import sys
import easygui

View file

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import sys
import easygui

View file

@ -1,15 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import configparser
import datetime
import json
import os
import queue as Queue
import threading
import ast
from base.command.fifo import Fifo
from base.model.enum.ContentType import ContentType
from base.model.enum.MessageCode import MessageCode
from base.model.enum.MessageType import MessageType
from base.model.enum.content_type import ContentType
from base.model.enum.message_code import MessageCode
from base.model.enum.message_type import MessageType
from base.system.system import System
from base.util.util import Util
@ -24,7 +28,7 @@ class Commander(object):
print('ERR')
params = args[0]
data = {}
data = dict()
if System.Ahenk.is_running() is True:
@ -63,7 +67,7 @@ class Commander(object):
elif len(params) > 5 and params[1] == 'send':
data['event'] = params[1]
response = {}
response = dict()
response['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
response['responseMessage'] = 'This content was sent via ahenk terminal command'
@ -199,14 +203,14 @@ class Commander(object):
config.read(System.Ahenk.config_path())
db_path = config.get('BASE', 'dbPath')
if Util.is_exist('/tmp/liderahenk.fifo'):
Util.delete_file('/tmp/liderahenk.fifo')
if Util.is_exist(System.Ahenk.fifo_file()):
Util.delete_file(System.Ahenk.fifo_file())
if os.path.exists(db_path):
os.remove(db_path)
# TODO remove pid file
if Util.is_exist(db_path):
Util.delete_file(db_path)
if Util.is_exist(System.Ahenk.pid_path()):
Util.delete_file(System.Ahenk.pid_path())
config.set('CONNECTION', 'uid', '')
config.set('CONNECTION', 'password', '')
@ -216,7 +220,7 @@ class Commander(object):
file.close()
print('Ahenk cleaned.')
except Exception as e:
print('Error while running clean command. Error Message {}'.format(str(e)))
print('Error while running clean command. Error Message {0}'.format(str(e)))
def status(self):
ahenk_state = False

View file

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import threading
@ -13,7 +17,7 @@ class Fifo(object):
file = open(self.path, 'a+')
file.write(content)
except Exception as e:
print('Error:{}'.format(str(e)))
print('Error:{0}'.format(str(e)))
finally:
file.close()
self.lock.release()
@ -29,7 +33,7 @@ class Fifo(object):
w_file.writelines(lines[1:])
w_file.close()
except Exception as e:
print('Error:{}'.format(str(e)))
print('Error:{0}'.format(str(e)))
finally:
self.lock.release()
queue.put(result)

View file

@ -4,7 +4,7 @@
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import sqlite3
from base.Scope import Scope
from base.scope import Scope
class AhenkDbService(object):

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# @author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.event.EventBase import EventBase, Event
from base.event.event_base import EventBase, Event
class EventManager(EventBase):

View file

@ -4,16 +4,16 @@
import json
from base.Scope import Scope
from base.scope import Scope
from base.file.file_transfer_manager import FileTransferManager
from base.model.PluginBean import PluginBean
from base.model.PolicyBean import PolicyBean
from base.model.ProfileBean import ProfileBean
from base.model.Response import Response
from base.model.TaskBean import TaskBean
from base.model.enum.MessageCode import MessageCode
from base.model.enum.MessageType import MessageType
from base.model.enum.ContentType import ContentType
from base.model.plugin_bean import PluginBean
from base.model.policy_bean import PolicyBean
from base.model.profile_bean import ProfileBean
from base.model.response import Response
from base.model.task_bean import TaskBean
from base.model.enum.message_code import MessageCode
from base.model.enum.message_type import MessageType
from base.model.enum.content_type import ContentType
from base.system.system import System
from base.util.util import Util
@ -34,7 +34,7 @@ class ExecutionManager(object):
self.db_service = scope.getDbService()
self.message_manager = scope.getMessageManager()
self.plugin_manager = scope.getPluginManager()
self.policy_executed = {}
self.policy_executed = dict()
self.event_manager.register_event(MessageType.EXECUTE_SCRIPT.value, self.execute_script)
self.event_manager.register_event(MessageType.EXECUTE_TASK.value, self.execute_task)
@ -65,7 +65,7 @@ class ExecutionManager(object):
[agreement_content, title, json_data['timestamp']])
except Exception as e:
self.logger.warning(
'[ExecutionManager] A problem occurred while updating agreement. Error Message : {}'.format(str(e)))
'[ExecutionManager] A problem occurred while updating agreement. Error Message : {0}'.format(str(e)))
def install_plugin(self, arg):
plugin = json.loads(arg)
@ -82,7 +82,7 @@ class ExecutionManager(object):
downloaded_file = System.Ahenk.received_dir_path() + file_name
except Exception as e:
self.logger.error(
'[ExecutionManager] Plugin package could not fetch. Error Message: {}.'.format(str(e)))
'[ExecutionManager] Plugin package could not fetch. Error Message: {0}.'.format(str(e)))
self.logger.error('[ExecutionManager] Plugin Installation is cancelling')
self.plugin_installation_failure(plugin_name, plugin_version)
return
@ -91,7 +91,7 @@ class ExecutionManager(object):
Util.install_with_gdebi(downloaded_file)
self.logger.debug('[ExecutionManager] Plugin installed.')
except Exception as e:
self.logger.error('[ExecutionManager] Could not install plugin. Error Message: {}'.format(str(e)))
self.logger.error('[ExecutionManager] Could not install plugin. Error Message: {0}'.format(str(e)))
self.plugin_installation_failure(plugin_name, plugin_version)
return
@ -99,13 +99,11 @@ class ExecutionManager(object):
Util.delete_file(downloaded_file)
self.logger.debug('[ExecutionManager] Temp files were removed.')
except Exception as e:
self.logger.error('[ExecutionManager] Could not remove temp file. Error Message: {}'.format(str(e)))
# self.plugin_manager.load_single_plugin(plugin_name)
self.logger.error('[ExecutionManager] Could not remove temp file. Error Message: {0}'.format(str(e)))
except Exception as e:
self.logger.error(
'[ExecutionManager] A problem occurred while installing new Ahenk plugin. Error Message:{}'.format(
'[ExecutionManager] A problem occurred while installing new Ahenk plugin. Error Message:{0}'.format(
str(e)))
def plugin_installation_failure(self, plugin_name, plugin_version):
@ -169,7 +167,7 @@ class ExecutionManager(object):
self.policy_executed[username] = False
def execute_default_policy(self, username):
self.logger.debug('[ExecutionManager] Executing active policies for {} user...'.format(username))
self.logger.debug('[ExecutionManager] Executing active policies for {0} user...'.format(username))
self.task_manager.addPolicy(self.get_active_policies(username))
def execute_policy(self, arg):
@ -316,7 +314,7 @@ class ExecutionManager(object):
json_server_conf = json.dumps(json.loads(arg)['fileServerConf'])
task = self.json_to_task_bean(json_task, json_server_conf)
self.logger.debug('[ExecutionManager] Adding new task...Task is:{}'.format(task.get_command_cls_id()))
self.logger.debug('[ExecutionManager] Adding new task...Task is:{0}'.format(task.get_command_cls_id()))
self.task_manager.addTask(task)
self.logger.debug('[ExecutionManager] Task added')
@ -343,7 +341,7 @@ class ExecutionManager(object):
self.logger.debug('[ExecutionManager] Executed script')
data = {}
data = dict()
data['type'] = 'SCRIPT_RESULT'
data['timestamp'] = str(Util.timestamp())
@ -389,7 +387,7 @@ class ExecutionManager(object):
messenger.send_direct_message(json.dumps(data))
except Exception as e:
self.logger.error(
'[ExecutionManager] A problem occurred while running execute script action. Error Message :{}'.format(
'[ExecutionManager] A problem occurred while running execute script action. Error Message :{0}'.format(
str(e)))
def json_to_PolicyBean(self, json_data):

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
from base.Scope import Scope
from base.scope import Scope
from base.file.ssh_file_transfer import Ssh
from base.file.http_file_transfer import Http
@ -22,9 +22,11 @@ class FileTransferManager(object):
elif str(protocol).lower() == 'http':
transporter = Http(parameter_map)
else:
raise Exception('Unsupported file transfer protocol: {}'.format(str(protocol)))
raise Exception('Unsupported file transfer protocol: {0}'.format(str(protocol)))
return transporter
except Exception as e:
self.logger.error('[FileTransferManager] A problem occurred while getting instance of related protocol. Error Message: {}'.format(str(e)))
self.logger.error(
'[FileTransferManager] A problem occurred while getting instance of related protocol. Error Message: {0}'.format(
str(e)))
return None

View file

@ -5,7 +5,7 @@ from base.util.util import Util
from base.system.system import System
import urllib.request
from base.Scope import Scope
from base.scope import Scope
class Http(object):
@ -17,7 +17,8 @@ class Http(object):
try:
self.url = parameter_map['url']
except Exception as e:
self.logger.error('[Http] A problem occurred while parsing parameter map. Error Message: {}'.format(str(e)))
self.logger.error(
'[Http] A problem occurred while parsing parameter map. Error Message: {0}'.format(str(e)))
def send_file(self, local_path, md5):
pass
@ -34,7 +35,8 @@ class Http(object):
Util.rename_file(local_full_path, System.Ahenk.received_dir_path() + file_md5)
self.logger.debug('[FileTransfer] File was downloaded to {0} from {1}'.format(local_full_path, self.url))
except Exception as e:
self.logger.error('[FileTransfer] A problem occurred while downloading file. Exception message: {}'.format(str(e)))
self.logger.error(
'[FileTransfer] A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
raise
return file_md5

View file

@ -4,7 +4,7 @@
from base.util.util import Util
from base.system.system import System
from base.Scope import Scope
from base.scope import Scope
import paramiko
import logging
@ -29,7 +29,8 @@ class Ssh(object):
else:
self.p_key = parameter_map['pkey']
except Exception as e:
self.logger.error('[Ssh] A problem occurred while parsing ssh connection parameters. Error Message: {}'.format(str(e)))
self.logger.error(
'[Ssh] A problem occurred while parsing ssh connection parameters. Error Message: {0}'.format(str(e)))
self.connection = None
self.logger.debug('[Ssh] Parameters set up')
@ -49,7 +50,7 @@ class Ssh(object):
self.logger.debug('[Ssh] File was sent to {0} from {1}'.format(local_path, self.target_path))
return True
except Exception as e:
self.logger.error('[Ssh] A problem occurred while sending file. Exception message: {}'.format(str(e)))
self.logger.error('[Ssh] A problem occurred while sending file. Exception message: {0}'.format(str(e)))
return False
def get_file(self):
@ -64,19 +65,21 @@ class Ssh(object):
Util.rename_file(local_full_path, System.Ahenk.received_dir_path() + file_md5)
self.logger.debug('[Ssh] File was downloaded to {0} from {1}'.format(local_full_path, self.target_path))
except Exception as e:
self.logger.error('[Ssh] A problem occurred while downloading file. Exception message: {}'.format(str(e)))
self.logger.error('[Ssh] A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
raise
return file_md5
def connect(self):
self.logger.debug('[FileTransfer] Connecting to {} via {}'.format(self.target_hostname, self.target_port))
self.logger.debug('[FileTransfer] Connecting to {0} via {1}'.format(self.target_hostname, self.target_port))
try:
connection = paramiko.Transport(self.target_hostname, int(self.target_port))
connection.connect(username=self.target_username, password=self.target_password, pkey=self.p_key)
self.connection = connection
self.logger.debug('[FileTransfer] Connected.')
except Exception as e:
self.logger.error('[FileTransfer] A problem occurred while connecting to {} . Exception message: {}'.format(self.target_hostname, str(e)))
self.logger.error(
'[FileTransfer] A problem occurred while connecting to {0} . Exception message: {1}'.format(
self.target_hostname, str(e)))
def disconnect(self):
self.connection.close()

View file

@ -4,7 +4,7 @@
import logging
import logging.config
from base.Scope import Scope
from base.scope import Scope
class Logger(object):

View file

@ -4,10 +4,10 @@
import logging
import logging.config
from base.Scope import Scope
from base.scope import Scope
class AhenkLogger(object):
class AAAAAAAhenkLogger(object):
"""docstring for Logger"""
def __init__(self):

View file

@ -4,7 +4,7 @@
import threading
from base.Scope import Scope
from base.scope import Scope
class MessageResponseQueue(threading.Thread):

View file

@ -5,7 +5,7 @@ import datetime
import json
from base.system.system import System
from base.Scope import Scope
from base.scope import Scope
from base.util.util import Util
@ -19,7 +19,7 @@ class Messaging(object):
self.event_manger = scope.getEventManager()
def missing_plugin_message(self, plugin):
data = {}
data = dict()
data['type'] = 'MISSING_PLUGIN'
data['pluginName'] = plugin.get_name()
data['pluginVersion'] = plugin.get_version()
@ -29,7 +29,7 @@ class Messaging(object):
return str(json_data)
def task_status_msg(self, response):
data = {}
data = dict()
data['type'] = response.get_type()
data['taskId'] = response.get_id()
data['responseCode'] = response.get_code()
@ -46,7 +46,7 @@ class Messaging(object):
return str(json_data)
def policy_status_msg(self, response):
data = {}
data = dict()
data['type'] = response.get_type()
data['policyVersion'] = response.get_policy_version()
data['commandExecutionId'] = response.get_execution_id()
@ -66,7 +66,7 @@ class Messaging(object):
return str(json_data)
def login_msg(self, username):
data = {}
data = dict()
data['type'] = 'LOGIN'
data['username'] = username
data['ipAddresses'] = str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '')
@ -76,7 +76,7 @@ class Messaging(object):
return json_data
def logout_msg(self, username):
data = {}
data = dict()
data['type'] = 'LOGOUT'
data['username'] = str(username)
data['timestamp'] = Util.timestamp()
@ -85,7 +85,7 @@ class Messaging(object):
return json_data
def policy_request_msg(self, username):
data = {}
data = dict()
data['type'] = 'GET_POLICIES'
user_policy_number = self.db_service.select_one_result('policy', 'version', 'type = \'U\' and name = \'' + username + '\'')
@ -101,7 +101,7 @@ class Messaging(object):
return json_data
def registration_msg(self):
data = {}
data = dict()
data['type'] = 'REGISTER'
data['from'] = self.db_service.select_one_result('registration', 'jid', ' 1=1')
data['password'] = self.db_service.select_one_result('registration', 'password', ' 1=1')
@ -119,7 +119,7 @@ class Messaging(object):
return json_data
def ldap_registration_msg(self):
data = {}
data = dict()
data['type'] = 'REGISTER_LDAP'
data['from'] = str(self.conf_manager.get('REGISTRATION', 'from'))
data['password'] = str(self.conf_manager.get('REGISTRATION', 'password'))
@ -132,7 +132,7 @@ class Messaging(object):
return json_data
def unregister_msg(self):
data = {}
data = dict()
data['type'] = 'UNREGISTER'
data['from'] = str(self.conf_manager.get('REGISTRATION', 'from'))
data['password'] = str(self.conf_manager.get('REGISTRATION', 'password'))
@ -146,7 +146,7 @@ class Messaging(object):
return json_data
def agreement_request_msg(self):
data = {}
data = dict()
data['type'] = 'REQUEST_AGREEMENT'
"""
@ -163,7 +163,7 @@ class Messaging(object):
return json_data
def agreement_answer_msg(self, username, answer):
data = {}
data = dict()
data['type'] = 'AGREEMENT_STATUS'
data['username'] = username
data['accepted'] = answer

View file

@ -4,7 +4,7 @@
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import json
from base.model.Profile import Profile
from base.model.profile import Profile
class Policy(object):

View file

@ -73,7 +73,7 @@ class TaskBean(object):
self.file_server = file_server
def to_json(self):
plugin_data = {}
plugin_data = dict()
plugin_data['id'] = self.plugin.get_id()
plugin_data['name'] = self.plugin.get_name()
plugin_data['version'] = self.plugin.get_version()
@ -88,7 +88,7 @@ class TaskBean(object):
plugin_data['createDate'] = self.plugin.get_create_date()
plugin_data['modifyDate'] = self.plugin.get_modify_date()
task_data = {}
task_data = dict()
task_data['id'] = self._id
task_data['plugin'] = plugin_data
task_data['commandClsId'] = self.command_cls_id

View file

@ -6,19 +6,19 @@
import json
import threading
from base.Scope import Scope
from base.scope import Scope
from base.file.file_transfer_manager import FileTransferManager
from base.model.Response import Response
from base.model.enum.ContentType import ContentType
from base.model.enum.MessageCode import MessageCode
from base.model.enum.MessageType import MessageType
from base.model.response import Response
from base.model.enum.content_type import ContentType
from base.model.enum.message_code import MessageCode
from base.model.enum.message_type import MessageType
from base.system.system import System
from base.util.util import Util
class Context(object):
def __init__(self):
self.data = {}
self.data = dict()
self.scope = Scope().getInstance()
def put(self, var_name, data):
@ -31,7 +31,7 @@ class Context(object):
return self.data['username']
def empty_data(self):
self.data = {}
self.data = dict()
def create_response(self, code, message=None, data=None, content_type=None):
self.data['responseCode'] = code
@ -69,7 +69,7 @@ class Plugin(threading.Thread):
obj_name = item_obj.obj_name
except Exception as e:
self.logger.error(
'[Plugin] A problem occurred while executing process. Error Message: {}'.format(str(e)))
'[Plugin] A problem occurred while executing process. Error Message: {0}'.format(str(e)))
if obj_name == "TASK":
self.logger.debug('[Plugin] Executing task')
@ -112,7 +112,7 @@ class Plugin(threading.Thread):
file_manager.transporter.disconnect()
except Exception as e:
self.logger.error(
'[Plugin] A problem occurred while file transferring. Error Message :{}'.format(
'[Plugin] A problem occurred while file transferring. Error Message :{0}'.format(
str(e)))
self.logger.debug('[Plugin] Sending response')
@ -180,7 +180,7 @@ class Plugin(threading.Thread):
file_manager.transporter.disconnect()
except Exception as e:
self.logger.error(
'[Plugin] A problem occurred while file transferring. Error Message :{}'.format(
'[Plugin] A problem occurred while file transferring. Error Message :{0}'.format(
str(e)))
self.logger.debug('[Plugin] Sending response')
@ -217,7 +217,7 @@ class Plugin(threading.Thread):
self.logger.debug('[Plugin] {0} plugin is stopping...'.format(str(self.name)))
self.keep_run = False
else:
self.logger.warning("[Plugin] Not supported object type: {}".format(str(obj_name)))
self.logger.warning("[Plugin] Not supported object type: {0}".format(str(obj_name)))
self.context.empty_data()
except Exception as e:
@ -225,18 +225,18 @@ class Plugin(threading.Thread):
def get_execution_id(self, profile_id):
try:
return self.db_service.select_one_result('policy', 'execution_id', ' id={}'.format(profile_id))
return self.db_service.select_one_result('policy', 'execution_id', ' id={0}'.format(profile_id))
except Exception as e:
self.logger.error(
"[Plugin] A problem occurred while getting execution id. Exception Message: {} ".format(str(e)))
"[Plugin] A problem occurred while getting execution id. Exception Message: {0} ".format(str(e)))
return None
def get_policy_version(self, profile_id):
try:
return self.db_service.select_one_result('policy', 'version', ' id={}'.format(profile_id))
return self.db_service.select_one_result('policy', 'version', ' id={0}'.format(profile_id))
except Exception as e:
self.logger.error(
"[Plugin] A problem occurred while getting policy version . Exception Message: {} ".format(str(e)))
"[Plugin] A problem occurred while getting policy version . Exception Message: {0} ".format(str(e)))
return None
def getName(self):

View file

@ -3,9 +3,9 @@
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
from base.Scope import Scope
from base.model.enum.ContentType import ContentType
from base.model.enum.MessageCode import MessageCode
from base.scope import Scope
from base.model.enum.content_type import ContentType
from base.model.enum.message_code import MessageCode
from base.system.system import System
from base.util.util import Util
@ -30,7 +30,8 @@ class AbstractPlugin(Util, System):
try:
return Scope.getInstance().getLogger()
except Exception as e:
self.scope.getLogger().error('[AbstractPlugin] A problem occurred while getting logger. Error Message: {}'.format(str(e)))
self.scope.getLogger().error(
'[AbstractPlugin] A problem occurred while getting logger. Error Message: {0}'.format(str(e)))
return None
@ -38,7 +39,9 @@ def configuration_manager(self):
try:
return self.scope.getConfigurationManager()
except Exception as e:
self.logger().error('[AbstractPlugin] A problem occurred while getting configuration manager. Error Message: {}'.format(str(e)))
self.logger().error(
'[AbstractPlugin] A problem occurred while getting configuration manager. Error Message: {0}'.format(
str(e)))
return None

View file

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import os
import signal

View file

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import threading
import time

View file

@ -5,15 +5,15 @@
import imp
import os
from base.Scope import Scope
from base.model.PluginBean import PluginBean
from base.scope import Scope
from base.model.plugin_bean import PluginBean
from base.model.modes.init_mode import InitMode
from base.model.modes.login_mode import LoginMode
from base.model.modes.logout_mode import LogoutMode
from base.model.modes.safe_mode import SafeMode
from base.model.modes.shutdown_mode import ShutdownMode
from base.plugin.Plugin import Plugin
from base.plugin.PluginQueue import PluginQueue
from base.plugin.plugin_queue import PluginQueue
from base.plugin.plugin_install_listener import PluginInstallListener
from base.system.system import System
@ -35,8 +35,8 @@ class PluginManager(object):
# self.listener = \
self.install_listener()
self.delayed_profiles = {}
self.delayed_tasks = {}
self.delayed_profiles = dict()
self.delayed_tasks = dict()
# TODO version?
def load_plugins(self):
@ -45,17 +45,17 @@ class PluginManager(object):
self.logger.debug('[PluginManager] Lookup for possible plugins...')
try:
possible_plugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
self.logger.debug('[PluginManager] Possible plugins: {} '.format(str(possible_plugins)))
self.logger.debug('[PluginManager] Possible plugins: {0} '.format(str(possible_plugins)))
for plugin_name in possible_plugins:
try:
self.load_single_plugin(plugin_name)
except Exception as e:
self.logger.error(
'[PluginManager] Exception occurred while loading plugin ! Plugin name : {}. Error Message: {}'.format(
str(plugin_name), str(e)))
'[PluginManager] Exception occurred while loading plugin ! Plugin name : {0}.'
' Error Message: {1}'.format(str(plugin_name), str(e)))
self.logger.info('[PluginManager] Loaded plugins successfully.')
except Exception as e:
self.logger.warning('[PluginManager] Plugin folder path not found. Error Message: {}'.format(str(e)))
self.logger.warning('[PluginManager] Plugin folder path not found. Error Message: {0}'.format(str(e)))
def load_single_plugin(self, plugin_name):
# TODO check already loaded plugin
@ -63,7 +63,7 @@ class PluginManager(object):
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(
location):
self.logger.debug(
'[PluginManager] It is not a plugin location ! There is no main module - {}'.format(str(location)))
'[PluginManager] It is not a plugin location ! There is no main module - {0}'.format(str(location)))
else:
if self.is_plugin_loaded(plugin_name):
self.logger.debug(
@ -75,7 +75,7 @@ class PluginManager(object):
plugin.setDaemon(True)
plugin.start()
self.plugins.append(plugin)
self.logger.debug('[PluginManager] New plugin was loaded. Plugin Name: {}'.format(plugin_name))
self.logger.debug('[PluginManager] New plugin was loaded. Plugin Name: {0}'.format(plugin_name))
# active init mode
mode = InitMode()
@ -103,10 +103,10 @@ class PluginManager(object):
def reload_single_plugin(self, plugin_name):
try:
self.logger.info('[PluginManager] {} plugin is reloading'.format(plugin_name))
self.logger.debug('[PluginManager] {} plugin is killing (in reloading action)'.format(plugin_name))
self.logger.info('[PluginManager] {0} plugin is reloading'.format(plugin_name))
self.logger.debug('[PluginManager] {0} plugin is killing (in reloading action)'.format(plugin_name))
self.remove_single_plugin(plugin_name)
self.logger.debug('[PluginManager] {} plugin is loading (in reloading action)'.format(plugin_name))
self.logger.debug('[PluginManager] {0} plugin is loading (in reloading action)'.format(plugin_name))
self.load_single_plugin(plugin_name)
except Exception as e:
self.logger.error(
@ -127,18 +127,18 @@ class PluginManager(object):
def remove_single_plugin(self, plugin_name):
try:
self.logger.debug('[PluginManager] Trying to remove {} plugin...'.format(plugin_name))
self.logger.debug('[PluginManager] Trying to remove {0} plugin...'.format(plugin_name))
if self.is_plugin_loaded(plugin_name):
self.logger.debug('[PluginManager] {} plugin is killing...'.format(plugin_name))
self.logger.debug('[PluginManager] {0} plugin is killing...'.format(plugin_name))
self.pluginQueueDict[plugin_name].put(ShutdownMode(), 1)
del self.pluginQueueDict[plugin_name]
for plugin in self.plugins:
if plugin.name == plugin_name:
self.plugins.remove(plugin)
self.logger.debug('[PluginManager] {} plugin was removed.'.format(plugin_name))
self.logger.debug('[PluginManager] {0} plugin was removed.'.format(plugin_name))
else:
self.logger.warning('[PluginManager] {} plugin not found.'.format(plugin_name))
self.logger.warning('[PluginManager] {0} plugin not found.'.format(plugin_name))
except Exception as e:
self.logger.error(
'[PluginManager] A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name,
@ -167,14 +167,14 @@ class PluginManager(object):
self.pluginQueueDict[plugin_name].put(task, 1)
else:
self.logger.warning(
'[PluginManager] {} plugin not found. Task was delayed. Ahenk will request plugin from Lider if distribution available'.format(
'[PluginManager] {0} plugin not found. Task was delayed. Ahenk will request plugin from Lider if distribution available'.format(
plugin_name))
self.delayed_tasks[plugin_name] = task
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
self.messenger.send_direct_message(msg)
except Exception as e:
self.logger.error(
'[PluginManager] Exception occurred while processing task. Error Message: {}'.format(str(e)))
'[PluginManager] Exception occurred while processing task. Error Message: {0}'.format(str(e)))
def find_policy_module(self, plugin_name):
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
@ -233,14 +233,14 @@ class PluginManager(object):
self.pluginQueueDict[plugin_name].put(profile, 1)
else:
self.logger.warning(
'[PluginManager] {} plugin not found. Profile was delayed. Ahenk will request plugin from Lider if distribution available'.format(
'[PluginManager] {0} plugin not found. Profile was delayed. Ahenk will request plugin from Lider if distribution available'.format(
plugin_name))
self.delayed_profiles[plugin_name] = profile
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
self.scope.getMessenger().send_direct_message(msg)
except Exception as e:
self.logger.error(
'[PluginManager] Exception occurred while processing profile. Error Message: {}'.format(str(e)))
'[PluginManager] Exception occurred while processing profile. Error Message: {0}'.format(str(e)))
def check_plugin_exists(self, plugin_name, version=None):
@ -267,16 +267,16 @@ class PluginManager(object):
elif mode_type == 'safe':
mode = SafeMode(username)
else:
self.logger.error('[PluginManager] Unknown mode type: {}'.format(mode_type))
self.logger.error('[PluginManager] Unknown mode type: {0}'.format(mode_type))
if mode is not None:
self.logger.info('[PluginManager] {} mode is running'.format(mode_type))
self.logger.info('[PluginManager] {0} mode is running'.format(mode_type))
for plugin_name in self.pluginQueueDict:
try:
self.pluginQueueDict[plugin_name].put(mode, 1)
except Exception as e:
self.logger.error(
'[PluginManager] Exception occurred while switching safe mode. Error Message : {}'.format(
'[PluginManager] Exception occurred while switching safe mode. Error Message : {0}'.format(
str(e)))
def find_module(self, mode, plugin_name):

View file

@ -7,7 +7,7 @@ import json
import uuid
from uuid import getnode as get_mac
from base.Scope import Scope
from base.scope import Scope
from base.messaging.anonymous_messenger import AnonymousMessenger
from base.system.system import System
from base.timer.setup_timer import SetupTimer

View file

@ -3,7 +3,7 @@
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.scheduler.base_scheduler import BaseScheduler
from base.Scope import Scope
from base.scope import Scope
from base.scheduler.custom.scheduledb import ScheduleTaskDB
from base.scheduler.custom.schedule_job import ScheduleTaskJob
from datetime import datetime, timedelta

View file

@ -3,7 +3,7 @@
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.scheduler.custom.all_match import AllMatch
from base.Scope import Scope
from base.scope import Scope
class ScheduleTaskJob(object):
@ -74,10 +74,10 @@ class ScheduleTaskJob(object):
return cron_sj
except Exception as e:
self.logger.error(
'[ScheduleTaskJob] A problem occurred while parsing cron expression. Error Message: {}'.format(str(e)))
'[ScheduleTaskJob] A problem occurred while parsing cron expression. Error Message: {0}'.format(str(e)))
def conv_to_set(self, obj):
self.logger.debug('[ScheduleTaskJob] Converting {} to set'.format(str(obj)))
self.logger.debug('[ScheduleTaskJob] Converting {0} to set'.format(str(obj)))
if str(obj).isdigit():
return set([int(obj)])

View file

@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.Scope import Scope
from base.model.Task import Task
from base.scope import Scope
from base.model.task import Task
class ScheduleTaskDB(object):

View file

@ -10,7 +10,7 @@ class Scope(object):
def __init__(self):
super(Scope, self).__init__()
self.customMap = {}
self.customMap = dict()
self.configurationManager = None
self.messageManager = None
self.logger = None

View file

@ -13,7 +13,7 @@ import fcntl
import struct
from uuid import getnode as get_mac
from base.util.util import Util
from base.Scope import Scope
from base.scope import Scope
class System:
@ -147,6 +147,10 @@ class System:
def pid_path():
return '/var/run/ahenk.pid'
@staticmethod
def fifo_file():
return '/tmp/liderahenk.fifo'
@staticmethod
def received_dir_path():
path = '/tmp/.ahenk/'
@ -279,7 +283,7 @@ class System:
@staticmethod
def user_home_path(username):
# TODO temp
return '/home/{}/'.format(str(username))
return '/home/{0}/'.format(str(username))
class Os(object):
@ -432,7 +436,7 @@ class System:
def ip_addresses():
arr = []
for iface in psutil.net_io_counters(pernic=True):
f = os.popen('ifconfig {} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface))
f = os.popen('ifconfig {0} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface))
ip = str(f.read()).replace('\n', '')
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$',
ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':

View file

@ -4,7 +4,7 @@
import threading
from base.task.TaskJob import TaskJob
from base.task.task_job import TaskJob
class TaskInQueue(threading.Thread):

View file

@ -3,7 +3,7 @@
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
import threading
from base.Scope import Scope
from base.scope import Scope
class TaskJob(threading.Thread):

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.Scope import Scope
from base.scope import Scope
from base.model.message_factory import MessageFactory
from base.model.enum.message_type import MessageType

View file

@ -1,3 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
class SetupTimer:
@staticmethod

View file

@ -1,3 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import time
import threading

View file

@ -228,7 +228,7 @@ class Util:
@staticmethod
def is_installed(package_name):
result_code, p_out, p_err = Util.execute('dpkg -s {}'.format(package_name))
result_code, p_out, p_err = Util.execute('dpkg -s {0}'.format(package_name))
try:
lines = str(p_out).split('\n')
for line in lines: