Ejemplo n.º 1
0
    def execute(self):
        args = [self._interface]

        try:
            iwconfig_output = Util.execute_shell_process(self._iwconfig, args)
            ifconfig_output = Util.execute_shell_process(self._ifconfig, args)
        except IOError:
            self.logger.error("Error executing iwconfig or ifconfig.")
            return None

        regex = {
            'essid': r'ESSID:"(\S*)"',
            'quality': r'Link Quality=(\d*)/(\d*)',
            'frequency': r'Frequency:(\S*)',
            'ap': r'Access Point: (\S*)',
            'rate': r'Bit Rate=(\d*)'
        }

        data = {}

        try:
            for key, val in regex.items():
                m = re.findall(val, iwconfig_output)
                if len(m) > 0:
                    data[key] = re.findall(val, iwconfig_output)[0]

            addr = re.findall(r'inet addr:(\S*)', ifconfig_output)

            if len(addr) > 0:
                data['address'] = addr[0]

            data['quality_pct'] = None
            if 'quality' in data.keys() and data['quality'][1] != 0:
                data['quality_pct'] = 100 * float(data['quality'][0]) / float(
                    data['quality'][1])
            else:
                data['quality_pct'] = 0

            if 'essid' in data.keys():
                if 'address' in data.keys() and self._layout_connected_address:
                    return self._layout_connected_address % data
                if self._layout_connected:
                    return self._layout_connected % data
            else:
                if self._layout_disconnected:
                    return self._layout_disconnected % data
        except TypeError:
            return None
Ejemplo n.º 2
0
    def execute(self):
        args = [self._interface]
        try:
            ifconfig_output = Util.execute_shell_process(self._ifconfig, args)
        except IOError:
            self.logger.error("Error executing " + self._ifconfig +
                              " with arguments " + args)

        down = re.findall(r'DOWN')
Ejemplo n.º 3
0
    def execute(self):
        args = ["sget", self._control]

        amixer_output = Util.execute_shell_process(self._amixer_command, args)

        regex_mute = r'\[off\]'
        regex_vol = r'\d{1,3}%'

        if re.search(regex_mute, amixer_output):
            return self._mute_output

        value = int(re.findall(regex_vol, amixer_output)[0].strip('%'))

        if self._show_units:
            return self._format % value + '%'
        else:
            return self._format % value
Ejemplo n.º 4
0
 def execute(self):
     if self._command:
         return Util.execute_shell_process(self._command,
                                           self._args).strip()