def _rm_dir_or_filename(self, path): to_MDS = BKDRHash(path, self.seed, self.mds_num) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.mds[to_MDS], self.port)) s.sendall(f"remove -> {path}".encode()) time.sleep(0.1) s.sendall("#finished#".encode()) temp = s.recv(4096).decode() if temp == "#finished#": s.close()
def _insert(self, sample): to_MDS = BKDRHash(sample.path, self.seed, self.mds_num) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.mds[to_MDS], self.port)) s.sendall(f"insert -> {sample.to_string()}".encode()) time.sleep(0.1) s.sendall("#finished#".encode()) temp = s.recv(4096).decode() if temp == "#finished#": s.close()
def _add_to_dir(self, filename, dir_path): to_MDS = BKDRHash(dir_path, self.seed, self.mds_num) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.mds[to_MDS], self.port)) msg = dir_path + ':' + filename s.sendall(f"add_dir -> {msg}".encode()) time.sleep(0.1) s.sendall("#finished#".encode()) temp = s.recv(4096).decode() if temp == "#finished#": s.close()
def _query_metadata(self, path): to_MDS = BKDRHash(path, self.seed, self.mds_num) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.mds[to_MDS], self.port)) s.sendall(f"query_metadata -> {path}".encode()) result = s.recv(4096).decode() s.sendall("#finished#".encode()) temp = s.recv(4096).decode() if temp == "#finished#": s.close() return result
def _create(self, path, isdir): if isdir == "no": filename = path.split('/')[-1] if '.' in filename: ftype = filename.split('.')[-1] else: ftype = 'txt' else: ftype = "none" time_stamp = datetime.datetime.now() ctime = '"' + time_stamp.strftime('%Y-%m-%d %H:%M:%S') + '"' line_sample = ', '.join([path, '10', isdir, ftype, ctime]) to_MDS = BKDRHash(path, self.seed, self.mds_num) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.mds[to_MDS], self.port)) s.sendall(f"insert -> {line_sample}".encode()) time.sleep(0.1) s.sendall("#finished#".encode()) temp = s.recv(4096).decode() if temp == "#finished#": s.close()