Ahenk/usr/share/ahenk/plugins/file-management/get_file_content.py
2020-04-06 18:13:10 +03:00

43 lines
1.8 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: Hasan Kara <hasan.kara@pardus.org.tr>
from base.plugin.abstract_plugin import AbstractPlugin
import json
class GetFileContent(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):
try:
file_path = self.data['file-path']
file_content = ""
is_file_exists = False
if self.is_exist(file_path):
self.logger.info("File exists: " + file_path)
is_file_exists = True
file_content = self.read_file(file_path)
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Dosya içeriği başarıyla alındı..',
data=json.dumps({'file_exists': is_file_exists, 'file_content': file_content}),
content_type=self.get_content_type().APPLICATION_JSON.value)
else:
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Dosya bulunamadı..',
content_type=self.get_content_type().APPLICATION_JSON.value)
except Exception as e:
self.logger.error(str(e))
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='Dosya içeriği alınırken hata oluştu: {0}'.format(str(e)))
def handle_task(task, context):
plugin = GetFileContent(task, context)
plugin.handle_task()