agreement operation bug fixes

This commit is contained in:
Volkan Şahin 2016-06-30 12:40:29 +03:00
parent edf0d13082
commit 62041fb649
4 changed files with 21 additions and 14 deletions

View file

@ -1,5 +1,6 @@
from base.Scope import Scope from base.Scope import Scope
from base.util.util import Util from base.util.util import Util
from base.system.system import System
class Agreement: class Agreement:
@ -46,13 +47,14 @@ class Agreement:
title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması' title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması'
contract_id = '-1' contract_id = '-1'
else: else:
content = result[0][0] content = str(result[0][0])
title = result[0][1] title = result[0][1]
contract_id = result[0][2] contract_id = result[0][2]
try: try:
command = 'export DISPLAY={0};python3 {1} \'{2}\' \'{3}\' '.format(display, self.ask_path, content, title) agreement_path = System.Ahenk.received_dir_path() + Util.generate_uuid()
result_code, p_out, p_err = Util.execute(command, as_user=username) Util.write_file(agreement_path, content)
command = 'export DISPLAY={0};su - {1} -c \'python3 {2} \"$(cat {3})\" \"{4}\"\''.format(display, username, self.ask_path, agreement_path, title)
result_code, p_out, p_err = Util.execute(command)
pout = str(p_out).replace('\n', '') pout = str(p_out).replace('\n', '')
if pout != 'Error': if pout != 'Error':
if pout == 'Y': if pout == 'Y':

View file

@ -17,4 +17,4 @@ if __name__ == '__main__':
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
else: else:
print('Error') print('Argument fault. Check your parameters or content of parameters. Parameters: '+str(sys.argv))

View file

@ -59,9 +59,11 @@ class ExecutionManager(object):
transfer_manager.transporter.disconnect() transfer_manager.transporter.disconnect()
agreement_content = Util.read_file(System.Ahenk.received_dir_path() + file_name) agreement_content = Util.read_file(System.Ahenk.received_dir_path() + file_name)
# TODO
title = 'Ahenk Agreement'
if agreement_content is not None and agreement_content != '': if agreement_content is not None and agreement_content != '':
self.db_service.update('contract', self.db_service.get_cols('contract'), [agreement_content, json_data['title'], json_data['timestamp']]) self.db_service.update('contract', self.db_service.get_cols('contract'), [agreement_content, title, json_data['timestamp']])
except Exception as e: except Exception as e:
self.logger.error('[ExecutionManager] A problem occurred while updating agreement. Error Message : {}'.format(str(e))) self.logger.error('[ExecutionManager] A problem occurred while updating agreement. Error Message : {}'.format(str(e)))
@ -212,17 +214,20 @@ class ExecutionManager(object):
str_task = json.loads(arg)['task'] str_task = json.loads(arg)['task']
json_task = json.loads(str_task) json_task = json.loads(str_task)
task = self.json_to_task_bean(json_task)
file_server_conf = None
task = self.json_to_task_bean(json_task, file_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:{}'.format(task.get_command_cls_id()))
self.task_manager.addTask(task) self.task_manager.addTask(task)
self.logger.debug('[ExecutionManager] Task added') self.logger.debug('[ExecutionManager] Task added')
def json_to_task_bean(self, json_data): def json_to_task_bean(self, json_data, file_server_conf=None):
plu = json_data['plugin'] plu = json_data['plugin']
plugin = PluginBean(p_id=plu['id'], active=plu['active'], create_date=plu['createDate'], deleted=plu['deleted'], description=plu['description'], machine_oriented=plu['machineOriented'], modify_date=plu['modifyDate'], name=plu['name'], policy_plugin=plu['policyPlugin'], user_oriented=plu['userOriented'], version=plu['version'], task_plugin=plu['taskPlugin'], x_based=plu['xBased']) plugin = PluginBean(p_id=plu['id'], active=plu['active'], create_date=plu['createDate'], deleted=plu['deleted'], description=plu['description'], machine_oriented=plu['machineOriented'], modify_date=plu['modifyDate'], name=plu['name'], policy_plugin=plu['policyPlugin'], user_oriented=plu['userOriented'], version=plu['version'], task_plugin=plu['taskPlugin'], x_based=plu['xBased'])
return TaskBean(_id=json_data['id'], create_date=json_data['createDate'], modify_date=json_data['modifyDate'], command_cls_id=json_data['commandClsId'], parameter_map=json_data['parameterMap'], deleted=json_data['deleted'], plugin=plugin, cron_str=json_data['cronExpression']) return TaskBean(_id=json_data['id'], create_date=json_data['createDate'], modify_date=json_data['modifyDate'], command_cls_id=json_data['commandClsId'], parameter_map=json_data['parameterMap'], deleted=json_data['deleted'], plugin=plugin, cron_str=json_data['cronExpression'], file_server=json.dumps(file_server_conf))
def move_file(self, arg): def move_file(self, arg):
default_file_path = System.Ahenk.received_dir_path() default_file_path = System.Ahenk.received_dir_path()

View file

@ -16,8 +16,8 @@ class Ssh(object):
self.configuration_manager = scope.getConfigurationManager() self.configuration_manager = scope.getConfigurationManager()
try: try:
self.target_hostname = parameter_map['hostname'] self.target_hostname = parameter_map['host']
self.port = parameter_map['port'] self.port =parameter_map['port']
self.target_username = parameter_map['username'] self.target_username = parameter_map['username']
self.target_path = parameter_map['path'] self.target_path = parameter_map['path']
self.target_password = None self.target_password = None
@ -32,13 +32,13 @@ class Ssh(object):
self.connection = None self.connection = None
self.logger.debug('[FileTransfer] Parameters set up') self.logger.debug('[FileTransfer] Parameters set up')
def send_file(self, local_path, remote_path): def send_file(self, local_path):
self.logger.debug('[FileTransfer] Sending file ...') self.logger.debug('[FileTransfer] Sending file ...')
try: try:
sftp = paramiko.SFTPClient.from_transport(self.connection) sftp = paramiko.SFTPClient.from_transport(self.connection)
sftp.put(local_path, remote_path) sftp.put(local_path, self.target_path)
self.logger.debug('[FileTransfer] File was sent to {} from {}'.format(local_path, remote_path)) self.logger.debug('[FileTransfer] File was sent to {} from {}'.format(local_path, self.target_path))
except Exception as e: except Exception as e:
self.logger.error('[FileTransfer] A problem occurred while sending file. Exception message: {}'.format(str(e))) self.logger.error('[FileTransfer] A problem occurred while sending file. Exception message: {}'.format(str(e)))
finally: finally: