Skip to content

Commit

Permalink
Adding sanity checks for file sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pehrsoderman committed Jun 10, 2024
1 parent 75cd6f3 commit db1f49c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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 @@ -174,6 +181,8 @@ def check(self, args: argparse.Namespace) -> 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_format_validators.validate(self)
anssize = os.path.getsize(self.ansfile) / 1024.0 / 1024.0
outputlim = self._problem.config.get('limits')['output']
Expand Down

0 comments on commit db1f49c

Please sign in to comment.