Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

admin.py 3.47 KB
Newer Older
Marc Duez's avatar
Marc Duez committed
1
# coding: utf8
Marc Duez's avatar
Marc Duez committed
2
import gluon.contrib.simplejson, re
3
import os.path, subprocess
4
import vidjil_utils
5

Marc Duez's avatar
Marc Duez committed
6 7 8 9 10 11 12 13
if request.env.http_origin:
    response.headers['Access-Control-Allow-Origin'] = request.env.http_origin  
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    response.headers['Access-Control-Max-Age'] = 86400
    

## return admin_panel
def index():
14
    if auth.has_membership("admin"):
15 16 17 18 19 20 21 22

        p = subprocess.Popen(["uptime"], stdout=subprocess.PIPE)
        uptime, err = p.communicate()
        
        p = subprocess.Popen(["df", "-h"], stdout=subprocess.PIPE)
        disk_use, err = p.communicate()
        
        return dict(worker = len(db().select(db.scheduler_worker.ALL)),
23 24
                    queued = len(db(db.scheduler_task.status=='QUEUED').select()),                    
                    assigned = len(db(db.scheduler_task.status=='ASSIGNED').select()),
25 26 27 28
                    running = len(db(db.scheduler_task.status=='RUNNING').select()),
                    uptime=uptime,
                    disk_use=disk_use
                    )
29 30 31 32 33


def monitor():
    # External monitor
    return dict (worker = len(db().select(db.scheduler_worker.ALL)),
34 35
                 queued = len(db(db.scheduler_task.status=='QUEUED').select()),
                 assigned = len(db(db.scheduler_task.status=='ASSIGNED').select()),
36
                 running = len(db(db.scheduler_task.status=='RUNNING').select()))
Marc Duez's avatar
Marc Duez committed
37 38 39 40
    
def worker():
    if auth.has_membership("admin"):
        return dict(message=T(''))
Marc Duez's avatar
Marc Duez committed
41 42 43 44 45
    
    
def log():
    if auth.has_membership("admin"):
        
46
        
Marc Duez's avatar
Marc Duez committed
47
        lines = []
48
        file = open(defs.DIR_LOG+request.vars["file"])
Marc Duez's avatar
Marc Duez committed
49
        
50 51
        if "filter" not in request.vars :
            request.vars["filter"] = ""
Marc Duez's avatar
Marc Duez committed
52
            
53 54 55
        for row in reversed(file.readlines()) :

            if vidjil_utils.filter(row, request.vars["filter"]) :
Marc Duez's avatar
Marc Duez committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
                line = {}

                tmp = re.split('\t+| +', row) 

                line["date"] = tmp[1]
                line["date2"] = tmp[2].split(',')[0]
                line["type"] = tmp[3]
                line["file"] = tmp[5]

                if tmp[6] != "Creating":
                    line["user"] = tmp[7]
                    line["mes"] = ""
                    for i in range(8,len(tmp)):
                        line["mes"] += tmp[i] + " "
                else:
                    line["user"] = ""
                    line["mes"] = ""
                    for i in range(6,len(tmp)):
                        line["mes"] += tmp[i] + " "

                lines.append(line)

                if len(lines) >= 100 :
                    return dict(lines = lines)
            
        return dict(lines = lines
                    )
Marc Duez's avatar
Marc Duez committed
83 84 85 86 87 88 89 90 91 92 93 94 95

## to use after change in the upload folder
def repair_missing_files():
    if auth.has_membership("admin"):
        
        flist = ""
        for row in db(db.sequence_file.id>0 and db.sequence_file.data_file != None).select() : 
            seq_file = defs.DIR_SEQUENCES+row.data_file
            
            if not os.path.exists(seq_file) :
                db.sequence_file[row.id] = dict(data_file = None)
                flist += " : " + row.filename
            else :
96
                size = os.path.getsize(seq_file)
Marc Duez's avatar
Marc Duez committed
97 98
                db.sequence_file[row.id] = dict(size_file = size)
                
Mathieu Giraud's avatar
Mathieu Giraud committed
99
        res = {"success" : "true", "message" : "references to missing files have been removed from the database"+flist}
Marc Duez's avatar
Marc Duez committed
100
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))