Fixed a bug from old code so the script would work, tweaked output.

I was trying to use `p4 have` for speed, but it doesn't seem to work
with files that are added to a changelist but not to a repo.  So I had
to resort back to `p4 fstat`.
This commit is contained in:
Brian 2014-05-08 19:05:02 -06:00
parent 266c5555ba
commit 2bb0fa671d
1 changed files with 21 additions and 17 deletions

View File

@ -42,8 +42,6 @@ def main( ):
if path_to_find in files_to_ignore:
ignore_list = ignore_list + files_to_ignore[ path_to_find ]
# ignore_list = [ r for p in [ os.sep.join( dirs[ : i + 1] ) for i, val in enumerate( dirs ) ] if p in files_to_ignore for r in files_to_ignore[ p ] ]
return ignore_list
def match_in_ignore_list( path, ignore_list ):
@ -52,15 +50,15 @@ def main( ):
return True
return False
root = "."
root_full_path = os.getcwd()
root_path = "."
root_full_path = os.getcwd( )
p4_ignore = ".p4ignore"
# make sure script doesn't delete itself
files_to_ignore[ root ] = [ re.compile( os.path.join( re.escape( root + os.sep ), os.path.basename( __file__ ) ) ) ]
files_to_ignore[ root_path ] = [ re.compile( os.path.join( re.escape( root_path + os.sep ), os.path.basename( __file__ ) ) ) ]
for root, dirs, files in os.walk( root ):
for root, dirs, files in os.walk( root_path ):
print ( os.linesep + "Checking '" + root + "' ...")
@ -76,8 +74,8 @@ def main( ):
if len( new_line ) > 0:
file_regexes.append( re.compile( os.path.join( re.escape( root + os.sep ), new_line ) ) )
print( "|appending ignores from " + path )
files_to_ignore[ root ] = file_regexes
print( "|Appending ignores from " + path )
files_to_ignore[ root ] = files_to_ignore[ root ] + file_regexes
ignore_list = get_ignore_list( root )
@ -104,18 +102,19 @@ def main( ):
i = line.rfind( ' - ')
if i >= 0:
basename = line[ : i ]
if basename == "*":
# Directory is empty, we could delete it now
continue
path = os.path.join( root, basename )
if not os.path.isdir( path ):
for file in files:
if file == basename:
files.append( file )
break
files.append( basename )
for file in files:
path = os.path.join( root, file )
if match_in_ignore_list( path, ignore_list ):
print( "| ignoring " + path )
print( "| Ignoring " + path )
continue
print( "| " + file + " is unversioned, removing it." )
@ -126,18 +125,23 @@ def main( ):
path = os.path.join( root, d )
if match_in_ignore_list( path, ignore_list ):
# add option of using send2trash
print( "| ignoring " + d )
print( "| Ignoring " + d )
dirs.remove( d )
print( "|Done." )
print( os.linesep + "Removing empty directories...")
# remove empty directories
for root, dirs, files in os.walk( '.', topdown=False ):
for root, dirs, files in os.walk( root_path, topdown=False ):
for d in dirs:
path = os.path.join( root, d )
if match_in_ignore_list( path, ignore_list ):
# add option of using send2trash
print( "| ignoring " + d )
dirs.remove( d )
try:
os.rmdir(d)
print( "|" + d + " was removed." )
os.rmdir(path)
print( "| " + d + " was removed." )
except OSError:
# Fails on non-empty directory
pass