|
| 1 | +import os |
| 2 | +import zipfile |
| 3 | + |
| 4 | +srcext_list = ['.c', '.h', '.cpp', '.hpp', '.txt'] |
| 5 | +binext_list = ['.dll', '.obj', '.o', '.a'] |
| 6 | +arcext_list = ['.zip', '.gz', '.tar', '.Z'] |
| 7 | + |
| 8 | +src_list = [] |
| 9 | +bin_list = [] |
| 10 | +arc_list = [] |
| 11 | +other_list = [] |
| 12 | +folders_binonly_list = [] |
| 13 | + |
| 14 | +def process_zip(name,path): |
| 15 | + with zipfile.ZipFile(path, 'r') as zf: |
| 16 | + for f in zf.infolist(): |
| 17 | + checkfile(os.path.basename(f.filename), path + "#" + f.filename, f.compress_size) |
| 18 | + |
| 19 | +def checkfile(name, path, size): |
| 20 | + global count_files |
| 21 | + global size_binlarge |
| 22 | + count_files = count_files + 1 |
| 23 | + print(path) |
| 24 | + dot = name.find(".") |
| 25 | + if (dot >= 0): |
| 26 | + if name[dot:] in srcext_list: |
| 27 | + src_list.append(path) |
| 28 | + print("source") |
| 29 | + elif name[dot:] in binext_list: |
| 30 | + bin_list.append(path) |
| 31 | + if size > 100000: |
| 32 | + size_binlarge += size |
| 33 | + print("binary") |
| 34 | + elif name[dot:] in arcext_list: |
| 35 | + arc_list.append(path) |
| 36 | + print("archive") |
| 37 | + if name[dot:] == '.zip': |
| 38 | + process_zip(name, path) |
| 39 | + else: |
| 40 | + print("other") |
| 41 | + other_list.append(path) |
| 42 | + else: |
| 43 | + print("other") |
| 44 | + other_list.append(path) |
| 45 | + |
| 46 | +def process(path): |
| 47 | + totalsize = 0 |
| 48 | + for entry in os.scandir(path): |
| 49 | + if entry.is_dir(follow_symlinks=False): |
| 50 | + totalsize += process(entry.path) |
| 51 | + else: |
| 52 | + checkfile(entry.name, entry.path, entry.stat(follow_symlinks=False).st_size) |
| 53 | + totalsize += entry.stat(follow_symlinks=False).st_size |
| 54 | + return totalsize |
| 55 | + |
| 56 | +count_files = 0 |
| 57 | +size_binlarge = 0 |
| 58 | + |
| 59 | +print("Total file size = {}".format(process("."))) |
| 60 | +print("Total files processed = {}".format(count_files)) |
| 61 | +print("Source files = {}".format(len(src_list))) |
| 62 | +print("Binary files = {}".format(len(bin_list))) |
| 63 | +print("Archive files = {}".format(len(arc_list))) |
| 64 | +print("Other files = {}".format(len(other_list))) |
| 65 | +print("Large binary file size = {}".format(size_binlarge)) |
0 commit comments