def handle_ARCHIVE_REQUEST(self, client_socket, archive_request): file_path = archive_request.file_path response = messages.ArchiveResponse(file_path, archived=False) logging.info("Handling Archive Request") f = self.db.get_file(file_path) if not f: communication.send_message(response, socket=client_socket) return self.db.add_version(f) f.latest_version += 1 self.db.add_or_update_file(f) response.archived = True communication.send_message(response, socket=client_socket) peers_list = self.db.get_peers(file_path) # notify all peers that have the file about the new version for peer in peers_list: if peer.hostname == self.hostname and peer.port == self.port: local_file_path = filesystem.get_local_path(self, file_path, f.latest_version-1) file_data = filesystem.read_file(local_file_path) local_file_path = filesystem.get_local_path(self, file_path, f.latest_version) filesystem.write_file(local_file_path, file_data) if peer.state == PeerState.OFFLINE: continue file_archived_msg = messages.FileArchived(f.path, f.latest_version) communication.send_message(file_archived_msg, peer)
def show_html_in_browser(html, filename): filesystem.write_file(filename, html) html_file = os.path.abspath(filename) html_file = 'file://' + html_file webbrowser.open(html_file)