Made script obey quiet option. Added file and error count to print at end.

Also made sure the error output gets piped and doesn't show up in
console. However, we shouldn't ignore any error output, this should be
accounted for and properly logged. So, this is a TODO.
This commit is contained in:
Brian 2014-05-13 14:08:16 -06:00
parent 0dcd14a73b
commit 4435a36bed
1 changed files with 37 additions and 15 deletions

View File

@ -94,7 +94,7 @@ def get_client_set( path ):
command = "p4 fstat ..."
proc = subprocess.Popen( command.split( ), stdout=subprocess.PIPE, stderr=None, cwd=path )
proc = subprocess.Popen( command.split( ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path )
for line in proc.stdout:
line = get_str_from_process_stdout( line )
@ -222,39 +222,61 @@ def main( args ):
directory = normpath( options.directory if options.directory is not None else os.getcwd( ) )
remove_count = 0
warning_count = 0
error_count = 0
with Console( auto_flush_num=20, auto_flush_time=1000 ) as c:
c.writeflush( "Caching files in depot..." )
if not options.quiet:
c.writeflush( "Caching files in depot..." )
files_in_depot = get_client_set( directory )
c.writeflush( "Checking " + directory)
if not options.quiet:
c.writeflush( "Checking " + directory)
for root, dirs, files in os.walk( directory ):
ignore_list = {}#get_ignore_list( root, files_to_ignore )
c.write( "|Checking " + root )
if not options.quiet:
c.write( "|Checking " + root )
for d in dirs:
path = join( root, d )
if match_in_ignore_list( path, ignore_list ):
# add option of using send2trash
c.write( "| ignoring " + d )
if not options.quiet:
c.write( "| ignoring " + d )
dirs.remove( d )
for f in files:
path = normpath( join( root, f ) )
if path not in files_in_depot:
c.write( "| " + path )
c.write( "| " + f + " is unversioned, removing it." )
#try:
# os.chmod( path, stat.S_IWRITE )
# os.remove( path )
#except OSError as ex:
# c.writeflush( "| " + type( ex ).__name__ )
# c.writeflush( "| " + repr( ex ) )
# c.writeflush( "|ERROR." )
if not options.quiet:
c.write( "| " + f + " is unversioned, removing it." )
try:
os.chmod( path, stat.S_IWRITE )
os.remove( path )
remove_count += 1
except OSError as ex:
c.writeflush( "| " + type( ex ).__name__ )
c.writeflush( "| " + repr( ex ) )
c.writeflush( "|ERROR." )
c.write( "|Done." )
error_count += 1
if not options.quiet:
c.write( "|Done." )
output = "\nRemoved " + str( remove_count ) + " file/s"
if warning_count > 0:
output += " w/ " + str( warning_count ) + " warning/s"
if error_count > 0:
output += " w/ " + str( error_count ) + " errors/s"
c.write( output + "." )
if __name__ == "__main__":
try: