예제 #1
0
파일: views.py 프로젝트: sio2project/oioioi
def download_input_file_view(request, test_id):
    test = get_object_or_404(Test, id=test_id)

    if not can_admin_instance_of_problem(request, test.problem):
        raise PermissionDenied
    return stream_file(test.input_file,
                       strip_num_or_hash(test.input_file.name))
예제 #2
0
def download_input_file_view(request, test_id):
    test = get_object_or_404(Test, id=test_id)

    if not can_admin_instance_of_problem(request, test.problem):
        raise PermissionDenied
    return stream_file(test.input_file,
                       strip_num_or_hash(test.input_file.name))
예제 #3
0
 def download_name(self):
     ext = split_extension(self.package_file.name)[1]
     if self.problem:
         return self.problem.short_name + ext
     else:
         filename = os.path.split(self.package_file.name)[1]
         return strip_num_or_hash(filename)
예제 #4
0
 def download_name(self):
     ext = split_extension(self.package_file.name)[1]
     if self.problem:
         return self.problem.short_name + ext
     else:
         filename = os.path.split(self.package_file.name)[1]
         return strip_num_or_hash(filename)
예제 #5
0
 def _assertTestsNotInPackage(self, tests, tp):
     zipf = zipfile.ZipFile(tp.package, 'r')
     for t in tests:
         for f in [t.input_file, t.output_file]:
             with self.assertRaises(KeyError):
                 file_name = strip_num_or_hash(os.path.basename(f.file.name))
                 zipf.open(file_name)
     zipf.close()
예제 #6
0
파일: views.py 프로젝트: sio2project/oioioi
def download_checker_exe_view(request, checker_id):
    checker = get_object_or_404(OutputChecker, id=checker_id)
    if not can_admin_instance_of_problem(request, checker.problem):
        raise PermissionDenied
    if not checker.exe_file:
        raise Http404
    return stream_file(checker.exe_file,
                       strip_num_or_hash(checker.exe_file.name))
예제 #7
0
def download_checker_exe_view(request, checker_id):
    checker = get_object_or_404(OutputChecker, id=checker_id)
    if not test.problem_instance.controller.can_see_checker_exe(request, test):
        raise PermissionDenied
    if not checker.exe_file:
        raise Http404
    return stream_file(checker.exe_file,
                       strip_num_or_hash(checker.exe_file.name))
예제 #8
0
def download_checker_exe_view(request, checker_id):
    checker = get_object_or_404(OutputChecker, id=checker_id)
    if not can_admin_instance_of_problem(request, checker.problem):
        raise PermissionDenied
    if not checker.exe_file:
        raise Http404
    return stream_file(checker.exe_file,
                       strip_num_or_hash(checker.exe_file.name))
예제 #9
0
 def _assertTestsInPackage(self, tests, tp):
     zipf = zipfile.ZipFile(tp.package, 'r')
     for t in tests:
         for f in [t.input_file, t.output_file]:
             file_name = strip_num_or_hash(os.path.basename(f.file.name))
             content1 = zipf.open(file_name).read()
             content2 = f.file.file.read()
             self.assertEqual(content1, content2)
     zipf.close()
예제 #10
0
파일: tests.py 프로젝트: sio2project/oioioi
 def _assertTestsInPackage(self, tests, tp):
     zipf = zipfile.ZipFile(tp.package, 'r')
     for t in tests:
         for f in [t.input_file, t.output_file]:
             file_name = strip_num_or_hash(os.path.basename(f.file.name))
             content1 = zipf.open(file_name).read()
             content2 = f.file.file.read()
             self.assertEqual(content1, content2)
     zipf.close()
예제 #11
0
파일: tests.py 프로젝트: sio2project/oioioi
 def _assertTestsNotInPackage(self, tests, tp):
     zipf = zipfile.ZipFile(tp.package, 'r')
     for t in tests:
         for f in [t.input_file, t.output_file]:
             with self.assertRaises(KeyError):
                 file_name = strip_num_or_hash(os.path.basename(
                         f.file.name))
                 zipf.open(file_name)
     zipf.close()
