Created
November 4, 2020 18:59
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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