import json import os class LmdClientManager: def __init__(self): self.clientpath="/etc/ltsp/bootopts/clients/" pass #def __init__ def getClientList(self): ''' Reads the file list of clients from /etc/ltsp/bootopts/clients Returna a JSON List. ''' clientlist=[] for i in os.listdir(self.clientpath): if '.json' in i: clientlist.append(str(i)) return json.dumps(clientlist) def getClient(self, client): ''' Returns the metadata from certain client ''' try: json_data=open(self.clientpath+client) data = json.load(json_data) json_data.close() return json.dumps(data) #return data; except Exception as e: return str(e); def setClient(self, client, data): ''' Saves metadata from *data to client data is unicoded string client is a mac ''' client=client.replace(":", "") path_to_write = os.path.join(self.clientpath,client + ".json") f = open(path_to_write,'w') f.writelines(data) f.close() def deleteClient(self, client): ''' N4d Method to delete a client ''' import shutil; try: client=client.replace(":", "") json_file = os.path.join("/etc/ltsp/bootopts/clients",client + ".json") # Remove .json file if (os.path.isfile(json_file)): os.remove(json_file); return {"status":True, "msg":"Client Removed"} except Exception as e: return {"status":False, "msg":str(e)}