mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
implemented execution manager for lider events
This commit is contained in:
parent
0644a12548
commit
8eac2d6615
1 changed files with 51 additions and 30 deletions
|
@ -1,43 +1,64 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
||||
import sys
|
||||
import logging,subprocess
|
||||
import logging.config
|
||||
|
||||
import subprocess
|
||||
from base.Scope import Scope
|
||||
from base.messaging.MessageSender import MessageSender
|
||||
import hashlib,json,os,stat,shutil
|
||||
|
||||
class ExecutionManager(object):
|
||||
"""docstring for FileTransferManager"""
|
||||
"""docstring for FileTransferManager"""
|
||||
|
||||
def __init__(self):
|
||||
super(ExecutionManager, self).__init__()
|
||||
def __init__(self):
|
||||
super(ExecutionManager, self).__init__()
|
||||
|
||||
scope = Scope.getInstance()
|
||||
self.config_manager = scope.getConfigurationManager()
|
||||
self.event_manager = scope.getEventManager()
|
||||
scope = Scope.getInstance()
|
||||
self.config_manager = scope.getConfigurationManager()
|
||||
self.event_manager = scope.getEventManager()
|
||||
|
||||
self.event_manager.register_event('EXECUTE_TASK',self.execute_task)
|
||||
self.event_manager.register_event('EXECUTE_SCRIPT',self.execute_script)
|
||||
self.event_manager.register_event('SEND_FILE',self.send_file)
|
||||
self.event_manager.register_event('EXECUTE_TASK',self.execute_task)
|
||||
self.event_manager.register_event('EXECUTE_SCRIPT',self.execute_script)
|
||||
self.event_manager.register_event('REQUEST_FILE',self.request_file)
|
||||
self.event_manager.register_event('MOVE_FILE',self.move_file)
|
||||
|
||||
def execute_task(self,arg):
|
||||
print("execute_task")
|
||||
def execute_task(self,arg):
|
||||
#TODO
|
||||
self.logger.debug('[ExecutionManager] Executing task...')
|
||||
|
||||
def execute_script(self,arg):
|
||||
print("execute_script")
|
||||
j = json.loads(arg)
|
||||
msg_id =str(j['id']).lower()
|
||||
file_name =str(j['filePath']).lower()
|
||||
time_stamp=str(j['timestamp']).lower()
|
||||
subprocess.call("/bin/sh "+self.conf_manager.get('CONNECTION', 'receivefileparam')+file_name, shell=True)
|
||||
def move_file(self,arg):
|
||||
default_file_path=self.config_manager.get('CONNECTION', 'receiveFileParam')
|
||||
j = json.loads(arg)
|
||||
#msg_id =str(j['id']).lower()
|
||||
target_file_path =str(j['filepath']).lower()
|
||||
file_name =str(j['filename']).lower()
|
||||
self.logger.debug('[ExecutionManager] %s will be moved to %s' % file_name,target_file_path)
|
||||
shutil.move(default_file_path+file_name,target_file_path+file_name)
|
||||
|
||||
#need to move somewhere else
|
||||
def send_file(self,arg):
|
||||
print("send_file")
|
||||
j = json.loads(arg)
|
||||
msg_id =str(j['id']).lower()
|
||||
file_path =str(j['filePath']).lower()
|
||||
time_stamp=str(j['timestamp']).lower()
|
||||
def execute_script(self,arg):
|
||||
j = json.loads(arg)
|
||||
#msg_id =str(j['id']).lower()
|
||||
file_path =str(j['filepath']).lower()
|
||||
time_stamp=str(j['timestamp']).lower()
|
||||
self.logger.debug('[ExecutionManager] Making executable file (%s) for execution' % file_path)
|
||||
st = os.stat(file_path)
|
||||
os.chmod(file_path, st.st_mode | stat.S_IEXEC)
|
||||
subprocess.call("/bin/sh "+file_path, shell=True)
|
||||
|
||||
message_sender=MessageSender(None,file_path)
|
||||
message_sender.connect_to_server()
|
||||
#need to move somewhere else
|
||||
def request_file(self,arg):
|
||||
j = json.loads(arg)
|
||||
#msg_id =str(j['id']).lower()
|
||||
file_path =str(j['filepath']).lower()
|
||||
time_stamp=str(j['timestamp']).lower()
|
||||
self.logger.debug('[ExecutionManager] Requested file is '+file_path)
|
||||
message_sender=MessageSender(None,file_path)
|
||||
message_sender.connect_to_server()
|
||||
|
||||
def get_md5_file(self,fname):
|
||||
self.logger.debug('[ExecutionManager] md5 hashing')
|
||||
hash_md5 = hashlib.md5()
|
||||
with open(fname, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(4096), b""):
|
||||
hash_md5.update(chunk)
|
||||
return str(hash_md5.hexdigest())
|
||||
|
|
Loading…
Reference in a new issue