Added exception catching with printing to thread-safe console. Removed press enter call.
Changed output a little bit. Also just realized it actually should be easy to parse `p4 fstat ...`, I just need to crab the clientFile output, and this script should be sped up substantially. I need to figure out the best way to break this down, don't want it to be called on a huge directory, but each subdirectory to split up the work. That said, that would miss the top level files. A good alternative to not waiting is to see if I can grab the process output while it's working, instead of waiting for it to be done. This would actually work perfectly; it's just tricky trying to figure out if I can break this up. This would also still delay the start of the script. Could do a mix of local and tree based fstat. Start with local and switch to the tree.
This commit is contained in:
parent
d3fdef1342
commit
8bb78e7c02
|
@ -4,6 +4,7 @@
|
||||||
# python_version : 2.7.6 and 3.4.0
|
# python_version : 2.7.6 and 3.4.0
|
||||||
# =================================
|
# =================================
|
||||||
|
|
||||||
|
# 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: 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: switch to faster method of calling p4 fstat on an entire directory and parsing it's output
|
||||||
# todo: add option of using send2trash
|
# todo: add option of using send2trash
|
||||||
|
@ -173,8 +174,17 @@ class Worker( threading.Thread ):
|
||||||
files = []
|
files = []
|
||||||
command = "p4 fstat *"
|
command = "p4 fstat *"
|
||||||
|
|
||||||
|
try:
|
||||||
proc = subprocess.Popen( command.split( ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=directory )
|
proc = subprocess.Popen( command.split( ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=directory )
|
||||||
(out, err) = proc.communicate()
|
(out, err) = proc.communicate()
|
||||||
|
except Exception as ex:
|
||||||
|
self.console.write( "| " + type( ex ) )
|
||||||
|
self.console.write( "| " + ex.args )
|
||||||
|
self.console.write( "| " + ex )
|
||||||
|
self.console.write( "|ERROR." )
|
||||||
|
self.console.flush( )
|
||||||
|
self.queue.task_done( )
|
||||||
|
continue
|
||||||
|
|
||||||
for line in err.decode('utf-8').split( os.linesep ):
|
for line in err.decode('utf-8').split( os.linesep ):
|
||||||
if len( line ) == 0:
|
if len( line ) == 0:
|
||||||
|
@ -229,6 +239,7 @@ def main( args ):
|
||||||
|
|
||||||
parser.add_option( "-d", "--dir", dest="directory", help="Desired directory to crawl.", default=None )
|
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 )
|
parser.add_option( "-t", "--threads", dest="thread_count", help="Number of threads to crawl your drive and poll p4.", default=100 )
|
||||||
|
parser.add_option( "-q", "--quiet", action="store_false", dest="quiet", default=False )
|
||||||
parser.add_option( "-v", "--verbose", action="store_true", dest="verbose", default=True )
|
parser.add_option( "-v", "--verbose", action="store_true", dest="verbose", default=True )
|
||||||
|
|
||||||
( options, args ) = parser.parse_args( )
|
( options, args ) = parser.parse_args( )
|
||||||
|
@ -296,5 +307,3 @@ if __name__ == "__main__":
|
||||||
except:
|
except:
|
||||||
print( "Unexpected error!" )
|
print( "Unexpected error!" )
|
||||||
traceback.print_exc( file = sys.stdout )
|
traceback.print_exc( file = sys.stdout )
|
||||||
|
|
||||||
PressEnter()
|
|
Loading…
Reference in New Issue