Exemplo n.º 1
0
    def run(self):
        # As long as we weren't asked to stop, try to take new data from the
        # queue. The tasks are taken with a blocking 'get', so no CPU
        # cycles are wasted while waiting.
        params = config.getParams(db_name)
        folder = params["path"][1]
        if folder[-1] != "/":
            folder = folder + "/"

        print "Writer Started"
        while True:
            print "Reading"
            msg = self.writer_q.get()
            print "AAAAAAAAAAA" + str(msg.data)
            if msg is None:  # This will probably never reached
                print "None Received"
                continue
#        self.writeLog(msg)
# if it is message add timestamp to the message
            if msg.data[0] == '#' and msg.data[-1] == ';':
                col = msg.data[1:-1].split(',')
                d_out = col[0] + "," + str(
                    msg.millis) + "," + msg.ip + "," + ",".join(col[1:])
                file = col[0]
                writeLog(folder, file, msg.ts, d_out)
            elif msg.data[0] == '$' and msg.data[-1] == ';':
                print "$$$$$$ is " + msg.data
                # $ needs to be handled in a different way
                col = msg.data[1:-1].split(',')
                file = col[0]
                d_out = col[0] + "," + str(
                    msg.millis) + "," + msg.ip + "," + ",".join(col[1:])
                writeLog(folder, file, msg.ts, d_out)
                if col[0] == "shutdown":
                    break
                if col[0] == "set":
                    if len(col) == 3:
                        config.setParam(db_name, col[1], col[2])
                        params = config.getParams(db_name)
                        folder = params["path"][1]
                        if folder[-1] != "/":
                            folder = folder + "/"

            else:
                file = "Error"
                d_out = str(msg.millis) + "," + msg.ip + "," + msg.data
                writeLog(folder, file, msg.ts, d_out)

            print "logWriter", msg.data
Exemplo n.º 2
0
  def run(self):
    # As long as we weren't asked to stop, try to take new data from the
    # queue. The tasks are taken with a blocking 'get', so no CPU
    # cycles are wasted while waiting.
    params = config.getParams(db_name)
    folder = params["path"][1]
    if folder[-1] != "/":
      folder = folder + "/"

    print "Writer Started"
    while True:
      print "Reading"
      msg = self.writer_q.get()
      print "AAAAAAAAAAA" + str(msg.data)
      if msg is None: # This will probably never reached 
        print "None Received"
        continue
#        self.writeLog(msg)
      # if it is message add timestamp to the message 
      if msg.data[0] == '#' and msg.data[-1] == ';': 
        col =  msg.data[1:-1].split(',')
        d_out  = col[0] + "," + str(msg.millis)  + "," + msg.ip + "," + ",".join(col[1:])
        file = col[0]
        writeLog(folder,file,msg.ts,d_out)
      elif msg.data[0] == '$' and msg.data[-1] == ';':
        print "$$$$$$ is " + msg.data
		# $ needs to be handled in a different way
        col =  msg.data[1:-1].split(',')
        file = col[0]
        d_out  = col[0] + "," + str(msg.millis)  + "," + msg.ip + "," + ",".join(col[1:])
        writeLog(folder,file,msg.ts,d_out)
        if col[0] == "shutdown":
          break;
        if col[0] == "set":
          if len(col) == 3:
            config.setParam(db_name,col[1],col[2])
            params = config.getParams(db_name)
            folder = params["path"][1]
            if folder[-1] != "/":
              folder = folder + "/"
            
      else:
        file = "Error"
        d_out  = str(msg.millis)  + "," + msg.ip + "," + msg.data
        writeLog(folder,file,msg.ts,d_out)


      print "logWriter", msg.data