Exemple #1
0
 def _read_config(absfilename):
     """
     Parse configuration from file
     
     @param absfilename:    Filename to read data from
     """
     config = {}
     try:
          config_file = open(absfilename)
          config_data = config_file.read()
          config = json.read(config_data)
          config_file.close()
     except Exception, e:
          logging.getLogger('LBRC.Config').exception(_("Could not read config file: %s") % absfilename)
          config = {}
 def _handle_buffer(self):
     packets = self.buffer.split(u"\u0000")
     # The last packet is either empty (if the last packet was completely send
     # or we only see a partital package, that we feed back into the buffer
     self.buffer = packets.pop()            
     for packet in packets:
         data = json.read(packet.encode('utf-8'))
         if (data['type'] == "keyCode"):
             mapping = data["mapping"]
             keycode = data["keycode"]
             self.emit('keycode', mapping, keycode)
         elif (data['type'] == "listReply" and self.handler['list']):
             handler = self.handler['list']
             self.handler['list'] = None
             handler(data['selectionIndex'])
         elif (data['type'] == 'debugMessage'):
             self.logger.debug("PHONE (%(function)s): %(message)s" % data )
         else:
             self.logger.debug("Unmatched package: " + str(data))
Exemple #3
0
 def _read_config(absfilename):
     """
     Parse configuration from file
     
     @param absfilename:    Filename to read data from
     """
     config_hash = {}
     try:
         config_file = open(absfilename)
         config_data = config_file.read()
         config_hash = json.read(config_data)
         config_file.close()
     except IOError:
         logging.getLogger('LBRC.Config').exception(
                             _("Error while opening: %s") % absfilename)
     except json.ReadException:
         logging.getLogger('LBRC.Config').exception(
                             _("Error while interpreting json data in file: %s") % absfilename)
     return config_hash