Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sanity checks for file sizes. #264

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ def check_newlines(self, filename: str) -> None:
if len(data) > 0 and data[-1] != '\n':
self.warning(f"The file {filename} does not end with '\\n'.")

def check_size_limits(self, filename: str) -> None:
filesize = os.path.getsize(filename) / 1024.0 / 1024.0
if filesize > 1000:
self.error(f'The file {filename} ({filesize:.1f} Mb) is larger than 1000 Mb and can not be installed.')
elif filesize > 100:
self.warning(f'The file {filename} ({filesize:.1f} Mb) is larger than 100 Mb. This may cause performance issues and is not recommended.')

def strip_path_prefix(self, path: str) -> str:
return os.path.relpath(path, os.path.join(self._problem.probdir, 'data'))

Expand All @@ -213,6 +220,8 @@ def check(self, context: Context) -> bool:
self.check_basename(self.ansfile)
self.check_newlines(self.infile)
self.check_newlines(self.ansfile)
self.check_size_limits(self.infile)
self.check_size_limits(self.ansfile)
self._problem.input_validators.validate(self)
anssize = os.path.getsize(self.ansfile) / 1024.0 / 1024.0
outputlim = self._problem.config.get('limits')['output']
Expand Down