Index: cloud_sync.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloud_sync.py (.../cloud_sync.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloud_sync.py (.../cloud_sync.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of CloudSync controller""" + import argparse import logging import socket @@ -15,12 +17,11 @@ from cloudsync.busses.file_input_bus import FileInputBus from cloudsync.utils.heartbeat import HeartBeatProvider -VERSION = "0.2.3" +VERSION = "0.2.4" arguments = sys.argv log_level = int(arguments[1]) - logging.basicConfig(filename='cloudsync.log', level=log_level) app = Flask(__name__) @@ -69,12 +70,12 @@ @api.route("/version") class Version(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def get(self): app.logger.info("Received /version HTTP request") return { "version": VERSION - }, 200 + }, OK @api.route("/credentials") @@ -87,8 +88,8 @@ }) @api.doc(body=FIELD_CREDENTIALS, validate=True) - @api.response(200, "Success") - @api.response(400, "Validation Error") + @api.response(OK, "Success") + @api.response(BAD_REQUEST, "Validation Error") def put(self): """ 4. Update the device's certificate and keys @@ -107,7 +108,7 @@ if public_key is None: invalid_params.append("public_key") if len(invalid_params) > 0: - return {"invalidAttributes": invalid_params}, 400 + return {"invalidAttributes": invalid_params}, BAD_REQUEST r = NetworkRequest(request_type=NetworkRequestType.MFT2CS_REQ_SET_CREDENTIALS, url=request.url, @@ -119,13 +120,13 @@ return { "invalidAttributes": [], - }, 200 + }, OK @api.route("/validate") class Validate(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def head(self): """ 5. Initiate device connectivity test @@ -142,13 +143,13 @@ network_request_handler.enqueue_request(r) # no body is returned - return {}, 200 + return {}, OK @api.route("/reset") class Reset(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def head(self): """ 13. Initiate a factory reset @@ -168,32 +169,32 @@ heartbeat_provider.send_heartbeat = True - return {}, 200 + return {}, OK # END - REGISTRATION ENDPOINTS @api.route("/config") class Config(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def get(self): """ Get the current json config """ app.logger.info("Received /config HTTP request") - return g_config, 200 + return g_config, OK @api.route("/token") class Config(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def get(self): """ Get the currently stored token """ app.logger.info("Received /token HTTP request") - return helpers_read_access_token(DEVICE_KEBORMED_ACCESS_TOKEN_PATH), 200 + return helpers_read_access_token(DEVICE_KEBORMED_ACCESS_TOKEN_PATH), OK @api.route("/logs") Index: cloudsync/busses/file_input_bus.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/busses/file_input_bus.py (.../file_input_bus.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/busses/file_input_bus.py (.../file_input_bus.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of an Input Bus based on the Linux file system and iNotify library""" + from logging import Logger from threading import Event, Thread from time import time, sleep @@ -8,8 +10,23 @@ class FileInputBus: - def __init__(self, logger: Logger, file_channels_path: str, input_channel_name: str, g_config: dict, message_handler: UICSMessageHandler): + """File Input Bus class that monitors, parses and sends upstream all inbound messages""" + def __init__(self, + logger: Logger, + file_channels_path: str, + input_channel_name: str, + g_config: dict, + message_handler: UICSMessageHandler): + """ + Initialize the File Input Bus. + :param Logger logger: Logger object + :param str file_channels_path: the path where the bus files are located + :param str input_channel_name: the name of the input channel file + :param dict g_config: the system configuration object + :param UICSMessageHandler message_handler: the upstream message handler + """ + self.last_input_message_id = 0 self.logger = logger @@ -26,6 +43,9 @@ self.thread.start() def input_channel_handler(self): + """ + The Input Channel Handler - it parses and sends upstream all messages arriving on the File Input Bus + """ for event in self.i.event_gen(yield_nones=False): (_, type_names, path, filename) = event # self.logger.debug("PATH=[{}] FILENAME=[{}] EVENT_TYPES={}".format(path, filename, type_names)) Index: cloudsync/busses/file_output_bus.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/busses/file_output_bus.py (.../file_output_bus.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/busses/file_output_bus.py (.../file_output_bus.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,12 +1,25 @@ +"""Implementation of an Output Bus based on the Linux file system""" + from logging import Logger from collections import deque from threading import Event, Thread import datetime class FileOutputBus: + """File Output Bus class that receives, parses and sends downstream all outbound messages""" + def __init__(self, + logger: Logger, + max_size, + file_channels_path: str): + """ + Initialize the File Input Bus. - def __init__(self, logger: Logger, max_size, file_channels_path: str): + :param Logger logger: Logger object + :param max_size: the maximum size of the message queue for the Output Bus + :type max_size: int + :param str file_channels_path: the path where the bus files are located + """ self.last_output_message_id = 1 @@ -31,9 +44,11 @@ self.handle_message(message_body) self.event.clear() - def enqueue_message(self, message_body: str) -> bool: + def enqueue_message(self, + message_body: str) -> bool: """ - :param message_body: the data to add to the queue + Adds messages to the queue + :param str message_body: the data to add to the queue :return: True upon success, False otherwise """ if len(self.queue) < self.queue.maxlen: @@ -43,7 +58,12 @@ else: return False - def handle_message(self, message_body: str): + def handle_message(self, + message_body: str): + """ + Parses queue messages and send them downstream + :param str message_body: the message body + """ print('Message body: {0}'.format(message_body)) self.logger.debug('Message body: {0}'.format(message_body)) Index: cloudsync/common/enums.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/common/enums.py (.../enums.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/common/enums.py (.../enums.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of all enumerations used in the application""" + from enum import Enum, unique Index: cloudsync/config/config.json =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/config/config.json (.../config.json) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/config/config.json (.../config.json) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,18 +1,18 @@ { "kebormed_paas": { - "idp_client_secret": "94bf9193-4beb-4b3b-b973-5ee807d1b3a3", - "url_mft": "http://192.168.10.216:3000", - "url_dcs": "https://device-api.diality.qa.kebormed.com", - "url_device_identity": "https://device-identity.diality.qa.kebormed.com:31400/auth/realms/Main/protocol/openid-connect/token", + "idp_client_secret": "", + "url_mft": "", + "url_dcs": "", + "url_device_identity": "", "dia_org_id": 1 }, "device": { - "ip": "192.168.10.153", - "port": 80, - "name": "hd-HD_Serial_00006", - "hd_serial": "hd-HD_Serial_00006", - "dg_serial": "dg-DG_Serial_00006", - "sw_version": "develop.06011728", + "ip": "", + "port": 5001, + "name": "", + "hd_serial": "", + "dg_serial": "", + "sw_version": "", "mode": "registration", "device_state": "INACTIVE_NOT_OK" } Index: cloudsync/config/config_INT.json =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/config/config_INT.json (.../config_INT.json) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/config/config_INT.json (.../config_INT.json) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,18 +1,18 @@ { "kebormed_paas": { - "idp_client_secret": "94bf9193-4beb-4b3b-b973-5ee807d1b3a3", - "url_mft": "http://192.168.10.83", + "idp_client_secret": "cccd502d-67d0-45e5-ab44-5e7b6119150b", + "url_mft": "", "url_dcs": "https://device-api.diality.integration.kebormed.com", "url_device_identity": "https://device-identity.diality.integration.kebormed.com:31400/auth/realms/Main/protocol/openid-connect/token", "dia_org_id": 1 }, "device": { - "ip": "192.168.10.153", + "ip": "", "port": 5001, - "name": "hd-HD_Serial_00006", - "hd_serial": "hd-HD_Serial_00006", - "dg_serial": "dg-DG_Serial_00006", - "sw_version": "develop.06011728", + "name": "", + "hd_serial": "", + "dg_serial": "", + "sw_version": "", "mode": "registration", "device_state": "INACTIVE_NOT_OK" } Index: cloudsync/config/config_QA.json =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/config/config_QA.json (.../config_QA.json) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/config/config_QA.json (.../config_QA.json) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,18 +1,18 @@ { "kebormed_paas": { "idp_client_secret": "94bf9193-4beb-4b3b-b973-5ee807d1b3a3", - "url_mft": "http://192.168.10.216:3000", + "url_mft": "", "url_dcs": "https://device-api.diality.qa.kebormed.com", "url_device_identity": "https://device-identity.diality.qa.kebormed.com:31400/auth/realms/Main/protocol/openid-connect/token", "dia_org_id": 1 }, "device": { - "ip": "192.168.10.153", + "ip": "", "port": 5001, - "name": "hd-HD_Serial_00006", - "hd_serial": "hd-HD_Serial_00006", - "dg_serial": "dg-DG_Serial_00006", - "sw_version": "develop.06011728", + "name": "", + "hd_serial": "", + "dg_serial": "", + "sw_version": "", "mode": "registration", "device_state": "INACTIVE_NOT_OK" } Index: cloudsync/handlers/cs_mft_dcs_request_handler.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/cs_mft_dcs_request_handler.py (.../cs_mft_dcs_request_handler.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/cs_mft_dcs_request_handler.py (.../cs_mft_dcs_request_handler.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Handler of network requests between CloudSync, Device Registration Tool and Diality Cloud System""" + from time import time from logging import Logger @@ -136,7 +138,10 @@ if len(invalid_attributes) > 0: self.logger.error( "Device with HD serial number {0}, DG serial number {1}, software version {2} is not a valid device for treatment. Invalid fields: {3}".format( - hd_serial_number, dg_serial_number, sw_version, invalid_attributes)) + req.g_config[CONFIG_DEVICE][CONFIG_DEVICE_HD_SERIAL], + req.g_config[CONFIG_DEVICE][CONFIG_DEVICE_DG_SERIAL], + req.g_config[CONFIG_DEVICE][CONFIG_DEVICE_SW_VERSION], + invalid_attributes)) return response else: organization_id = response.get("associatedOrganizationId", None) @@ -158,9 +163,9 @@ # Step #2b - If patient with emr_id doesn't exist, create temporary patient - if response.status_code == 200: + if response.status_code == OK: patient_id = response.json().get("id", None) - elif response.status_code == 404: + elif response.status_code == NOT_FOUND: response = cmd_outgoing_create_temporary_patient(access_token=access_token, url=create_temporary_patient_url) patient_id = response.get("id", None) @@ -178,8 +183,8 @@ associate=True) # Step #4 - Send treatment report - treatment_log_json['generatedAt'] = int(round(time() * 1000)) + 30000 - treatment_log_json['completedAt'] = int(round(time() * 1000)) + 31000 + treatment_log_json['generatedAt'] = int(round(time() * S_MS_CONVERSION_FACTOR)) + 30000 # TEMPORARY DELAY TO COMPENSATE FOR DEVICE INTERNAL CLOCK ERROR - TODO REMOVE AFTER FIX + treatment_log_json['completedAt'] = int(round(time() * S_MS_CONVERSION_FACTOR)) + 31000 # TEMPORAR DELAY TO COMPENSATE FOR DEVICE INTERNAL CLOCK ERROR - TODO REMOVE AFTER FIX treatment_log_json = json.dumps(treatment_log_json) @@ -216,7 +221,7 @@ else: response = cmd_outgoing_verify_token(url=token_verification_url, access_token=access_token) - if response.status_code == 401: + if response.status_code == UNAUTHORIZED: access_token = cmd_outgoing_get_new_token_with_cert(path_certificate=CREDENTIALS_CERTIFICATE_X509, path_private_key=CREDENTIALS_PRIVATE_KEY, save=True, Index: cloudsync/handlers/incoming/handler_mft_to_cs.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/incoming/handler_mft_to_cs.py (.../handler_mft_to_cs.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/incoming/handler_mft_to_cs.py (.../handler_mft_to_cs.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Handler of commands received by CloudSync app from the Device Registration Tool""" + import os from cloudsync.handlers.outgoing import * @@ -9,15 +11,18 @@ @log_func -def cmd_incoming_set_credentials(certificate: str, private_key: str, - public_key: str, output_channel) -> None: +def cmd_incoming_set_credentials(certificate: str, + private_key: str, + public_key: str, + output_channel) -> None: """ - Sets the credentials on the device - :param certificate: The X.509 certificate - :param private_key: The private key - :param public_key: The public key + Sets device credentials + :param str certificate: the X.509 certificate + :param str private_key: the private key + :param str public_key: the public key :param output_channel: CS_UI output channel :return: None + :raises IOError: if any of the device credentials can't be saved """ try: f = open(CREDENTIALS_CERTIFICATE_X509, 'w') @@ -60,22 +65,16 @@ g_config: dict) -> None: """ Initiates the connectivity test on the device - # Step 6. Device Auth (POST /auth/...) - # Step 7. Device Auth Response (access token) - # Step 8. Validate Device (POST /api/device/validate) - # Step 9. Validate Device Response (list of invalid fields) - # Step 10. Validation Result (POST /validation) (list of invalid fields) - :param url_token: The kebormed request new token url - :param username: The username for requesting a token - :param password: The password for requesting a token + + :param str url_token: the validation request tok + :param str url_validate: The kebormed request new token url :param hd_serial: The hd serial number :param dg_serial: The dg serial number :param sw_version: The software version :param g_config: The configuration dictionary :return: None """ - # Step 6. Device Auth (POST /auth/...) - # Step 7. Device Auth Response (access token) + client_secret = g_config[CONFIG_KEBORMED][CONFIG_KEBORMED_IDP_CLIENT_SECRET] access_token = cmd_outgoing_get_new_token_with_cert(path_certificate=TEMP_CREDENTIALS_CERTIFICATE_X509, path_private_key=TEMP_CREDENTIALS_PRIVATE_KEY, Index: cloudsync/handlers/network_request.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/network_request.py (.../network_request.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/network_request.py (.../network_request.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Network Request object""" + from cloudsync.common.enums import * from cloudsync.utils.globals import * Index: cloudsync/handlers/outgoing/handler_cs_to_dcs.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/outgoing/handler_cs_to_dcs.py (.../handler_cs_to_dcs.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/outgoing/handler_cs_to_dcs.py (.../handler_cs_to_dcs.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Handler of commands sent by CloudSync app to the Diality Cloud System""" + from typing import List, Tuple import json import requests @@ -23,7 +25,7 @@ data=payload, verify=False) - if resp.status_code == 404: + if resp.status_code == NOT_FOUND: resp = requests.put(url=url, headers=headers, data=payload, Index: cloudsync/handlers/outgoing/handler_cs_to_mft.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/outgoing/handler_cs_to_mft.py (.../handler_cs_to_mft.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/outgoing/handler_cs_to_mft.py (.../handler_cs_to_mft.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Handler of commands sent by CloudSync app to the Device Registration Tool""" + import json import requests from time import time Index: cloudsync/handlers/ui_cs_request_handler.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/ui_cs_request_handler.py (.../ui_cs_request_handler.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/ui_cs_request_handler.py (.../ui_cs_request_handler.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Message handler for inbound messages""" + from time import sleep from logging import Logger from threading import Event, Thread Index: cloudsync/handlers/uics_message.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/handlers/uics_message.py (.../uics_message.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/handlers/uics_message.py (.../uics_message.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""UICS Message object""" + class UICSMessage: def __init__(self, message_body: str, g_config: dict): Index: cloudsync/utils/globals.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/utils/globals.py (.../globals.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/utils/globals.py (.../globals.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,4 @@ +"""Object holding all application global constants""" import os import socket @@ -103,3 +104,13 @@ # TREATMENT TEMPLATE PATH TREATMENT_REPORT_TEMPLATE_PATH = "cloudsync/config/treatment_report_template.json" + +# HTTP CODES +OK = 200 +BAD_REQUEST = 400 +UNAUTHORIZED = 401 +NOT_FOUND = 404 +INTERNAL_SERVER_ERROR = 500 + +# TIME CONSTANTS +S_MS_CONVERSION_FACTOR = 1000 Index: cloudsync/utils/heartbeat.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/utils/heartbeat.py (.../heartbeat.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/utils/heartbeat.py (.../heartbeat.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of heartbeat functionality""" + from logging import Logger from threading import Thread from time import sleep Index: cloudsync/utils/helpers.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/utils/helpers.py (.../helpers.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/utils/helpers.py (.../helpers.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of helper methods""" + import os import json import datetime @@ -284,7 +286,7 @@ for data_line in section_lines: data_components = data_line.split(',') data_record = { - "time": int(data_components[0]) * 1000, + "time": int(data_components[0]) * S_MS_CONVERSION_FACTOR, "bloodFlowRate": float(data_components[1]), "dialysateFlowRate": float(data_components[2]), "ultrafiltrationRate": float(data_components[3]), @@ -302,7 +304,7 @@ if len(data_components) > 2: parameters = data_components[2:(len(data_components) - 2)] data_record = { - "time": int(data_components[0]) * 1000, + "time": int(data_components[0]) * S_MS_CONVERSION_FACTOR, "title": data_components[1], "parameters": parameters } @@ -314,7 +316,7 @@ if len(data_components) > 2: parameters = data_components[2:(len(data_components) - 2)] data_record = { - "time": int(data_components[0]) * 1000, + "time": int(data_components[0]) * S_MS_CONVERSION_FACTOR, "title": data_components[1], "parameters": parameters } @@ -362,11 +364,11 @@ elif line.startswith(TREATMENT_START_DATE_TIME): element = datetime.datetime.strptime(line.split(',')[1], "%Y/%m/%d %H:%M") timestamp = datetime.datetime.timestamp(element) - treatment_data['data']['treatment']['time']['start'] = int(timestamp) * 1000 + treatment_data['data']['treatment']['time']['start'] = int(timestamp) * S_MS_CONVERSION_FACTOR elif line.startswith(TREATMENT_END_DATE_TIME): element = datetime.datetime.strptime(line.split(',')[1], "%Y/%m/%d %H:%M") timestamp = datetime.datetime.timestamp(element) - treatment_data['data']['treatment']['time']['end'] = int(timestamp) * 1000 + treatment_data['data']['treatment']['time']['end'] = int(timestamp) * S_MS_CONVERSION_FACTOR elif line.startswith(ACTUAL_TREATMENT_DURATION): treatment_data['data']['treatment']['time']['treatmentDuration'] = int(line.split(',')[1]) elif line.startswith(DIALYSATE_VOLUME_USED): @@ -401,8 +403,9 @@ def helpers_add_to_network_queue(network_request_handler, request_type, url, payload, method, g_config, success_message): - cycle_duration = 10 - total_cycles = 3 + cycle_duration = REACHABILITY_CYCLE_PAUSE + total_cycles = REACHABILITY_CYCLES + cycle = 0 while (not g_utils.reachability_provider.reachability) and (cycle < total_cycles): Index: cloudsync/utils/reachability.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/utils/reachability.py (.../reachability.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/utils/reachability.py (.../reachability.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,11 +1,15 @@ +"""Implementation of reachability functionality""" + from logging import Logger from threading import Thread from time import sleep import requests -REACHABILITY_URL = "https://google.com" -REACHABILITY_FREQ = 5 +REACHABILITY_URL = "https://kebormed.com" +REACHABILITY_CHECK_PAUSE = 5 +REACHABILITY_CYCLES = 3 +REACHABILITY_CYCLE_PAUSE= 10 class ReachabilityProvider: @@ -25,14 +29,14 @@ response = requests.get(url=REACHABILITY_URL) status_code = response.status_code except requests.exceptions.RequestException as er: - status_code = 500 + status_code = INTERNAL_SERVER_ERROR - if status_code == 200: + if status_code == OK: if not self.reachability: self.logger.info('Internet UP') self.reachability = True else: if self.reachability: self.logger.warning('Internet DOWN') self.reachability = False - sleep(REACHABILITY_FREQ) + sleep(REACHABILITY_CHECK_PAUSE) Index: cloudsync/utils/singleton.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloudsync/utils/singleton.py (.../singleton.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloudsync/utils/singleton.py (.../singleton.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of generic singleton object""" + from threading import Lock Index: cs.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cs.py (.../cs.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cs.py (.../cs.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,12 +1,17 @@ +#!/usr/bin/python3 + +"""Implementation of CloudSync launcher and management script""" + import os import signal import sys import time import logging from subprocess import Popen -arguments = sys.argv +DELAY = 0.5 +arguments = sys.argv logging_level = logging.INFO @@ -25,15 +30,15 @@ print("CloudSync app already running") else: print("Starting CloudSync app with logging level {0}".format(logging_level)) - time.sleep(0.5) + time.sleep(DELAY) Popen(['python3', 'cloud_sync.py', str(logging_level)]) def stop(): cs_proc_pid = get_pid() if cs_proc_pid: print("Stopping CloudSync app...") - time.sleep(0.5) + time.sleep(DELAY) os.kill(int(cs_proc_pid), signal.SIGKILL) else: print("CloudSync app is not running.") @@ -57,7 +62,7 @@ stop() elif arguments[1] == "restart": print("Restarting CloudSync app...") - time.sleep(0.5) + time.sleep(DELAY) stop() start() elif arguments[1] == "status":