<commit_before># Copyright 2017 the Isard-vdi project authors:
#      <NAME>
#      <NAME>
# License: AGPLv3

#!/usr/bin/env python
# coding=utf-8
import random, queue
from threading import Thread
import time, json, sys
from webapp import app
from flask_login import current_user
import rethinkdb as r
from ..lib.log import * 

from .flask_rethink import RethinkDB
db = RethinkDB(app)
db.init_app(app)

from .admin_api import flatten
from ..auth.authentication import Password  

from netaddr import IPNetwork, IPAddress 

from ..lib.quotas import QuotaLimits
quotas = QuotaLimits()

class isard():
    def __init__(self):
        with app.app_context():
            try:
                self.config=r.table('config').get(1).run(db.conn)
                self.f=flatten()
            except Exception as e:
                log.error('Unable to read config table from RethinkDB isard database')
                log.error('If you need to recreate isard database you should activate wizard again:')
                log.error('   REMOVE install/.wizard file  (rm install/.wizard) and start isard again')
                exit(1)
        pass



    def update_table_status(self,user,table,data,remote_addr):
            item = table[:-1].capitalize()
            with app.app_context():
                dom = r.table(table).get(data['pk']).pluck('status','name','ephimeral').run(db.conn)          
            try:
                if data['name']=='status':
                    if data['value']=='DownloadAborting':
                        if dom['status'] in ['Downloading']:
                            if app.isardapi.update_table_value(table, data['pk'], data['name'], data['value']):
                                return json.dumps({'title':item+' aborting success','text':item+' '+dom['name']+' will be aborted','icon':'success','type':'info'}), 200, {'ContentType':'application/json'}
                            else:
                                return json.dumps({'title':item+' aborting error','text':item+' '+dom['name']+' can\'t be aborted. Something went wrong!','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                        else:
                            return json.dumps({'title':item+' aborting error','text':item+' '+dom['name']+' can\'t be aborted while not Downloading','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                    if data['value']=='Stopping':
                        if dom['status'] in ['Started']:
                            if app.isardapi.update_table_value(table, data['pk'], data['name'], data['value']):
                                return json.dumps({'title':False,'text':item+' '+dom['name']+' will be stopped','icon':'success','type':'info'}), 200, {'ContentType':'application/json'}
                            else:
                                return json.dumps({'title':item+' stopping error','text':item+' '+dom['name']+' can\'t be stopped. Something went wrong!','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                        else:
                            return json.dumps({'title':item+' stopping error','text':item+' '+dom['name']+' can\'t be stopped while not Started','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                    if data['value']=='Deleting':
                        if table=='media':
                            ''' WE SHOULD CHECK THAT DOMAINS ARE STOPPED '''
                            app.adminapi.media_delete(data['pk'])                        
                            # ~ if dom['status'] in ['Stopped','Failed']:
                            if app.isardapi.update_table_value(table, data['pk'], data['name'], data['value']):<commit_msg>Fix "Medi" messages of webapp<commit_after># Copyright 2017 the Isard-vdi project authors:
#      <NAME>
#      <NAME>
# License: AGPLv3

#!/usr/bin/env python
# coding=utf-8
import random, queue
from threading import Thread
import time, json, sys
from webapp import app
from flask_login import current_user
import rethinkdb as r
from ..lib.log import * 

from .flask_rethink import RethinkDB
db = RethinkDB(app)
db.init_app(app)

from .admin_api import flatten
from ..auth.authentication import Password  

from netaddr import IPNetwork, IPAddress 

from ..lib.quotas import QuotaLimits
quotas = QuotaLimits()

class isard():
    def __init__(self):
        with app.app_context():
            try:
                self.config=r.table('config').get(1).run(db.conn)
                self.f=flatten()
            except Exception as e:
                log.error('Unable to read config table from RethinkDB isard database')
                log.error('If you need to recreate isard database you should activate wizard again:')
                log.error('   REMOVE install/.wizard file  (rm install/.wizard) and start isard again')
                exit(1)
        pass



    def update_table_status(self,user,table,data,remote_addr):
            # Python 3.9
            # item = table.removesuffix('s').capitalize()
            item = (table.endswith('s') and table[:-1] or table).capitalize()
            with app.app_context():
                dom = r.table(table).get(data['pk']).pluck('status','name','ephimeral').run(db.conn)          
            try:
                if data['name']=='status':
                    if data['value']=='DownloadAborting':
                        if dom['status'] in ['Downloading']:
                            if app.isardapi.update_table_value(table, data['pk'], data['name'], data['value']):
                                return json.dumps({'title':item+' aborting success','text':item+' '+dom['name']+' will be aborted','icon':'success','type':'info'}), 200, {'ContentType':'application/json'}
                            else:
                                return json.dumps({'title':item+' aborting error','text':item+' '+dom['name']+' can\'t be aborted. Something went wrong!','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                        else:
                            return json.dumps({'title':item+' aborting error','text':item+' '+dom['name']+' can\'t be aborted while not Downloading','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                    if data['value']=='Stopping':
                        if dom['status'] in ['Started']:
                            if app.isardapi.update_table_value(table, data['pk'], data['name'], data['value']):
                                return json.dumps({'title':False,'text':item+' '+dom['name']+' will be stopped','icon':'success','type':'info'}), 200, {'ContentType':'application/json'}
                            else:
                                return json.dumps({'title':item+' stopping error','text':item+' '+dom['name']+' can\'t be stopped. Something went wrong!','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                        else:
                            return json.dumps({'title':item+' stopping error','text':item+' '+dom['name']+' can\'t be stopped while not Started','icon':'warning','type':'error'}), 500, {'ContentType':'application/json'}
                    if data['value']=='Deleting':
                        if table=='media':
                            ''' WE SHOULD CHECK THAT DOMAINS ARE STOPPED '''
                            app.adminapi.media_delete(data['pk'])                        
                            # ~ if dom['status'] in ['Stopped','Failed']:
                            if app.isardapi.update_table_value(table, data['pk'], data['name'], data['value']):
{'fraction_non_alphanumeric': 0.15739537301793605, 'fraction_numerical': 0.0072783987522745, 'mean_word_length': 2.208924103419516, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340914', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2049, 'n_words': 491}