예제 #12
0
파일: tests.py 프로젝트: jakubste/oioioi
    def test_strip_num_or_hash(self):
        cases = {
            'abc_1.pdf': 'abc.pdf',
            'abc_123.pdf': 'abc.pdf',
            'abc_45HKmyT.pdf': 'abc.pdf',
            'abc_1.tar.gz': 'abc.tar.gz',
            'abc_45HKmyT.tar.gz': 'abc.tar.gz',
            'abc.tar_1.gz': 'abc.tar.gz',
            'abc.tar.gz': 'abc.tar.gz',
            '/a/b/abc.tar.gz': '/a/b/abc.tar.gz',
            'my_file': 'my_file',
            'a_1_2.pdf': 'a_1.pdf',
        }

        for (before, after) in cases.iteritems():
            self.assertEqual(strip_num_or_hash(before), after)
예제 #13
0
파일: tests.py 프로젝트: sio2project/oioioi
    def test_strip_num_or_hash(self):
        cases = {
            'abc_1.pdf': 'abc.pdf',
            'abc_123.pdf': 'abc.pdf',
            'abc_45HKmyT.pdf': 'abc.pdf',
            'abc_1.tar.gz': 'abc.tar.gz',
            'abc_45HKmyT.tar.gz': 'abc.tar.gz',
            'abc.tar_1.gz': 'abc.tar.gz',
            'abc.tar.gz': 'abc.tar.gz',
            '/a/b/abc.tar.gz': '/a/b/abc.tar.gz',
            'my_file': 'my_file',
            'a_1_2.pdf': 'a_1.pdf',
        }

        for (before, after) in six.iteritems(cases):
            self.assertEqual(strip_num_or_hash(before), after)
예제 #14
0
def _create_tests_package(sender, instance, action, reverse, **kwargs):
    # This function is called upon changing TestsPackage object.
    # The package should be repacked only if set of tests changes
    # but not when, e.g., only the description of package changes.
    if action == 'pre_clear':
        instance._old_tests = list(instance.tests.all())
    elif action == 'post_add':
        if instance._old_tests == list(instance.tests.all()):
            return
        with tempfile.NamedTemporaryFile(delete=False) as f:
            zipf = zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED)
            for test in instance.tests.all():
                for test_file in [test.input_file, test.output_file]:
                    arch_path = strip_num_or_hash(
                            os.path.basename(test_file.file.name))
                    pack_test_file(test_file, arch_path, zipf)
            zipf.close()
            instance.package.save('tests.zip', File(f))
            os.unlink(f.name)
예제 #15
0
파일: models.py 프로젝트: wczyz/oioioi
def _create_tests_package(sender, instance, action, reverse, **kwargs):
    # This function is called upon changing TestsPackage object.
    # The package should be repacked only if set of tests changes
    # but not when, e.g., only the description of package changes.
    if action == 'pre_clear':
        instance._old_tests = list(instance.tests.all())
    elif action == 'post_add':
        if instance._old_tests == list(instance.tests.all()):
            return
        with tempfile.NamedTemporaryFile(delete=False) as f:
            zipf = zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED)
            for test in instance.tests.all():
                for test_file in [test.input_file, test.output_file]:
                    arch_path = strip_num_or_hash(
                        os.path.basename(test_file.file.name))
                    pack_test_file(test_file, arch_path, zipf)
            zipf.close()
            instance.package.save('tests.zip', File(f))
            os.unlink(f.name)
예제 #16
0
 def download_name(self):
     return strip_num_or_hash(self.filename)
예제 #17
0
 def download_name(self):
     return strip_num_or_hash(self.filename)
예제 #18
0
def download_output_file_view(request, test_id):
    test = get_object_or_404(Test, id=test_id)
    if not test.problem_instance.controller.can_see_test(request, test):
        raise PermissionDenied
    return stream_file(test.output_file,
                       strip_num_or_hash(test.output_file.name))