Skip to content

Commit 2cbe919

Browse files
authored
Merge pull request #221 from ghamerly/check-for-large-files
problem2html.py: warn about large generated files
2 parents 7673dbb + 1e4a309 commit 2cbe919

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

problemtools/problem2html.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def convert(problem, options=None):
9090
if not options.quiet:
9191
print("Warning: Command 'tidy' not found. Install tidy or run with --messy")
9292

93+
# identify any large generated files (especially images)
94+
if not options.quiet:
95+
for path, dirs, files in os.walk('.'):
96+
for f in files:
97+
file_size_kib = os.stat(os.path.join(path, f)).st_size // 1024
98+
if file_size_kib > 1024:
99+
print(f"WARNING: FILE {f} HAS SIZE {file_size_kib} KiB; CONSIDER REDUCING IT")
100+
elif file_size_kib > 300:
101+
print(f"Warning: file {f} has size {file_size_kib} KiB; consider reducing it")
102+
93103
if options.bodyonly:
94104
content = open(destfile).read()
95105
body = re.search('<body>(.*)</body>', content, re.DOTALL)

0 commit comments

Comments
 (0)