Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import os
import sys
import subprocess
def Execute( command, cwd=None ):
result = 0
output = ""
print( "Run command [" + command + "]" )
try:
output = subprocess.check_output( command, cwd=cwd )
except subprocess.CalledProcessError as error:
output = error.output
result = error.returncode
if result > 0:
print( output )
raise RuntimeError()
####################################################
def ExecuteReturnOutput( command, cwd=None ):
result = 0
output = ""
print( "Run command [" + command + "]" )
try:
output = subprocess.check_output( command, cwd=cwd )
except subprocess.CalledProcessError as error:
output = error.output
result = error.returncode
if result > 0:
print( output )
raise RuntimeError()
return output
####################################################
# The directory to walk to search for files
searchDir = "."
# The extension of the files to search for
ext = ".ext"
lfsFilesString = ExecuteReturnOutput( "git lfs ls-files" )
#print( lfsFilesString.decode( "utf-8" ) )
lfsFilesRaw = lfsFilesString.decode( "utf-8" ).split( "\n" )
lfsFiles = []
for lfsFileRaw in lfsFilesRaw:
#print( "lfs file [" + lfsFile + "]" )
if ( len( lfsFileRaw.strip() ) > 0 ):
#print( lfsFileRaw.split( " ", 2 ) )
#print( lfsFileRaw )
lfsFiles.append( lfsFileRaw.split( " ", 2 )[2] )
#for lfsFile in lfsFiles:
# print( "lfs file [" + lfsFile + "]" )
count = 0
for root, directories, files in os.walk( searchDir ):
for file in files:
if ( os.path.splitext( file )[1] == ext ):
count += 1
#print( "Found file [" + os.path.join( root, file ) + "]" )
filePath = os.path.join( root, file ).replace( "\\", "/" )
if ( not ( filePath in lfsFiles ) ):
gitCmd = "git lfs migrate import --no-rewrite \"" + filePath + "\""
#print( gitCmd )
Execute( gitCmd )
#else:
# print( "File [" + filePath + "] already in LFS" )
#else:
# print ("Found non-ext file [" + file + "]" )
print( "Found [" + str( count ) + "] files" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.