import subprocess as s import re import os.path import os class LliurexBerry: def __init__(self): self.excludepaht = ['/','/boot','/home'] def get_devices(self): cmd = s.Popen(["lsblk","-o","RM,TYPE,NAME,SIZE,MODEL"],stdout=s.PIPE) list_output = cmd.stdout.readlines() list_output.pop(0) result = [] for item in list_output: aux = item.strip() aux_splited = re.match(r'\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(.*)',aux) volume = {} if aux_splited.group(2) == 'disk': volume['name'] = aux_splited.group(3) volume['size'] = aux_splited.group(4) volume['model'] = aux_splited.group(5) cmd1 = s.Popen(["lsblk",os.path.join('/dev',volume['name']),"-o","MOUNTPOINT"],stdout=s.PIPE) mountpointsdevice = map(str.strip,cmd1.stdout.readlines()) found = False for point in self.excludepaht: if point in mountpointsdevice: found = True if not found: result.append(volume) return {'status':True,'msg':result} def burn_llxberry(self,device): """ record /usr/share/n4d-lliurexberry/llxberry.img on device """ token = "/var/run/remove_partitions" f = open(token,'w') f.close() cmd = s.Popen(['create_llxberry_sd',device,'--ignore-removable'],stdout=s.PIPE) output = cmd.stdout.readlines() if output[-1].strip() == "Ok": status = True else: status = False return {"status": status,"msg":"".join(output)} if __name__ == "__main__": x = LliurexBerry() for z in x.get_removable_devices(): print z