コード例 #1
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def clock_check(self, station_name):
        """
         Returns the current time of the station and the difference between the station and the server.
         The time difference is in milliseconds.  A negative value indicates the station is ahead of the server.

        :param station_name:
        :return:
        """
        station_time = {}

        try:
            cora_output = self.execute_cora('clock-check {' + station_name +
                                            '};')

            # extract the time returned
            response = extract_data(cora_output, 'clock-check')

            self.logger.debug(response)

            clock_response = re.search(
                '"(?P<station_time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3})",(?P<differences_msec>[|-]\d+)',
                response[0])

            if clock_response is not None:
                station_time['Station Time'] = clock_response.group(
                    'station_time')
                station_time['Time Difference'] = clock_response.group(
                    'differences_msec')

                return station_time

        except CoraError:
            raise
コード例 #2
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def list_stations(self):
        """
        issues the cora command to list the station on the LoggerNet server and return as a list

        :return:
        """
        cmd = 'list-stations'
        station_list = []
        station_name = re.compile(
            r'\{\{(?P<station_name>.*)\}\s+(?P<broker_id>\d+)\}')

        self.logger.debug('getting station list via cora')

        cora_output = self.execute_cora(cmd + ';')

        try:
            for line in extract_data(cora_output, cmd):
                sn_match = station_name.match(line.strip())
                if sn_match is not None:
                    if sn_match.group('station_name') != '__Statistics__':
                        station_list.append(sn_match.group('station_name'))

            return station_list

        except CoraError:
            raise
コード例 #3
0
def test_extract_data(command, cora_output, response):
    logger = getLogger('test_device_settings')
    logger.setLevel(DEBUG)

    extracted_response = extract_data(cora_output, command)
    logger.debug('{}'.format(extracted_response))

    assert extracted_response == response
コード例 #4
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def list_tables(self, station_name):
        try:
            cora_output = self.execute_cora('list-tables {' + station_name +
                                            '};')
            self.logger.debug('cora_output is: {}'.format(cora_output))
            return remove_quotes(extract_data(cora_output, 'list-tables'))

        except CoraError:
            raise
コード例 #5
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def get_value(self, station_name, value, swath=1):
        try:
            cora_output = self.execute_cora('get-value {' + station_name +
                                            '.' + value + '} --swath=' +
                                            str(swath) + ';')

            self.logger.debug('cora_output is: {}'.format(cora_output))
            cora_output = remove_quotes(cora_output)
            return extract_data(cora_output, 'get-value')

        except CoraError:
            raise
コード例 #6
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def data_query(self, station_name, table_name, begin_date, end_date):
        try:
            cmd = 'data-query {%s} {%s} "%s" "%s";' % (
                station_name, table_name, begin_date, end_date)
            self.logger.debug('cora command: {}'.format(cmd))

            cora_output = self.execute_cora(cmd)
            self.logger.debug('cora_output is: {}'.format(cora_output))
            return extract_data(cora_output, 'data-query')

        except CoraError:
            raise
コード例 #7
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def get_device_setting(self, device_name, setting):
        try:
            setting_id = DeviceSettings(setting).value
            self.logger.debug('Getting {}({}) from {}'.format(
                setting, setting_id, device_name))
            cora_output = self.execute_cora(
                'get-device-setting {{{}}} {};'.format(device_name,
                                                       setting_id))

            settings = extract_data(cora_output, 'get-device-setting')

            if len(settings) == 1:
                return settings[0]
            else:
                settings = list(filter(None, settings))
                return settings

        except CoraError:
            raise
コード例 #8
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def list_devices(self):
        """
        get a list of the devices on the loggernet server
        """

        device_list = []

        reg_device = re.compile(
            r'\{\{(?P<device_name>.+)\}\s(?P<device_id>\d)+\s(?P<device_type_code>.+)\s(?P<device_indent>\d+)\}'
        )

        try:
            cora_output = self.execute_cora('list-devices;')

            for line in extract_data(cora_output, 'list-devices'):
                line = line.strip()

                device = reg_device.search(line)

                if device:
                    # append the device to list of devices
                    device_list.append({
                        'device_name':
                        device.group('device_name').strip(),
                        'device_id':
                        device.group('device_id').strip(),
                        'device_type_code':
                        device.group('device_type_code').strip(),
                        'device_indent':
                        device.group('device_indent').strip()
                    })

            return device_list

        except CoraError:
            raise
コード例 #9
0
ファイル: corautil.py プロジェクト: eastmanjoe/corautil
    def list_files(self, station_name):
        """
        This command is used to list the files that can be found in a datalogger's file system. It is supported only
        for those datalogger types that support file systems (CR9000, CR5000, CR1000, CR10X-PB, CR510-PB,
        CR23X-PB, and, in a limited sense, the CR2xx).

        :param station_name:
        :return:
        """
        re_file = re.compile(
            r'\{CPU:(?P<filename>.+)\}\srn=(?P<rn>false|true)\spu=(?P<pu>false|true)'
            +
            r'\sro=(?P<ro>false|true)\ssize=(?P<size>\d+)\slast-changed=\{(?P<last_changed>.+)\}'
        )

        cmd = 'list-files'
        file_list = []

        try:
            cora_output = self.execute_cora(cmd + ' ' + station_name + ';')

            logger.debug('cora_output list is: {}'.format(cora_output))

            for line in extract_data(cora_output, cmd):
                # clear dictionary
                file_info = {}

                # remove newline characters
                line = line.strip()

                logger.debug('cora_output line is: {}'.format(line))

                if 'CPU' in line:

                    parameter = re_file.search(line)
                    # logger.debug('cora_output regex is: {}'.format(parameter))

                    if parameter:
                        # logger.debug('file parameters are: {}'.format(parameter.groups()))

                        file_info['filename'] = parameter.group('filename')
                        file_info['filename'] = file_info['filename'].strip(
                            '{CPU:')
                        file_info['filename'] = file_info['filename'].strip(
                            '}')

                        file_info['rn'] = parameter.group('rn')
                        file_info['pu'] = parameter.group('pu')
                        file_info['ro'] = parameter.group('ro')
                        file_info['size'] = parameter.group('size')
                        file_info['last-changed'] = parameter.group(
                            'last_changed')

                        self.logger.debug('filename is: {}'.format(
                            file_info['filename']))
                        self.logger.debug('file_info is: {}'.format(file_info))

                        if file_info['filename'] != '':
                            file_list.append(file_info)

                        self.logger.debug(
                            'the complete list is: {}'.format(file_list))
            return file_list

        except CoraError:
            raise