<commit_before>#!/usr/bin/env python
# coding=utf-8
# Copyright 2017 the Isard-vdi project authors:
#      <NAME>
#      <NAME>
# License: AGPLv3
import pprint
import time
from datetime import datetime, timedelta

from rethinkdb import RethinkDB

from api import app

from .api_exceptions import Error

r = RethinkDB()
import logging
import traceback

from .flask_rethink import RDB

db = RDB(app)
db.init_app(app)

from ..auth.authentication import *
from .api_exceptions import Error
from .helpers import _check
from .validators import _validate_item, _validate_table


def admin_table_list(table, order_by, pluck, without):
    _validate_table(table)

    if not pluck and not without:
        with app.app_context():
            return list(r.table(table).order_by(order_by).run(db.conn))

    if pluck and not without:
        with app.app_context():
            return list(r.table(table).pluck(pluck).order_by(order_by).run(db.conn))

    if not pluck and without:
        with app.app_context():
            return list(r.table(table).without(without).order_by(order_by).run(db.conn))

    if pluck and without:
        with app.app_context():
            return list(
                r.table(table)
                .pluck(pluck)
                .without(without)
                .order_by(order_by)
                .run(db.conn)
            )


def admin_table_insert(table, data):
    _validate_table(table)
    with app.app_context():
        if r.table(table).get(data["id"]).run(db.conn) == None:
            if not _check(r.table(table).insert(data).run(db.conn), "inserted"):
                raise Error(
                    "internal_server",
                    "Internal server error ",
                    traceback.format_exc(),
                )
        else:
            raise Error(
                "conflict", "Id " + data["id"] + " already exists in table " + table<commit_msg>fix(api): admin table add id from parsed name<commit_after>#!/usr/bin/env python
# coding=utf-8
# Copyright 2017 the Isard-vdi project authors:
#      <NAME>
#      <NAME>
# License: AGPLv3
import pprint
import time
from datetime import datetime, timedelta

from rethinkdb import RethinkDB

from api import app

from .api_exceptions import Error

r = RethinkDB()
import logging
import traceback

from .flask_rethink import RDB

db = RDB(app)
db.init_app(app)

from ..auth.authentication import *
from .api_exceptions import Error
from .helpers import _check, _parse_string
from .validators import _validate_item, _validate_table


def admin_table_list(table, order_by, pluck, without):
    _validate_table(table)

    if not pluck and not without:
        with app.app_context():
            return list(r.table(table).order_by(order_by).run(db.conn))

    if pluck and not without:
        with app.app_context():
            return list(r.table(table).pluck(pluck).order_by(order_by).run(db.conn))

    if not pluck and without:
        with app.app_context():
            return list(r.table(table).without(without).order_by(order_by).run(db.conn))

    if pluck and without:
        with app.app_context():
            return list(
                r.table(table)
                .pluck(pluck)
                .without(without)
                .order_by(order_by)
                .run(db.conn)
            )


def admin_table_insert(table, data):
    data["id"] = _parse_string(data["name"])
    _validate_table(table)
    with app.app_context():
        if r.table(table).get(data["id"]).run(db.conn) == None:
            if not _check(r.table(table).insert(data).run(db.conn), "inserted"):
                raise Error(
                    "internal_server",
                    "Internal server error ",
                    traceback.format_exc(),
                )
        else:
            raise Error(
                "conflict", "Id " + data["id"] + " already exists in table " + table
{'fraction_non_alphanumeric': 0.10703285420944558, 'fraction_numerical': 0.003080082135523614, 'mean_word_length': 2.319420783645656, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2950108', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1173, 'n_words': 291}