Exemplo n.º 1
0
 def test_list_depending_files(self):
     problem = Problem(Path.cwd(), Path('sample/aplusb'))
     files = list(problem.list_depending_files())  # type: List[Path]
     find_random = False
     find_verifier = False
     for f in files:
         if f.resolve() == Path('common/random.h').resolve():
             find_random = True
         if f.resolve() == Path('sample/aplusb/verifier.cpp').resolve():
             find_verifier = True
     self.assertTrue(find_random)
     self.assertTrue(find_verifier)
Exemplo n.º 2
0
def gen_docs(problems, libdir, docdir: Path):
    logger.info('generate docs')
    for name, probinfo in problems['problems'].items():
        problem = Problem(libdir, libdir / probinfo['dir'])
        probdir = problem.basedir

        # convert task
        html = ToHTMLConverter(probdir)
        with open(docdir / (name + '.html'), 'w', encoding='utf-8') as f:
            f.write(html.html)
Exemplo n.º 3
0
    hostname = environ.get('POSTGRE_HOST', '127.0.0.1')
    port = int(environ.get('POSTGRE_PORT', '5432'))
    user = environ.get('POSTGRE_USER', 'postgres')
    password = environ.get('POSTGRE_PASS', 'passwd')

    conn = psycopg2.connect(
        host=hostname,
        port=port,
        user=user,
        password=password,
        database='librarychecker'
    )

    for name, probinfo in problems['problems'].items():
        title = probinfo['title']
        problem = Problem(libdir, libdir / probinfo['dir'])
        probdir = problem.basedir
        timelimit = problem.config['timelimit']

        with tempfile.NamedTemporaryFile(suffix='.zip') as tmp:
            m = hashlib.sha256()

            with zipfile.ZipFile(tmp.name, 'w') as newzip:
                def zip_write(filename, arcname):
                    newzip.write(filename, arcname)
                    m.update(pack('q', path.getsize(filename)))
                    with open(filename, 'rb') as f:
                        m.update(f.read())
                zip_write(probdir / 'checker.cpp', arcname='checker.cpp')
                for f in sorted(probdir.glob('in/*.in')):
                    zip_write(f, arcname=f.relative_to(probdir))
Exemplo n.º 4
0
    logger.info('connect to SQL')
    hostname = environ.get('POSTGRE_HOST', '127.0.0.1')
    port = int(environ.get('POSTGRE_PORT', '5432'))
    user = environ.get('POSTGRE_USER', 'postgres')
    password = environ.get('POSTGRE_PASS', 'passwd')

    conn = psycopg2.connect(host=hostname,
                            port=port,
                            user=user,
                            password=password,
                            database='librarychecker')
    for toml_path in tomls:
        probdir = toml_path.parent
        name = probdir.name
        problem = Problem(libdir, probdir)
        title = problem.config['title']
        timelimit = problem.config['timelimit']

        with tempfile.NamedTemporaryFile(suffix='.zip') as tmp:
            m = hashlib.sha256()

            with zipfile.ZipFile(tmp.name, 'w') as newzip:

                def zip_write(filename, arcname):
                    newzip.write(filename, arcname)
                    m.update(pack('q', path.getsize(filename)))
                    with open(filename, 'rb') as f:
                        m.update(f.read())

                zip_write(probdir / 'checker.cpp', arcname='checker.cpp')
Exemplo n.º 5
0
                         secret_key=minio_secret_key,
                         secure=args.prod)

    bucket_name = environ.get('MINIO_BUCKET', 'testcase')

    if not minio_client.bucket_exists(bucket_name):
        logger.error('No bucket {}'.format(bucket_name))
        raise ValueError('No bucket {}'.format(bucket_name))

    tomls_new: List[Path] = []
    tomls_old: List[Path] = []

    for toml_path in tomls:
        probdir = toml_path.parent
        name = probdir.name
        problem = Problem(libdir, probdir)

        new_version = problem.testcase_version()
        first_time = "FirstTime"

        try:
            old_version = stub.ProblemInfo(libpb.ProblemInfoRequest(name=name),
                                           credentials=cred_token).case_version
        except grpc.RpcError as err:
            if err.code() == grpc.StatusCode.UNKNOWN:
                old_version = first_time
            else:
                raise RuntimeError('Unknown gRPC error')

        if new_version != old_version:
            tomls_new.append(toml_path)
Exemplo n.º 6
0
    hostname = environ.get('POSTGRE_HOST', '127.0.0.1')
    port = int(environ.get('POSTGRE_PORT', '5432'))
    user = environ.get('POSTGRE_USER', 'postgres')
    password = environ.get('POSTGRE_PASS', 'passwd')

    conn = psycopg2.connect(
        host=hostname,
        port=port,
        user=user,
        password=password,
        database='librarychecker'
    )

    for name, probinfo in problems['problems'].items():
        title = probinfo['title']
        problem = Problem(libdir, libdir / probinfo['dir'])
        probdir = problem.basedir
        timelimit = problem.config['timelimit']

        with tempfile.NamedTemporaryFile(suffix='.zip') as tmp:
            m = hashlib.sha256()

            with zipfile.ZipFile(tmp.name, 'w') as newzip:
                def zip_write(filename, arcname):
                    newzip.write(filename, arcname)
                    m.update(pack('q', path.getsize(filename)))
                    with open(filename, 'rb') as f:
                        m.update(f.read())
                zip_write(probdir / 'checker.cpp', arcname='checker.cpp')
                for f in sorted(probdir.glob('in/*.in')):
                    zip_write(f, arcname=f.relative_to(probdir))