Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import sys, os
- import tarfile
- import shutil
- import subprocess
- import requests
- from time import sleep
- from git import Repo
- from openpyxl import *
- #Class for the fancy colors in the terminal YAY
- class bcolors():
- HEADER = '\033[95m'
- OKBLUE = '\033[94m'
- OKGREEN = '\033[92m'
- WARNING = '\033[93m'
- FAIL = '\033[91m'
- ENDC = '\033[0m'
- CLEAR = '\033[2J'
- #POST: returns the size of the folder in the path
- def getSize(path):
- #start_time = time.time()
- totalSize = 0
- if os.path.isdir(path):
- for dirpath, dirnames, filenames in os.walk(path):
- for fName in filenames:
- fp = os.path.join(dirpath, fName)
- #Error
- try:
- totalSize += os.path.getsize(fp)
- except ErrorGetSize:
- print "Error in GetSize"
- #print time.time() - start_time, "seconds"
- return totalSize
- else:
- return os.path.getsize(path)
- def doTheMagic(excelFileDir, columnNumber):
- repositoriesId = random.randint(1, 10000213)
- repos = requests.get('https://api.github.com/repositories', params={'since':repositoriesId})
- if repos.status_code != 200:
- print("Error in GET")
- sys.exit(1)
- reposJSON = repos.json()
- repoHtml = reposJSON[0]["html_url"]
- repoName = str(reposJSON[0]["name"] + '-' + str(repositoriesId))
- cloneDir = os.path.join(os.getcwd(), os.path.join("clones", repoName))
- if not os.path.exists(cloneDir):
- os.makedirs(cloneDir)
- Repo.clone_from(repoHtml, cloneDir)
- shutil.make_archive(cloneDir, format="bztar", root_dir=cloneDir)
- shutil.make_archive(cloneDir, format="tar", root_dir=cloneDir)
- shutil.make_archive(cloneDir, format="gztar", root_dir=cloneDir)
- shutil.make_archive(cloneDir, format="zip", root_dir=cloneDir)
- #7zip
- subprocess.call(["./7za", "a", cloneDir, cloneDir])
- #DATA
- folderSize = getSize(cloneDir)
- tarSize = os.path.getsize(cloneDir+".tar")
- zipSize = os.path.getsize(cloneDir+".zip")
- gzSize = os.path.getsize(cloneDir+".tar.gz")
- bz2Size = os.path.getsize(cloneDir+".tar.bz2")
- sevenzSize = os.path.getsize(cloneDir+".7z")
- #Write results to database
- wb = load_workbook(excelFileDir)
- ws = wb.active
- #Headers
- ws['A2'] = "FolderSize"
- ws['A3'] = "TarSize"
- ws['A4'] = "ZipSize"
- ws['A5'] = "GzSize"
- ws['A6'] = "Bz2Size"
- ws['A7'] = "7sSize"
- ws.cell(row=1, column=columnNumber+2, value=repoName)
- ws.cell(row=2, column=columnNumber+2, value=folderSize)
- ws.cell(row=3, column=columnNumber+2, value=tarSize)
- ws.cell(row=4, column=columnNumber+2, value=zipSize)
- ws.cell(row=5, column=columnNumber+2, value=gzSize)
- ws.cell(row=6, column=columnNumber+2, value=bz2Size)
- ws.cell(row=7, column=columnNumber+2, value=sevenzSize)
- wb.save(excelFileDir)
- #OUTPUT
- print bcolors.HEADER + repoName + bcolors.ENDC
- print "Size of the directory:", bcolors.OKBLUE + str(folderSize) + bcolors.ENDC
- print "Size of the tar file", bcolors.OKBLUE + str(tarSize) + bcolors.ENDC
- print "Size of the zip file", bcolors.OKBLUE + str(zipSize) + bcolors.ENDC
- print "Size of the gzip file", bcolors.OKBLUE + str(gzSize) + bcolors.ENDC
- print "Size of the bzip file", bcolors.OKBLUE + str(bz2Size) + bcolors.ENDC
- print "Size of the 7z file", bcolors.OKBLUE + str(sevenzSize) + bcolors.ENDC
- if __name__ == '__main__':
- excelFolderDir = os.getcwd() + "/excels"
- if not os.path.exists(excelFolderDir):
- os.makedirs(excelFolderDir)
- excelFileDir = excelFolderDir + "/" + str(sys.argv[2]) + ".xlsx"
- #Create excel file
- wb = Workbook()
- wb.save(excelFileDir)
- print "EXCEL CREATED"
- for i in range(0, int(sys.argv[1])):
- doTheMagic(excelFileDir, i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement