Example #1
0
def execute():
    """
       Create execution semaphore and threads.
       Join threads and returns result files. 
    """
    resultfiles = []
    threads = []
    semaphore = threading.BoundedSemaphore(value=Configuration.semaphore)

    for (root, dirs, files) in os.walk(Configuration.sourcedir):
        for file in files:

            # path manipulation
            abspath = os.path.join(root, file)
            relpath = os.path.relpath(abspath, Configuration.sourcedir)

            # Resultdir
            resdir = os.path.join(Configuration.resultdir, os.path.dirname(relpath)) 

            # Create resultdir
            if not os.path.exists(resdir):
                os.makedirs(resdir)

            e = Executor(relpath, file, semaphore)
            e.start()
            threads.append(e)

    for t in threads: 
        t.join() 

    que = Executor.get_queue()

    while que.empty() != True:
        resultfiles = resultfiles + que.get()

    return resultfiles