Skip to content

Commit 2b4a35a

Browse files
authored
Merge pull request #70 from brad-colbert/server_new_command_line
v1.3.3: Server command line additions
2 parents 13f30c5 + 28c6597 commit 2b4a35a

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

server/yeet_to_yail.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
logging.basicConfig(level=logging.WARN)
2424
logger = logging.getLogger(__name__)
2525

26+
SOCKET_WAIT_TIME = 1
2627
GRAPHICS_8 = 2
2728
GRAPHICS_9 = 4
2829
GRAPHICS_RANDOM = 42
@@ -154,7 +155,7 @@ def stream_YAI(client: str, gfx_mode: int, url: str = None, filepath: str = None
154155
# download the body of response by chunk, not immediately
155156
try:
156157
if url is not None:
157-
logger.info('Loading', url, url.encode())
158+
logger.info(f'Loading %s %s' % (url, url.encode()))
158159

159160
file_size = 0
160161

@@ -295,7 +296,7 @@ def handle_client_connection(client_socket):
295296
client_mode = None
296297

297298
connections = connections + 1
298-
logger.info('Starting Connection:', connections)
299+
logger.info(f'Starting Connection: %d' % connections)
299300

300301
try:
301302
done = False
@@ -330,7 +331,7 @@ def handle_client_connection(client_socket):
330331
logger.warning(f'Problem with %s trying another...', url)
331332
url_idx = random.randint(0, len(urls)-1)
332333
url = urls[url_idx]
333-
time.sleep(1)
334+
time.sleep(SOCKET_WAIT_TIME)
334335
tokens = []
335336

336337
elif tokens[0] == 'files':
@@ -344,7 +345,7 @@ def handle_client_connection(client_socket):
344345
logger.warning(f'Problem with %s trying another...', filename)
345346
file_idx = random.randint(0, len(filenames)-1)
346347
filename = filenames[file_idx]
347-
time.sleep(1)
348+
time.sleep(SOCKET_WAIT_TIME)
348349
tokens.pop(0)
349350

350351
elif tokens[0] == 'next':
@@ -358,7 +359,7 @@ def handle_client_connection(client_socket):
358359
logger.warning('Problem with image trying another...')
359360
url_idx = random.randint(0, len(urls)-1)
360361
url = urls[url_idx]
361-
time.sleep(1)
362+
time.sleep(SOCKET_WAIT_TIME)
362363
tokens.pop(0)
363364
elif client_mode == 'video':
364365
send_yail_data(client_socket)
@@ -374,7 +375,7 @@ def handle_client_connection(client_socket):
374375
logger.warning(f'Problem with %s trying another...', filename)
375376
file_idx = random.randint(0, len(filenames)-1)
376377
filename = filenames[file_idx]
377-
time.sleep(1)
378+
time.sleep(SOCKET_WAIT_TIME)
378379
tokens.pop(0)
379380

380381
elif tokens[0] == 'gfx':
@@ -399,7 +400,7 @@ def handle_client_connection(client_socket):
399400
connections = connections - 1
400401
if connections == 0: # Maybe should look into killing this thread when there are no video connections.
401402
camera_done = True
402-
time.sleep(1)
403+
time.sleep(SOCKET_WAIT_TIME)
403404
camera_thread = None
404405

405406
def process_files(input_path: Union[str, List[str]],
@@ -437,41 +438,53 @@ def main():
437438
bind_ip = '0.0.0.0'
438439
bind_port = 5556
439440

440-
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
441-
server.bind((bind_ip, bind_port))
442-
server.listen(10) # max backlog of connections
443-
444-
logger.info('Listening on {}:{}'.format(bind_ip, bind_port))
445-
446441
# Check if any arguments were provided (other than the script name)
447442
if len(sys.argv) > 1:
448443
parser = argparse.ArgumentParser(description="Yeets images to YAIL")
449444
parser.add_argument('paths', nargs='?', default=None, help='Directory path or list of file paths')
450445
parser.add_argument('--extensions', nargs='+', default=['.jpg', '.jpeg', '.gif', '.png'], help='List of file extensions to process', required=False)
451-
parser.add_argument('--mode', nargs='?', default='9', help='List of file extensions to process', required=False)
452446
parser.add_argument('--camera', nargs='?', default=None, help='The camera device to use', required=False)
447+
parser.add_argument('--port', nargs='+', default=None, help='Specify the port to listen too', required=False)
448+
parser.add_argument('--loglevel', nargs='+', default=None, help='The level of logging', required=False)
453449

454450
args = parser.parse_args()
455451

456-
if args.mode == '8':
457-
gfx_mode = GRAPHICS_8
458-
elif args.mode == '9':
459-
gfx_mode = GRAPHICS_9
460-
461452
if args.camera:
462453
camera_name = args.camera
463454

464455
if args.paths is not None and len(args.paths) == 1 and os.path.isdir(args.paths[0]):
465456
# If a single argument is passed and it's a directory
466457
directory_path = args.paths[0]
467-
print("Processing files in directory:")
458+
logger.info("Processing files in directory:")
468459
process_files(directory_path, args.extensions, F)
469460
elif args.paths:
470461
# If multiple file paths are passed
471462
file_list = args.paths
472-
print("\nProcessing specific files in list:")
463+
logger.info("Processing specific files in list:")
473464
process_files(file_list, args.extensions, F)
474465

466+
if args.loglevel:
467+
loglevel = args.loglevel[0].upper()
468+
if loglevel == 'DEBUG':
469+
logger.setLevel(logging.DEBUG)
470+
elif loglevel == 'INFO':
471+
logger.setLevel(logging.INFO)
472+
elif loglevel == 'WARN':
473+
logger.setLevel(logging.WARN)
474+
elif loglevel == 'ERROR':
475+
logger.setLevel(logging.ERROR)
476+
elif loglevel == 'CRITICAL':
477+
logger.setLevel(logging.CRITICAL)
478+
479+
if args.port:
480+
bind_port = int(args.port[0])
481+
482+
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
483+
server.bind((bind_ip, bind_port))
484+
server.listen(10) # max backlog of connections
485+
486+
logger.info('Listening on {}:{}'.format(bind_ip, bind_port))
487+
475488
while True:
476489
client_sock, address = server.accept()
477490
logger.info('Accepted connection from {}:{}'.format(address[0], address[1]))
@@ -483,4 +496,4 @@ def main():
483496
client_handler.start()
484497

485498
if __name__ == "__main__":
486-
main()
499+
main()

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
#define MAJOR_VERSION 1
77
#define MINOR_VERSION 3
8-
#define BUILD_VERSION 2
8+
#define BUILD_VERSION 3
99

1010
#endif // YAIL_VERSION_H

0 commit comments

Comments
 (0)