def share_file(self, filename, other_user): if os.path.isdir(filename): return rpc.share_folder(other_user, filename, self.server_ip, self.server_port, self.username, self.ip, self.port) with open(filename, "rb") as in_file, open(filename + '.enc', "wb") as out_file: EncryptionTest.encrypt(in_file, out_file, "ThisPassword") in_file.close() out_file.close() with open(filename + '.enc', "rb") as handle: binary_data = xmlrpclib.Binary(handle.read()) handle.close() os.remove(filename + '.enc') return rpc.share_file(other_user, filename, binary_data, self.server_ip, self.server_port, self.username, self.ip, self.port)
def push_file(self, filename): # this method push the modified/new file to the server if os.path.isdir(filename): return rpc.push_folder(filename, self.server_ip, self.server_port, self.username, self.ip, self.port, self.mac) with open(filename, "rb") as in_file, open(filename + '.enc', "wb") as out_file: EncryptionTest.encrypt(in_file, out_file, "ThisPassword") in_file.close() out_file.close() with open(filename + '.enc', "rb") as handle: binary_data = xmlrpclib.Binary(handle.read()) handle.close() os.remove(filename + '.enc') return rpc.push_file(filename, binary_data, self.server_ip, self.server_port, self.username, self.ip, self.port, self.mac)
def modify_local_file(self): try: f, d = self.incoming_file_names.get(True, .1) if d is None: try: os.makedirs(f) except OSError: pass if f not in self.files: self.files.append(f) if f not in self.synced_from_server: self.synced_from_server.append(f) else: path, name = os.path.split(f) if not os.path.exists(path): os.makedirs(path) if path not in self.files: self.files.append(path) if path not in self.synced_from_server: self.synced_from_server.append(path) try: with open(f + '.enc', "wb") as handle: handle.write(d.data) handle.close() with open(f + '.enc', "rb") as in_file, open(f, "wb") as out_file: EncryptionTest.decrypt(in_file, out_file, "ThisPassword") in_file.close() out_file.close() os.remove(f + '.enc') if f not in self.files: self.files.append(f) if f not in self.synced_from_server: self.synced_from_server.append(f) except OSError: pass self.incoming_file_names.task_done() except Empty: pass