From 3a0190785e0af38ffe8e7cfc784515a96a7acc0c Mon Sep 17 00:00:00 2001 From: Brad Colbert Date: Fri, 29 Mar 2024 16:54:41 -0700 Subject: [PATCH 1/3] Added --port and --log to command line of server. --- server/yeet_to_yail.py | 53 ++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/server/yeet_to_yail.py b/server/yeet_to_yail.py index 87bbcd4..2f40ea5 100755 --- a/server/yeet_to_yail.py +++ b/server/yeet_to_yail.py @@ -23,6 +23,7 @@ logging.basicConfig(level=logging.WARN) logger = logging.getLogger(__name__) +SOCKET_WAIT_TIME = 1 GRAPHICS_8 = 2 GRAPHICS_9 = 4 GRAPHICS_RANDOM = 42 @@ -154,7 +155,7 @@ def stream_YAI(client: str, gfx_mode: int, url: str = None, filepath: str = None # download the body of response by chunk, not immediately try: if url is not None: - logger.info('Loading', url, url.encode()) + logger.info(f'Loading %s %s' % (url, url.encode())) file_size = 0 @@ -295,7 +296,7 @@ def handle_client_connection(client_socket): client_mode = None connections = connections + 1 - logger.info('Starting Connection:', connections) + logger.info(f'Starting Connection: %d' % connections) try: done = False @@ -330,7 +331,7 @@ def handle_client_connection(client_socket): logger.warning(f'Problem with %s trying another...', url) url_idx = random.randint(0, len(urls)-1) url = urls[url_idx] - time.sleep(1) + time.sleep(SOCKET_WAIT_TIME) tokens = [] elif tokens[0] == 'files': @@ -344,7 +345,7 @@ def handle_client_connection(client_socket): logger.warning(f'Problem with %s trying another...', filename) file_idx = random.randint(0, len(filenames)-1) filename = filenames[file_idx] - time.sleep(1) + time.sleep(SOCKET_WAIT_TIME) tokens.pop(0) elif tokens[0] == 'next': @@ -358,7 +359,7 @@ def handle_client_connection(client_socket): logger.warning('Problem with image trying another...') url_idx = random.randint(0, len(urls)-1) url = urls[url_idx] - time.sleep(1) + time.sleep(SOCKET_WAIT_TIME) tokens.pop(0) elif client_mode == 'video': send_yail_data(client_socket) @@ -374,7 +375,7 @@ def handle_client_connection(client_socket): logger.warning(f'Problem with %s trying another...', filename) file_idx = random.randint(0, len(filenames)-1) filename = filenames[file_idx] - time.sleep(1) + time.sleep(SOCKET_WAIT_TIME) tokens.pop(0) elif tokens[0] == 'gfx': @@ -399,7 +400,7 @@ def handle_client_connection(client_socket): connections = connections - 1 if connections == 0: # Maybe should look into killing this thread when there are no video connections. camera_done = True - time.sleep(1) + time.sleep(SOCKET_WAIT_TIME) camera_thread = None def process_files(input_path: Union[str, List[str]], @@ -437,27 +438,17 @@ def main(): bind_ip = '0.0.0.0' bind_port = 5556 - server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - server.bind((bind_ip, bind_port)) - server.listen(10) # max backlog of connections - - logger.info('Listening on {}:{}'.format(bind_ip, bind_port)) - # Check if any arguments were provided (other than the script name) if len(sys.argv) > 1: parser = argparse.ArgumentParser(description="Yeets images to YAIL") parser.add_argument('paths', nargs='?', default=None, help='Directory path or list of file paths') parser.add_argument('--extensions', nargs='+', default=['.jpg', '.jpeg', '.gif', '.png'], help='List of file extensions to process', required=False) - parser.add_argument('--mode', nargs='?', default='9', help='List of file extensions to process', required=False) parser.add_argument('--camera', nargs='?', default=None, help='The camera device to use', required=False) + parser.add_argument('--port', nargs='+', default=None, help='Specify the port to listen too', required=False) + parser.add_argument('--loglevel', nargs='+', default=None, help='The level of logging', required=False) args = parser.parse_args() - if args.mode == '8': - gfx_mode = GRAPHICS_8 - elif args.mode == '9': - gfx_mode = GRAPHICS_9 - if args.camera: camera_name = args.camera @@ -472,6 +463,28 @@ def main(): print("\nProcessing specific files in list:") process_files(file_list, args.extensions, F) + if args.loglevel: + loglevel = args.loglevel[0].upper() + if loglevel == 'DEBUG': + logger.setLevel(logging.DEBUG) + elif loglevel == 'INFO': + logger.setLevel(logging.INFO) + elif loglevel == 'WARN': + logger.setLevel(logging.WARN) + elif loglevel == 'ERROR': + logger.setLevel(logging.ERROR) + elif loglevel == 'CRITICAL': + logger.setLevel(logging.CRITICAL) + + if args.port: + bind_port = int(args.port[0]) + + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server.bind((bind_ip, bind_port)) + server.listen(10) # max backlog of connections + + logger.info('Listening on {}:{}'.format(bind_ip, bind_port)) + while True: client_sock, address = server.accept() logger.info('Accepted connection from {}:{}'.format(address[0], address[1])) @@ -483,4 +496,4 @@ def main(): client_handler.start() if __name__ == "__main__": - main() + main() \ No newline at end of file From 7a111851191d226ec5eeec6c40d3e5e840f6dc2c Mon Sep 17 00:00:00 2001 From: Brad Colbert Date: Fri, 29 Mar 2024 17:23:11 -0700 Subject: [PATCH 2/3] There were a couple print()'s left over. Converted to logs. --- server/yeet_to_yail.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/yeet_to_yail.py b/server/yeet_to_yail.py index 2f40ea5..ce69de8 100755 --- a/server/yeet_to_yail.py +++ b/server/yeet_to_yail.py @@ -455,12 +455,12 @@ def main(): if args.paths is not None and len(args.paths) == 1 and os.path.isdir(args.paths[0]): # If a single argument is passed and it's a directory directory_path = args.paths[0] - print("Processing files in directory:") + logger.info("Processing files in directory:") process_files(directory_path, args.extensions, F) elif args.paths: # If multiple file paths are passed file_list = args.paths - print("\nProcessing specific files in list:") + logger.info("Processing specific files in list:") process_files(file_list, args.extensions, F) if args.loglevel: From 28c65977c2b8907d5ad4c19abdd250206eff9435 Mon Sep 17 00:00:00 2001 From: Brad Colbert Date: Sat, 30 Mar 2024 10:28:10 -0700 Subject: [PATCH 3/3] Ticked the version for the server updates. --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index b549cba..75958df 100644 --- a/src/version.h +++ b/src/version.h @@ -5,6 +5,6 @@ #define MAJOR_VERSION 1 #define MINOR_VERSION 3 -#define BUILD_VERSION 2 +#define BUILD_VERSION 3 #endif // YAIL_VERSION_H