示例#1
0
    def upload_config(config: str, device: str):
        """
        POST handler

        :param config: str
        :param device: str

        :return result: str
        """
        core_cfg = CoreCfg()
        data_dir = core_cfg.get(attrib='data_dir')
        data_dirs_dict = core_cfg.get(attrib='data_dirs_dict')

        file_url = os.path.join(data_dir, device, data_dirs_dict['upld'],
                                config + '.ini')

        if os.path.isfile(path=file_url):
            f = open(file_url, 'r')
            result = f.read()
            f.close()

        else:
            result = 'Incorrect config file request.'
            logger.info(result)
            print(result)

        return result
示例#2
0
    def post_text(post_data):
        """
        POST handler

        :param post_data: request object
        """
        core_cfg = CoreCfg()
        data_dir = core_cfg.get(attrib='data_dir')
        data_dirs_dict = core_cfg.get(attrib='data_dirs_dict')

        user_agent = post_data.headers['User-Agent'].split('_')[0]
        file_type = post_data.headers['User-Agent'].split('_')[1]
        file_name = post_data.headers['User-Agent']

        file_url = ''
        if file_type == 'errs':
            file_url = os.path.join(data_dir, user_agent,
                                    data_dirs_dict['errs'], file_name)
        elif file_type == 'logs':
            file_url = os.path.join(data_dir, user_agent,
                                    data_dirs_dict['logs'], file_name)

        f = open(file_url, 'w+b')
        f.write(post_data.data)
        f.close()

        log = 'Text datafile {0} uploaded!'.format(file_url)
        logger.info(log)
        print(log)

        return log
示例#3
0
    def post_binary(post_data):
        """
        POST handler

        :param post_data: request object
        """
        core_cfg = CoreCfg()
        data_dir = core_cfg.get(attrib='data_dir')

        file_name = post_data.headers['User-Agent']
        file_url = os.path.join(data_dir, 'incoming/', file_name)

        f = open(file_url, 'w+b')
        f.write(post_data.data)
        f.close()

        log = 'Binary datafile {0} uploaded!'.format(file_url)
        logger.info(log)
        print(log)

        return log
示例#4
0
def errors(err_xmit_url: str, err_msg: str) -> bool:
    """
    Places log error entry into transmit folder for transmission

    :param err_xmit_url: str
    :param err_msg: str

    :return copy_err: bool
    """
    core_cfg = CoreCfg()
    cfg_url_dict = core_cfg.get(attrib='cfg_url_dict')

    copy_err = False

    err_dtg = str(os.path.basename(err_xmit_url)).split('_')[1] + '_' + \
        str(os.path.basename(err_xmit_url).split('_')[2])
    err_msg = 'DATE-TIME: ' + err_dtg + '_' + err_msg

    if not os.path.isfile(path=err_xmit_url):
        copy_err = file_ops.copy_file(data_orig_url=cfg_url_dict['err'],
                                      data_dest_url=err_xmit_url)

        if not copy_err:
            file_ops.f_request(file_cmd='file_line_write',
                               file_name=err_xmit_url,
                               data_file_in=[err_msg])

        else:
            log = 'Failed to append error message to file for error transmission'
            logger.error(log)
            print(log)

    else:
        file_ops.f_request(file_cmd='file_line_append',
                           file_name=err_xmit_url,
                           data_file_in=[err_msg])

    return copy_err
