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