Example #1
0
    def __init__(self, connection, driver, device,
                 filename='lircd.conf.learning', path=None):
        assert not os.path.isabs(filename)

        if not path:
            IrRecordDriver.__last_instance += 1
            path = '/IrRecordDriver%d' % self.__last_instance

        self._workdir = tempfile.mkdtemp(prefix='gnome-lirc-properties-')
        self._cmdargs = [config.LIRC_IRRECORD, '--driver=%s' % driver]
        self._filename = filename

        if device:
            self._cmdargs.append('--device=%s' % ShellQuote.shellquote(device))
        if filename:
            self._cmdargs.append(filename)

        super(IrRecordDriver, self).__init__(connection, path)
        logging.info("__init__.IrRecordDriver(): irrecord cmdargs=%s", self._cmdargs)
Example #2
0
    def _write_hardware_configuration(self,
                                      remote_values=dict(),
                                      receiver_values=dict(),
                                      start_lircd=None):
        '''Updates lirc's hardware.conf file on Debian/Ubuntu.'''

        if start_lircd is not None:
            start_lircd = str(bool(start_lircd)).lower()

        oldfile = config.LIRC_HARDWARE_CONF
        newfile = '%s.tmp' % oldfile

        if not os.path.isfile(oldfile):
            raise UnsupportedException('Cannot find %s script' % oldfile)

        logging.info('Updating %s...', oldfile)
        logging.info('- receiver_values: %r', receiver_values)
        logging.info('- remote_values: %r', remote_values)

        output = file(newfile, 'w')
        for line in file(oldfile, 'r'):

            # Identify directives starting with REMOTE_ and replacing their values with ours.
            # Remove entry from the dict on match, so we know what was written.
            match = self.__re_remote_directive.match(line)
            value = match and remote_values.pop(match.group(1), None)

            if value is not None:
                logging.info('- writing %s"%s"', match.group(0), value)
		if value == "":
                    print >> output, ('%s"%s"' % (match.group(0), value))
                else:
                    print >> output, ('%s"%s"' % (match.group(0), ShellQuote.shellquote(value)))
                continue

            # Identify directives starting with RECEIVER_ and replacing their values with ours.
            # Remove entry from the dict on match, so we know what was written.
            match = self.__re_receiver_directive.match(line)
            value = match and receiver_values.pop(match.group(1), None)

            if value is not None:
                logging.info('- writing %s"%s"', match.group(0), value)
		if value == "":
                    print >> output, ('%s"%s"' % (match.group(0), value))
	        else:
                    print >> output, ('%s"%s"' % (match.group(0), ShellQuote.shellquote(value)))
                continue

            if config.STARTUP_STYLE is not 'fedora':
                # Deal with the START_LIRCD line:

                match = self.__re_start_lircd.match(line)

                if match:
                    # pychecker says "Using a conditional statement with a constant value (true)",
                    # which is ridicilous, considering Python 2.4 doesn't have conditional statements
                    # yet (PEP 308, aka. 'true_value if condition else false_value') and the expression
                    # below ('condition and true_value or false_value') is the recommended equivalent.
                    value = (start_lircd is None) and 'true' or start_lircd
                    start_lircd = None

                    print >> output, (match.group(0) + ShellQuote.shellquote(value))
                    continue

            output.write(line)

        # Write out any values that were not already in the file,
        # and therefore just replaced:

        if remote_values:
            print >> output, '\n# Remote settings required by gnome-lirc-properties'
        for key, value in remote_values.items():
            if config.STARTUP_STYLE is not 'fedora':
                print >> output, ('REMOTE_%s="%s"' % (key, ShellQuote.shellquote(value)))
            else:
                print >> output, ('%s="%s"' % (key, ShellQuote.shellquote(value)))

        if receiver_values:
            print >> output, '\n# Receiver settings required by gnome-lirc-properties'
        for key, value in receiver_values.items():
            print >> output, ('RECEIVER_%s="%s"' % (key, ShellQuote.shellquote(value)))

        if start_lircd is not None and config.STARTUP_STYLE is not 'fedora':
            print >> output, '\n# Daemon settings required by gnome-lirc-properties'
            print >> output, ('START_LIRCD=%s' % start_lircd)

        if config.STARTUP_STYLE is 'fedora':
            value = (start_lircd is None) and 'true' or start_lircd
            start_lircd = None
            if 'true' == value:
                args = '/sbin/chkconfig', 'lirc', 'on'
            else:
                args = '/sbin/chkconfig', 'lirc', 'off'
            os.spawnv(os.P_WAIT, args[0], args)

        # Replace old file with new contents:

        os.unlink(oldfile)
        os.rename(newfile, oldfile)