示例#5
0
    log = 'JanusWM logging started'
    logger.info(msg=log)
    logging.getLogger(name=logfile).setLevel(level=logging.INFO)

    cron_sched = CronTab(user='******')
    cron_sched.remove_all()
    cron_sched.write()

    log = 'Jobs listed in CRON at program start (possibly no entries):'
    logger.info(msg=log)
    print(log)
    for job in cron_sched:
        logger.info(msg=job)
        print(job)

    core_cfg = CoreCfg()
    capture_cfg = CaptureCfg(core_cfg=core_cfg)
    img_capt_dict = capture_cfg.get(attrib='img_capt_dict')

    transmit_cfg = TransmitCfg(core_cfg=core_cfg)
    xmit_exec_int = transmit_cfg.get(attrib='exec_int')

    job_capt = cron_sched.new(
        command='sudo python3 /opt/Janus/WM/python3/main-capture.py')
    job_capt.minute.every(img_capt_dict['exec_interval'])
    log = 'Setting capture execution to every {0} minutes.'.format(
        img_capt_dict['exec_interval'])
    logger.info(msg=log)

    job_xmit = cron_sched.new(
        command='sudo python3 /opt/Janus/WM/python3/main-transmit.py')
示例#6
0
    try:
        me = singleton.SingleInstance()

    except singleton.SingleInstanceException:
        log = 'Duplicate transmit process, shutting down.'
        logger.warning(msg=log)
        print(log)
        sys.exit(-1)

    for i in range(1, 6):
        logger.info(msg='')

    log = 'JanusWM Transmit logging started'
    logger.info(msg=log)

    core_cfg = CoreCfg()

    timea = ttime.time()

    minute = int(datetime.today().strftime('%M'))
    hour = int(datetime.today().strftime('%H'))
    execution_minute = (hour * 60) + minute

    transmit_cfg = TransmitCfg(core_cfg=core_cfg)
    gprs_cfg_dict = transmit_cfg.get(attrib='gprs_cfg_dict')

    print(execution_minute)
    log = 'Transmission execution minute: {0}'.format(execution_minute)
    logger.info(msg=log)
    # Update not implemented yet
    # if not (execution_minute % update_freq):
示例#7
0
    err_dict = {
        'shape': True,
        'build_yolo': True,
        'build_incept': True,
        'detection': True,
        'img_bbox': True,
        'img_angle': True,
        'img_rotd': True,
        'img_digw': True,
        'img_digs': True,
        'img_olay': True,
        'prediction': True,
    }

    # Load configuration settings
    core_cfg = CoreCfg()
    img_path_dict = core_cfg.get(attrib='img_path_dict')

    # Setup TensorFlow models
    tensor = Tensor(core_cfg=core_cfg)
    err_dict['build_yolo'], yolo_model, yolo_classes = tensor.build_yolo_model()
    print('Build YOLO error: {0}'.format(err_dict['build_yolo']))
    err_dict['build_incept'], incept_model = tensor.build_incept_model()
    print('Build Inception error: {0}'.format(err_dict['build_incept']))

    # Proceed only if model setup successful
    if not err_dict['build_yolo'] and not err_dict['build_incept']:

        # Create sorted list of image names from source directory for iteration
        img_orig_names = iter(sorted(os.listdir(img_path_dict['orig'])))
        for img_orig_name in img_orig_names:
示例#8
0
    err_dict = {
        'shape': True,
        'build_yolo': True,
        'build_incept': True,
        'detection': True,
        'img_bbox': True,
        'img_angle': True,
        'img_rotd': True,
        'img_digw': True,
        'img_digs': True,
        'img_olay': True,
        'prediction': True,
    }

    # Load configuration settings
    core_cfg = CoreCfg()
    data_dir = core_cfg.get(attrib='data_dir')
    data_dirs_dict = core_cfg.get(attrib='data_dirs_dict')
    img_save_dict = core_cfg.get(attrib='img_save_dict')
    tensor_cfg = TensorCfg(core_cfg=core_cfg)
    pred_freq = tensor_cfg.get(attrib='pred_freq')
    incoming_path = os.path.join(
        data_dir,
        'incoming/',
    )

    # Setup TensorFlow models
    tensor = Tensor(core_cfg=core_cfg)
    err_dict['build_yolo'], yolo_model, yolo_classes = tensor.build_yolo_model(
    )
    log = 'Build YOLO error: {0}'.format(err_dict['build_yolo'])