From 8bb78e7c02f13afdadca9b7b27090345753b3dbc Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 9 May 2014 11:51:59 -0600 Subject: [PATCH] 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. --- p4RemoveUnversioned.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/p4RemoveUnversioned.py b/p4RemoveUnversioned.py index 154728b..d2e326b 100644 --- a/p4RemoveUnversioned.py +++ b/p4RemoveUnversioned.py @@ -4,6 +4,7 @@ # 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: switch to faster method of calling p4 fstat on an entire directory and parsing it's output # todo: add option of using send2trash @@ -160,7 +161,7 @@ class Worker( threading.Thread ): if len( new_line ) > 0: file_regexes.append( re.compile( os.path.join( re.escape( directory + os.sep ), new_line ) ) ) - self.console.write( "|Appending ignores from " + path ) + self.console.write( "| Appending ignores from " + path ) with self.files_to_ignore.mutex: if directory not in self.files_to_ignore: self.files_to_ignore[ directory ] = [] @@ -173,8 +174,17 @@ class Worker( threading.Thread ): files = [] command = "p4 fstat *" - proc = subprocess.Popen( command.split( ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=directory ) - (out, err) = proc.communicate() + try: + proc = subprocess.Popen( command.split( ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=directory ) + (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 ): 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( "-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 ) ( options, args ) = parser.parse_args( ) @@ -295,6 +306,4 @@ if __name__ == "__main__": main( sys.argv ) except: print( "Unexpected error!" ) - traceback.print_exc( file = sys.stdout ) - - PressEnter() \ No newline at end of file + traceback.print_exc( file = sys.stdout ) \ No newline at end of file