def copy(self, src, dst): fp = FilePath(self._task_directory, src) if not fp.exists(): return (False, 'No such file') try: fp.copy(dst) (st, msg) = (True, 'OK') return (st, msg) except Exception: # pylint: disable=broad-except return (False, 'Error when copying file')
def copy(self, src, dst): fp = FilePath(self._task_directory, src) if not fp.exists(): return (False, 'No such file') try: fp.copy(dst) (st, msg) = (True, 'OK') return (st, msg) except Exception: # pylint: disable=broad-except return (False, 'Error when copying file')
def copy_to(self, directory): new_dir = directory.mkdir(str(self)) (st, _) = self.compress_dataset() if st: dataset = FilePath(self._directory.chdir('dataset'), 'data.zip') dataset_dst = FilePath(new_dir, 'data.zip') if dataset.exists(): dataset.copy(dataset_dst) (st, _) = self.build_statement() if st: statement = FilePath(new_dir, 'statement.pdf') FilePath(self._directory.chdir('statement'), 'statement.pdf').copy(statement)
def package(self): """Compress statement and dataset of all tasks in a single file""" tmpdir = Directory.tmpdir() try: for task in self._tasks: task.copy_to(tmpdir) self.build_problemset_twoside() self.build_problemset_oneside() oneside = FilePath(self._directory, 'oneside.pdf') if oneside.exists(): oneside.copy(FilePath(tmpdir, 'oneside.pdf')) twoside = FilePath(self._directory, 'twoside.pdf') if twoside.exists(): twoside.copy(FilePath(tmpdir, 'twoside.pdf')) cmd = 'cd %s && zip -r contest.zip .' % tmpdir st = subprocess.call(cmd, stdout=subprocess.DEVNULL, shell=True) contest = FilePath(self._directory, '%s.zip' % self.name) FilePath(tmpdir, 'contest.zip').copy(contest) finally: tmpdir.rmtree() return st == 0