From 3ffdd761474ad404d0830ac4436f3d63f26f0dc0 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 13 May 2014 20:45:55 -0600 Subject: [PATCH] Added basic worker thread back in, and TODO comments for multi-threading this new script. --- p4RemoveUnversioned.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/p4RemoveUnversioned.py b/p4RemoveUnversioned.py index 30c44c1..8fd2a8d 100644 --- a/p4RemoveUnversioned.py +++ b/p4RemoveUnversioned.py @@ -212,6 +212,34 @@ class Console( threading.Thread ): self.queue.task_done( ) +class Worker( threading.Thread ): + def __init__( self, console, queue, files_to_ignore ): + threading.Thread.__init__( self ) + + self.console = console + self.queue = queue + self.files_to_ignore = files_to_ignore + + def run( self ): + while True: + ( cmd, data ) = self.queue.get( ) + + if cmd == MSG.SHUTDOWN: + self.queue.task_done( ) + self.console.flush( ) + break + + if cmd != MSG.PARSE_DIRECTORY or data is None: + self.console.flush( ) + self.queue.task_done( ) + continue + + directory = data + + # add threading stuffs + + self.queue.task_done( ) + def main( args ): # check requirements if call_process( 'p4 -V' ) != 0: @@ -242,8 +270,18 @@ def main( args ): with Console( auto_flush_num=20, auto_flush_time=1000 ) as c: if not options.quiet: c.writeflush( "Caching files in depot, this may take a little while..." ) + + # TODO: push this off to a thread and walk the directory so we get a headstart. files_in_depot = get_client_set( directory ) + # TODO: push a os.walk request off to a thread to build a list of files in the directory; create batch based on directory? + + # TODO: at this point join on both tasks to wait until they're done + + # TODO: kick off file removal, make batches from the files for threads to work on since testing has to be done for each. + # need to figure out the best way to do this since the ignore list needs to be properly built for each directory; + # will at least need to redo how the ignore lists are handled for efficiencies sake. + if not options.quiet: c.writeflush( "Checking " + directory) for root, dirs, files in os.walk( directory ):