| 
									
										
										
										
											2010-12-30 22:11:50 +00:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											1995-04-10 11:46:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-30 22:11:50 +00:00
										 |  |  | """
 | 
					
						
							|  |  |  | Remote python client. | 
					
						
							|  |  |  | Execute Python commands remotely and send output back. | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											1995-04-10 11:46:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2010-12-30 21:33:07 +00:00
										 |  |  | from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR | 
					
						
							| 
									
										
										
										
											1995-04-10 11:46:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PORT = 4127 | 
					
						
							|  |  |  | BUFSIZE = 1024 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2004-07-18 05:56:09 +00:00
										 |  |  |     if len(sys.argv) < 3: | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |         print("usage: rpython host command") | 
					
						
							| 
									
										
										
										
											2004-07-18 05:56:09 +00:00
										 |  |  |         sys.exit(2) | 
					
						
							|  |  |  |     host = sys.argv[1] | 
					
						
							|  |  |  |     port = PORT | 
					
						
							| 
									
										
										
										
											2010-12-30 21:33:07 +00:00
										 |  |  |     i = host.find(':') | 
					
						
							| 
									
										
										
										
											2004-07-18 05:56:09 +00:00
										 |  |  |     if i >= 0: | 
					
						
							| 
									
										
										
										
											2019-04-22 21:28:57 +08:00
										 |  |  |         port = int(host[i+1:]) | 
					
						
							| 
									
										
										
										
											2004-07-18 05:56:09 +00:00
										 |  |  |         host = host[:i] | 
					
						
							| 
									
										
										
										
											2010-12-30 21:33:07 +00:00
										 |  |  |     command = ' '.join(sys.argv[2:]) | 
					
						
							| 
									
										
										
										
											2019-03-30 08:33:02 +02:00
										 |  |  |     with socket(AF_INET, SOCK_STREAM) as s: | 
					
						
							|  |  |  |         s.connect((host, port)) | 
					
						
							|  |  |  |         s.send(command.encode()) | 
					
						
							|  |  |  |         s.shutdown(SHUT_WR) | 
					
						
							|  |  |  |         reply = b'' | 
					
						
							|  |  |  |         while True: | 
					
						
							|  |  |  |             data = s.recv(BUFSIZE) | 
					
						
							|  |  |  |             if not data: | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |             reply += data | 
					
						
							|  |  |  |         print(reply.decode(), end=' ') | 
					
						
							| 
									
										
										
										
											1995-04-10 11:46:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | main() |