Fixed console to exit properly, wasn't finished frankly.

Script now exits as expected.
This commit is contained in:
Brian 2014-05-09 14:16:13 -06:00
parent 4bb145e4ca
commit b3b960e9ef
1 changed files with 10 additions and 8 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/python
#!/usr/bin/python
# -*- coding: utf8 -*-
# author : Brian Ernst
# python_version : 2.7.6 and 3.4.0
# =================================
# todo: switch to `p4 fstat ...`, and parse the output for clientFile and cache it.
# todo: switch to `p4 fstat ...`, and parse the output for clientFile and cache it.
# todo: have a backup feature, make sure files are moved to the recycle bin or a temporary file.
# todo: switch to faster method of calling p4 fstat on an entire directory and parsing it's output
# todo: add option of using send2trash
@ -93,11 +93,10 @@ class Console( threading.Thread ):
return self
def __exit__( self, type, value, tb ):
self.running = False
self.queue.put( ( Console.MSG.SHUTDOWN, ) )
self.queue.join( )
def run( self ):
# TODO: switch to a queue so we're not spinning and wasting a thread
self.running = True
while True:
data = self.queue.get( )
event = data[0]
@ -107,6 +106,8 @@ class Console( threading.Thread ):
for ( pid, buffer ) in self.buffers.iteritems( ):
for line in buffer:
print( line )
self.buffers.clear( )
self.queue.task_done( )
break
elif event == Console.MSG.WRITE:
@ -126,6 +127,8 @@ class Console( threading.Thread ):
if pid in self.buffers:
self.buffers.pop( pid, None )
self.queue.task_done( )
class Worker( threading.Thread ):
def __init__( self, console, queue, files_to_ignore ):
threading.Thread.__init__( self )
@ -237,8 +240,8 @@ def main( args ):
print( 'Perforce Command-line Client(p4) is required for this script.' )
sys.exit( 1 )
#http://docs.python.org/library/optparse.html
parser = optparse.OptionParser( )
#http://docs.python.org/library/optparse.html
parser = optparse.OptionParser( )
parser.add_option( "-d", "--dir", dest="directory", help="Desired directory to crawl.", default=None )
parser.add_option( "-t", "--threads", dest="thread_count", help="Number of threads to crawl your drive and poll p4.", default=100 )
@ -247,7 +250,6 @@ def main( args ):
( options, args ) = parser.parse_args( )
root_full_path = os.getcwd( )
# Files are added from .p4ignore