def create_config(bucket, fsid): initial_cfg = config_pb2.Config() initial_cfg.name = fsid initial_cfg.uuid = fsid initial_cfg.primary.host = "localhost" initial_cfg.primary.epoch = 0 initial_cfg.primary.startTime = int(time.time()) initial_cfg.primary.fuse_cache_enable = True initial_cfg.primary.fuse_direct_io = False initial_cfg.keyValueStore.type = 1 #LEVELDB initial_cfg.keyValueStore.persistenceRule = 2 #LAZY initial_cfg.keyValueStore.maxSizeBytes = 100000000 initial_cfg.tiering.cacheDir = 'proxy_dir' #'/var/cbfs/' + fsid initial_cfg.cloud.protocol = 1 #S3 initial_cfg.cloud.endpoint = bucket + fsid return str(initial_cfg);
def run(self): state = 0 hexsize = '' messagetype = 0 messagelength = 0 while True: while state < 7: c = self._ser.read() if state == 0: if ord(c) == 0x41: state += 1 print ("A") continue else: state = 0 if state == 1: if ord(c) == 0x4E: state += 1 print ("N") continue else: state = 0 if state == 2: if ord(c) == 0x53: state += 1 print ("S") continue else: state = 0 if state == 3: if ord(c) == 0x49: state += 1 print ("I") continue else: state = 0 if state == 4: messagetype = ord(c) state += 1 print ("MessageType: %d" % messagetype) continue if state == 5: hexsize = c state += 1 print ("size") continue if state == 6: hexsize += c state += 1 messagelength = unpack('<H', hexsize)[0] print ("size:%d" % messagelength) continue state = 0 message = self._ser.read(messagelength) print ("Buffersize:%d" % len(message)) if messagetype == 4: print ("STATUS:") status = status_pb2.Status() status.ParseFromString(message) print (status) self._queue.put(status) if messagetype == 3: print ("Sensor:") sensor = sensor_pb2.Sensor() sensor.ParseFromString(message) print (sensor) self._queue.put(sensor) if messagetype == 2: print ("Motor:") motor = motor_pb2.Motor() motor.ParseFromString(message) print (motor) self._queue.put(motor) if messagetype == 1: print ("Config:") config = config_pb2.Config() config.ParseFromString(message) print (config) self._queue.put(config)
import config_pb2 config = config_pb2.Config() with open("exported.config") as f: config.ParseFromString(f.read()) print( config.accounts[0].username )