#!/usr/bin/python3
import os
import sys
from threading import Thread
from queue import Queue
import os

indicator = sys.argv[-2]

if indicator == '-g':
    SEARCH_PATH = os.path.expanduser('~')
else:
    SEARCH_PATH = os.getcwd()

SEARCH_NAME = sys.argv[-1]

print("The directory you are searching is: ", SEARCH_PATH)

NUMBER_OF_THREADS = 5
q = Queue(maxsize = 0)

def do_stuff(q):
    while True:
        x = q.get()
        search(x, SEARCH_NAME)
        q.task_done()

def search(the_dir, name):
    files_in_dir = os.listdir(the_dir)
    for i in files_in_dir:
        if name in i:
            print(os.path.join(the_dir, i))
        if os.path.isdir(os.path.join(the_dir, i)):
            q.put(os.path.join(the_dir, i))

for i in range(NUMBER_OF_THREADS):
    worker = Thread(target=do_stuff, args = (q,))
    worker.setDaemon(True)
    worker.start()

q.put(SEARCH_PATH)

q.join()
