Skip to content

Instantly share code, notes, and snippets.

@DVDAndroid
Last active April 26, 2021 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DVDAndroid/a8896842a7de3ca2494cb0bff602a1ea to your computer and use it in GitHub Desktop.
Save DVDAndroid/a8896842a7de3ca2494cb0bff602a1ea to your computer and use it in GitHub Desktop.
clear project dirs
import os
import subprocess
import datetime
import math
from pathlib import Path
import shutil
def convert_size(size_bytes):
if size_bytes == 0:
return "0B"
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return "%s %s" % (s, size_name[i])
def check(root, dirs, d):
summ = 0
if "node_modules" in dirs or "node_modules" in root:
return (dirs, summ)
if d in dirs:
##if d == ".git":
## git = subprocess.run(["git", "gc", "--aggressive", "--prune"], cwd=root)
## print(git)
path = Path(root, d)
summ = sum(f.stat().st_size for f in path.glob('**/*') if f.is_file())
date = datetime.datetime.fromtimestamp(path.stat().st_ctime)
#if date.year < 2021:
print(root, d, convert_size(summ), date)
#shutil.rmtree(path)
dirs[:] = [x for x in dirs if x != path]
return (dirs, summ)
def list_dirs(dir):
tot = 0;
for root, d, files in os.walk(dir):
(d, x1) = check(root, d, ".gradle")
#(d, x2) = check(root, d, ".git")
(d, x3) = check(root, d, "build")
tot += x1 + x3
print(tot, convert_size(tot))
list_dirs(xxx)
import os
import subprocess
import math
from pathlib import Path
import shutil
def convert_size(size_bytes):
if size_bytes == 0:
return "0B"
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return "%s %s" % (s, size_name[i])
def check(root, dirs, d):
summ = 0
if d in dirs:
##if d == ".git":
## git = subprocess.run(["git", "gc", "--aggressive", "--prune"], cwd=root)
## print(git)
path = Path(root, d)
summ = sum(f.stat().st_size for f in path.glob('**/*') if f.is_file())
print(root, d, convert_size(summ))
#shutil.rmtree(path)
dirs[:] = [x for x in dirs if f"{root}\\{d}" in x]
return (dirs, summ)
def list_dirs(dir):
tot = 0;
for root, d, files in os.walk(dir):
(d, x1) = check(root, d, "node_modules")
#(d, x2) = check(root, d, ".git")
tot += x1
print(tot, convert_size(tot))
list_dirs("D:\workspaces\www")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment