Skip to content

Instantly share code, notes, and snippets.

@mcrd25
Created November 4, 2020 18:59
Show Gist options
  • Save mcrd25/5628465104cd213239578477e746bf47 to your computer and use it in GitHub Desktop.
Save mcrd25/5628465104cd213239578477e746bf47 to your computer and use it in GitHub Desktop.
Python Script to Check if Directory's initial commit is too big (will be extended to be more complex)
#!/usr/bin/env python3
import os
# python function to check size of directory in bytes
def get_directory_size(directory):
total = 0
try:
# check files in directory
for entry in os.scandir(directory):
if entry.is_file():
total += entry.stat().st_size
elif entry.is_dir():
total += get_directory_size(entry.path)
except NotADirectoryError:
return os.path.getsize(directory)
except PermissionError:
return 0
return total
def github_friendly(size):
# if directory size is already more than or equal to 100MB it is not fit to be a GitHub repo's intial commit
return size < 100000000
directory = input("Enter directory being checked")
if github_friendly(get_directory_size(directory)):
print ('You are safe to push')
else:
print('You are not safe to push')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment