diff --git a/main.py b/main.py index 831c175..23856a9 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import asyncio import threading +import time from queue import Queue import datetime import json @@ -19,6 +20,7 @@ import zipfile PASSWORD = 'gost_2012$a742ec53198ec2a5027086fba8814a89982a57112d1a72d02260161108f39b50' tasks = Queue() +connected = False def run_tasks(): @@ -27,14 +29,46 @@ def run_tasks(): task() +def replication_task(): + while not connected: + time.sleep(1) + date = datetime.datetime.now() + rxmls = RequestXmlService() + res_id = uuid4().hex + res = rxmls.get_request_document(res_id, None) + res.set('replication_package', '1') + rxmls.set_result(res, 0, '') + response_params = { + 'from': 'tcp://bnd127', + 'to': 'tcp://kptsp_vb', + 'ts_added': date.timestamp(), + 'user_id': '0', + 'query_type': 1114, + 'query_data': ET.tostring(res, encoding='unicode', xml_declaration=True) + } + filename = '51a8a2c81f774af7bba61b475b4b51b5' + filepath = '/tmp/' + filename + response_files = [{'name': filename, 'url': filepath, 'size': os.path.getsize(filepath)}] + logging.info('Send replication package') + proxy = ServerProxy('http://127.0.0.1:7000/xmlrpc') + proxy.send(response_params, response_files, 'http://10.10.8.27:9000/') + + # Expose a function def list_contents(dir_name): - logging.debug('list_contents(%s)', dir_name) + logging.info('list_contents(%s)', dir_name) return os.listdir(dir_name) def aud_add(message): - logging.debug(message) + global connected + if not isinstance(message, list): + logging.warning(message) + return 'OK' + for item in message: + logging.warning(item) + if item.get('level', -1) == 0 and item.get('type', -1) == 4002: + connected = True return 'OK' @@ -56,7 +90,7 @@ def restore_uuid(oid): def load_catalog(params, files, url): - print('load_catalog') + logging.debug('load_catalog') date = datetime.datetime.now() rxmls = RequestXmlService() req = ET.fromstring(params['query_data']) @@ -74,7 +108,7 @@ def load_catalog(params, files, url): 'query_data': ET.tostring(res, encoding='unicode', xml_declaration=True) } catalog = get_catalog() - print('Catalog_loaded') + logging.debug('Catalog_loaded') filename = uuid4().hex filepath = '/tmp/' + filename zipf = zipfile.ZipFile(filepath, "w") @@ -191,17 +225,17 @@ def accept(params, files, url): def onSent(params, files, callback_url): - print('onSent') + logging.debug('onSent') def onDelivered(params, files, callback_url): - print('onDelivered') + logging.debug('onDelivered') def main(): - print('Use Control-C to exit') + logging.debug('Use Control-C to exit') logging.basicConfig(level=logging.DEBUG) - server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=True, allow_none=True) + server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=False, allow_none=True) server.register_function(list_contents) server.register_function(aud_add) server.register_function(auth_response) @@ -213,10 +247,13 @@ def main(): thread = threading.Thread(target=run_tasks) thread.start() + replication_thread = threading.Thread(target=replication_task) + replication_thread.start() + try: server.serve_forever() except KeyboardInterrupt: - print('Exiting') + logging.debug('Exiting') def test():